SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Member
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    360
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Execute is the only way?

    I have a constant that i want to use and its name is the value of this expression "const_" & Environment.Value("AutomationTestCaseData")(2,Data Headers)

    So I thought this would work - Execute(ObjectClassConst = "const_" & Environment.Value("AutomationTestCaseData")(2,Data Headers))

    I would get the the value of the constant being placed in ObjectClassConst

    Does anyone have a better way?

    Joe

  2. #2
    SQA Knight
    Join Date
    May 2006
    Location
    Playa Del Rey, California, United States
    Posts
    2,635
    Post Thanks / Like
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0
    you won't need execute for that. Your problem seems like a simple dictionary object can handle since what you are doing is essentially a lookup table.
    https://msdn.microsoft.com/en-us/lib...(v=vs.84).aspx
    Last edited by dlai; 10-10-2016 at 08:25 PM.
    David Lai
    SDET / Consultant
    LinkedIn profile

  3. #3
    Member
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    360
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    Quote Originally Posted by dlai View Post
    you won't need execute for that. Your problem seems like a simple dictionary object can handle since what you are doing is essentially a lookup table.
    https://msdn.microsoft.com/en-us/lib...(v=vs.84).aspx
    Dim obj_datadict ' Create a variable.
    Set obj_datadict = CreateObject("Scripting.Dictionary")
    obj_datadict.Add "a", "const_" ' Add some keys and items.
    obj_datadict.Add "b", Environment.Value("AutomationTestCaseData")(2,Data Headers
    a=obj_datadict.items
    Gives me the constant name msgbox(a(0)&a(1))
    I'd like the value of the constant that is named bya(0)&a(1) - how?
    Last edited by jloyzaga; 10-10-2016 at 08:39 PM. Reason: more info

  4. #4
    Member
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    360
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    this is the contant defined
    Const const_OTC_Log_in="Class Name:=Link|xpath:= //a[contains(text(),'Log in')]"
    and I'd like to retrieve the value it holds - "Class Name:=Link|xpath:= //a[contains(text(),'Log in')]"

  5. #5
    Advanced Member
    Join Date
    May 2007
    Posts
    612
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    2 Thread(s)
    Total Downloaded
    0
    It took me a couple of reads through but I think I understand what you're saying now...
    Environment.Value("AutomationTestCaseData")(2,Data Headers) holds the name of the constant you want.
    You are trying to set ObjectClassConst to the value of the constant.

    Code:
       ObjectClassConst = Eval("const_" & Environment.Value("AutomationTestCaseData")(2,Data Headers))
    Dennis Belew

  6. #6
    SQA Knight
    Join Date
    May 2006
    Location
    Playa Del Rey, California, United States
    Posts
    2,635
    Post Thanks / Like
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0
    Quote Originally Posted by jloyzaga View Post
    Dim obj_datadict ' Create a variable.
    Set obj_datadict = CreateObject("Scripting.Dictionary")
    obj_datadict.Add "a", "const_" ' Add some keys and items.
    obj_datadict.Add "b", Environment.Value("AutomationTestCaseData")(2,Data Headers
    a=obj_datadict.items
    Gives me the constant name msgbox(a(0)&a(1))
    I'd like the value of the constant that is named bya(0)&a(1) - how?
    They key thing you really want is not the "cost_..." variable, but the value in it. Instead of creating const variable, just create a dictionary, then add those xpath etc.. values you're storing in there into the dictionary. Then when you want to do a lookup, just get the value out of the dictionary.

    Think of it as a spreadsheet with 2 columns. First column is a lookup key. So you can put the names of those constants you created. Then for the value, put the values you previously assigned the constants. Then instead of doing an Eval to get the value from a unknown constant variable, you are fetching a value from a known dictionary key value.
    David Lai
    SDET / Consultant
    LinkedIn profile

  7. #7
    Member
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    360
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    Quote Originally Posted by belewda View Post
    It took me a couple of reads through but I think I understand what you're saying now...
    Environment.Value("AutomationTestCaseData")(2,Data Headers) holds the name of the constant you want.
    You are trying to set ObjectClassConst to the value of the constant.

    Code:
       ObjectClassConst = Eval("const_" & Environment.Value("AutomationTestCaseData")(2,Data Headers))
    that is correct - any ideas?

  8. #8
    Member
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    360
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    Quote Originally Posted by dlai View Post
    They key thing you really want is not the "cost_..." variable, but the value in it. Instead of creating const variable, just create a dictionary, then add those xpath etc.. values you're storing in there into the dictionary. Then when you want to do a lookup, just get the value out of the dictionary.

    Think of it as a spreadsheet with 2 columns. First column is a lookup key. So you can put the names of those constants you created. Then for the value, put the values you previously assigned the constants. Then instead of doing an Eval to get the value from a unknown constant variable, you are fetching a value from a known dictionary key value.
    could you tell me how to do that given this set of constants? How would I get the value of OTC_CTE1_Username
    I'm assuming I'm sewtting up the dictionary like this?
    Dim obj_datadict ' Create a variable.
    Set obj_datadict = CreateObject("Scripting.Dictionary")
    obj_datadict.Add "OTC_CTE1_Username", "Class Name:=WebEdit|xpath:=//*[@id='login']" ' Add some keys and items.
    How do get the value which has a key OTC_CTE1_Username anywhere in my code?
    Const const_OTC_CTE1_Username="Class Name:=WebEdit|xpath:=//*[@id='login']"
    Const const_OTC_CTE1_Password="Class Name:=WebEdit|xpath:=//*[@id='passwd']"
    Const const_OTC_Log_in="Class Name:=Link|xpath:= //a[contains(text(),'Log in')]"
    Const const_OTC_Sign_in="Class Name:=WebButton|name:=Sign in"
    Const const_OTC_Building_Plan_Approvals="Class Name:=WebElement|innertext:=Building plan approvals"
    Const const_OTC_Continue = "Class Name:=WebElementClick|innertext:=Building plan approvals"
    Const const_OTC_Property_Image="Class Name:=Image|css:=img.img-responsive"
    Const const_OTC_Property_Address="Class Name:=WebEditandClick|xpath:=//INPUT[@id=""pac-input""]"
    Const const_OTC_PropertyAddressConfirm="Class Name:=WebElementSendEnter|innertext:=New South Wales"
    Const const_OTC_AddStructure="Class Name:=WebElement|html id:=add-structure-btn"
    Const const_OTC_Structure1="Class Name:=WebElementSpecial1|name:=structureType"
    Const const_OTC_GoToStructure="Class Name:=WebButton|html id:=structureModalNext"
    Const const_OTC_Structure1_Length="Class Name:=WebNumber|xpath:=//INPUT[@id=""currentStructure-Length""]"
    Const const_OTC_Structure1_Width="Class Name:=WebNumber|xpath:=//INPUT[@id=""currentStructure-Width""]"
    Const const_OTC_Structure1_Units="Class Name:=WebList|xpath:=//SELECT[@id=""currentStructure-Units""]"
    Const const_OTC_Structure1_Is_Digging="Class Name:=WebElement|xpath:=//DIV[@id=""newStructure""]/DIV[@role=""listbox""][1]/DIV[2]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/LABEL[1]/SPAN[1]"
    Const const_OTC_Structure1_Digging_Depth="Class Name:=WebNumber|xpath:=//INPUT[@id=""currentStructure-Depth""]"
    Const const_OTC_PlaceButton="Class Name:=WebElement|xpath:=//A[@id=""structureModalPlace""]"

  9. #9
    Member
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    360
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    is the dictionary available to all functions to use - like global variables?

  10. #10
    SQA Knight
    Join Date
    May 2006
    Location
    Playa Del Rey, California, United States
    Posts
    2,635
    Post Thanks / Like
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0
    Quote Originally Posted by jloyzaga View Post
    is the dictionary available to all functions to use - like global variables?
    You set a global value to the dictionary. Then you have an init script dump the values into the dictionary as opposed to initializing all those constants. Then instead of eval, you do a dictionary lookup.
    David Lai
    SDET / Consultant
    LinkedIn profile

 

 
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 07:49 PM.

Copyright BetaSoft Inc.