Forum Discussion

scottroutesmart's avatar
scottroutesmart
Occasional Contributor
7 days ago

Is it Possible to use CurrentTest as

I sometimes use Code Expressions as a parameters to call other tests or scripts.  But, I have not found an easy way to copy/paste these test step into another test without having to manually update the test name (from the old test to the new test name).

A code expression I may pass would look like this:

KeywordTests.Copy_Station.Variables.Station_12345 + " - COPY"
KeywordTests.TEST_NAME.Variables.VARIABLE_NAME + " - COPY"

But I would rather do something like the following, so as I copy/paste I don't need to modify the test name each time I need to use the same function:

ProjectSuite.TestItems.Current.VARIABLE_NAME
or
THIS_TEST.Variables.VARIABLE_NAME + " - COPY"
or
CURRENT_TEST.Variables.VARIABLE_NAME + " - COPY"

I assume this is possible in TC and some of you do something similar but can't come up with a solution that seems to work.  Any suggestions are appreciated.  I have tried multiple times over the years (and read endless documentation and community posts) but I figure someone out there has a solution they have found useful.

  • This does seem like too many steps. Could you put in some actual code that's working now along with a sample call? 

    • scottroutesmart's avatar
      scottroutesmart
      Occasional Contributor

      Here is a screenshot of what I am doing to show the setup on how the test is called:  (I also do something similar to call some scripts too.)

      You can see I have a keyword test which takes in 9 parameter values, in order to make a backup of the data I want to preserve.  Note that the 7th parameter is a Code Expression, which refers to a variable specific to the test being executed in the test "CSA_Maint_Copy_CSA_and_Verify_Default_Values_Flow"

      The Keyword test which I am calling is a generic method which I reuse across many tests, so only the parameters values it receives change.

      The problem is... when I copy (control-c) the step which calls the generic method, and paste it in to another test, I then have to manually update the test name from "CSA_Maint_Copy_CSA_and_Verify_Default_Values_Flow" to reflect the new test name that I have created (let's say "CSA_Maint_Copy_CSA_and_Verify_Employees_Flow").  If there was a "currenttest" or "this.test" reference that I could use instead of the test name, then it would save the manual editing of these parameters with each new test created.