Forum Discussion

AKarandjeff's avatar
AKarandjeff
Contributor
14 years ago

Passing Variables into Keyword Tests to Identify Objects

Is it possible to pass a variable into the object string on a keyword test?  The overall container frame for our application is identified by the header value of our frame, which is a combination of our application product branding, the user ID of the individual logged in and the link to the application server (highlighted below as C3C:, eak_admin and <https://chcrh.strata-group.com:18291/> respectively).  I'm trying to build our test cases so they are as generic as possible as all three values can change and was thinking that we could set them as project suite level variables.  That said, I do not know how to feed those variables into the object string so they properly populate and identify the object.  As you can see, I would need to put the variables plus some spaces between each variable, or if there is a way to capture that frame identifier the at the beginning of a script run and then pass it along to all the other objects, that would probably be most ideal.  Thanks.



Sys.Process("javaw").SwingObject("JFrame", " C3C: eak_admin <https://c3crh.strata-group.com:18291/>", 0).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("C3C", "", 0).SwingObject("SessionWorkspace", "", 0).SwingObject("InternalSessionFrameProxy", "User Details", 0).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("UserPropertySheet", "", 0).SwingObject("JPanel", "", 0).SwingObject("JPanel", "", 0).SwingObject("JPanel", "", 0).SwingObject("JPanel", "", 0).SwingObject("JButton", "OK", 0)

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Andrew,



    I think, the easiest way is to mask variable parts of the window caption with wildcards, like this:

    Sys.Process("javaw").SwingObject("JFrame", "* <https://*/>", 0)...


    Does this suit your needs?
  • Is there an a way to do a mass update of the object nameds in a keyword test?  I tried doing a find replace on the project suite and that didn't seem to work for the keyword test objects.  I also noticed an issue in the script test where the //*/ in https://*/ gets treated like a comment block delimiter.  My scripts are in Java Script so I may have to find something a little different.  Thanks!
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Andrew,



    > I also noticed an issue in the script [JScript] test where the //*/ in https://*/
    gets treated like a comment block delimiter.



    I might be wrong as I am not using JScript, but it seems to me that slashes (like in C/C++) must be doubled in JScript:

    'https://*/' ==> 'https:////*//'



    Does it help?
  • I got around the commenting issue, but still have the outstanding question on doing mass updates of objects in keyword tests.  Is there a way to update all the objects, or am I going to have to go into each step and update?  That will take a lot of time to do.  I suppose I could convert to script, but would like to exhaust the keyword test option first.  Thanks.

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Andrew,



    Is there a way to update all the objects, or am I going to have to go into each step and update?


    I'm afraid, find/replace is currently supported only for keyword test operation parameters, that is, the Value column in the test editor. Replacing object names in keyword tests can be done only manually.



    We have an existing feature request to allow find/replace in object names, and I've increased its rating based on your post; but, currently, there's no ETA when it may be implemented. Sorry for the inconvenience.





    I suppose I could convert to script


    Yes, that would be an option.



    Also, you may want to consider using the Name Mapping in your test project. It allows you to keep the identification properties of test objects individually from tests, so, when these properties need to be changed, you need only to update the Name Mapping and not the tests themselves. This would help you avoid the situations like this in the future.