Forum Discussion

mfoster711's avatar
mfoster711
Regular Contributor
11 years ago

Get Keyword Test Name from script code?

Is this possible:



I want  to use the "Run Script Routine" from a Keyword test and have it call a generic function called "MyTestFunction". Within MyTestFunction, I want to be able to programmatically determine the name of the Keyword test that called the function and then use that name to determine and loop through all the Keyword test variables.



For example:



Function MyTestFunction()

    KeywordTestName = GetCallingKeywordTestName???

    For i = 0 to KeywordTestName.VariablesCount

        VarName = KeywordTestName.Variables.GetVariableName(i)

        'Now do what I want with the VarName

    Next

End Function



If not possible, any alternative ideas??



I am using VBScript.
  • oops a typo - for your example it would be



    eval("KeywordTests." & KeywordTests.ThisTest.Variables.sTestName & ".Variables.GetVariableName(i)")
  • I'm not sure how to say it in VB but in a keyword test you would set VarName to this:



    eval("KeywordTests." & KeywordTests.ThisTest.Variables.sTestName & ".Variables.GetVariableName(0)")





    where ThisTest is the test you are running it from
  • mfoster711's avatar
    mfoster711
    Regular Contributor
    I have thought of a possible solution to part of my problem. When I use "Run Script Rountine" I could simply pass in the Keyword test name as a parameter on the function call. This would allow me to programmtically know the name of the calling keyword test.



    But, this is only half of my problem. How do you use a variable to reference a KeywordTest? It appears you can only reference the KeywordTest using the hardcoded value. For example, I am trying to use this code:



    VarName = HardCodedKeywordTestName.Variables.GetVariableName(i)



    There does not appear to be anyway to use a variable to refer to the KeywordTestName. I would ideally want to do something like this:



    sTestName = "MyKeywordTest"

    VarName = sTestName.Variables.GetVariableName(i)



    Any Ideas???
  • oops a typo - for your example it would be



    eval("KeywordTests." & KeywordTests.ThisTest.Variables.sTestName & ".Variables.GetVariableName(i)")
    • swapnaliuk's avatar
      swapnaliuk
      Occasional Contributor

      Hi,

       

      I am also having the similar issue - I want to get a Keyword test name from script and set it in a variable and run that keyword test using Run method by passing the Keyword test variable. Can I  get some more information on how did you get the Keywork test name from script code? I am using Jscript. Thanks in advance.

      • Marsha_R's avatar
        Marsha_R
        Moderator

        The keyword tests don't know their own names.  In the example above, it was hard-coded and passed in as a string.