Forum Discussion

Sahall0308's avatar
Sahall0308
New Contributor
27 days ago
Solved

Referencing the Keyword Test

Hello,

Apologies, I'm fairly new to Test Complete. I'm having an issue attempting to reference the Keyword Test that my function is being called from, thus not being able to access it's variables or anything else without specifying the Keyword Test. 

Rather than having to specify each time, I thought there must be a way to reference the Keyword Test that a function is being called from so I can access other properties such as Variables or Parameters. Is this possible to achieve? I have tried various things (Project.TestItems.Current.ElementToBeRun.CaptionMarked, Current.Name and so on) and they just simply return null or undefined. 

  • It was for adding an indeterminate level of variables based on what was given as the parameter and to use a for loop to list through each one and perform an action based on this. It's pretty niche to this situation, so apologies for the confusion!

    I did manage to get it working, I'd just stupidly not added my test as a test item in the test execution plan, hence why it was returning as null.

    So my solution was using Project.TestItems.Current.Name and adding the Keyword Test to the execution plan and running it from there to return the current Keyword Test Name.

    Thank you for your reply :)

5 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Are you able to provide an example of the issue you are having?

    • Sahall0308's avatar
      Sahall0308
      New Contributor

      In this example, I'm taking a parameter that I'm delimiting into separate objects and then adding each as a variable to my keyword test. On the KeywordTests.myKeywordTestName lines, I'm stating the specific Keyword Test that I want to add the variables to.

      I'm wondering if I can replace the specific KeywordTest name with something more generic for whichever Keyword Test I'm calling this from, so I don't have to have a function or a ton of logic for all of the various Keyword Tests I might be calling this from.

      So instead of KeywordTests.AddNewStockItemAddLocation.Variables.AddVariable I could write KeywordTests.CurrentKeywordTest.Variables.AddVariable. Or at the very least, be able to access the name of the Keyword Test in some way to eventually achieve the same outcome.

       

      • rraghvani's avatar
        rraghvani
        Champion Level 3

        I'm a bit confused as to why you need to create variables for your keyword tests, like how you have shown?

         

  • Indeed, in Test Complete it is not always easy to access the keyword test from which the function is called. Try the following approach: Instead of trying to access the keyword test directly, you can pass the required variables or parameters through function parameters. This way the function will have access to this data regardless of the keyword test it is called from. This is a more reliable and flexible way to work with data in tests.