Forum Discussion

tinoboehme's avatar
tinoboehme
Occasional Contributor
13 years ago

get calling TestCase at Groovy Script in called TestCase

Hello,

I'm using a central generic testcase ("get Values") to provide dynamic unique properties to each test case (in my example "my 1st TestCase" and "my 2nd TestCase").
Is there any possibility by using Groovy Script ("Generic" - "get Values" - "get Test Data") to find out the initial calling test case ("my 1st TestCase" or "my 2nd TestCase")?

Finally I want to access one property from the calling Test Case (e.g. "my 2nd TestCase") with the GroovyScript ("get Test Data") at the called Test Case ("get Values").

Regards Tino

5 Replies

  • Hi Tino,

    Unfortunately, this is difficult to accomplish. If you really want to access the test case flow, you could perhaps utilize the logs and read data from there, but other than that there is no simple way to get that information.

    Regarding your second question, then yes, you can definitely do that. Here's an line in groovy to access your desired property:

    testRunner.testCase.testSuite.project.getTestSuiteByName("Generic").getTestCaseByName("get Values").getPropertyValue("yourPropertyNameHere")

    Hope this helps!

    Regards,

    Arian
    SmartBear Sweden
  • tinoboehme's avatar
    tinoboehme
    Occasional Contributor
    Hello,

    sorry for the confusion, but I've had only one question
    I need the other direction: Within the script "Generic" - "get Values" - "get Test Data" I need to access a property from the initial calling TestCase ("my 1st TestCase" or "my 2nd TestCase").
    Thus I can Imagine that the "testCase flow" or the "testStep flow" would be quite helpful, but I couldn't find any method providing a list of testCases / testSteps.

    Which logs you are referring to?
    Are these logs "Thread Save"? Because the Tests will run in parallel, if all TestCases will write the same logs it is impossible to get the correct logs (except there is anyRun ID).

    Regards Tino
  • Hi!

    There are unfortunately no guarantee that the logs are thread safe.

    To get the properties, you can use

    testRunner.testCase.testSuite.project.getTestSuiteByName("myTestSuite").getTestCaseByName("my 1st TestCase").getPropertyValue("yourPropertyNameHere")
    testRunner.testCase.testSuite.project.getTestSuiteByName("myTestSuite").getTestCaseByName("my 2st TestCase").getPropertyValue("yourPropertyNameHere")

    within the getValues TestCase

    ---
    Regards
    Erik, SmartBear Sweden
  • tinoboehme's avatar
    tinoboehme
    Occasional Contributor
    Hello,

    yes, I know how to access the Properties but I don't know which test case ("my 1st TestCase" or "my 2nd TestCase") has calles the "get Values" test case. How I can get this information?

    Regards Tino
  • Hi again!

    I see.

    Well, as stated before there is no easy way to find out the caller, but maybe you could try setting a TestCase property on Generic with the name of the calling TestCase before you call Generic, and then
    read from that variable. However this might cause problems if you run things in parallell as the TestCase properties is not guaranteed to be thread safe either though.

    --
    Regards

    Erik
    SmartBear Sweden