Forum Discussion

jmahant's avatar
jmahant
Occasional Contributor
6 years ago
Solved

Groovy to run a specific test step and then abort the test case

In one of my re-usable test case I have 5 steps(requests) and I want to write a groovy step (in the same test case) which should read the property and based on its value should run one of the available 5 steps and ignore rest of them.

Basically dynamically pick and run a test step and then abort the test case.

 

Thanks in advance for help.

  • def tc=testRunner.testCase.testSuite.getTestCaseByName("TestCaseName")
    tc.getTestStepList().each{

    if(it.name.toString()=="StepName"){
    it.run(testRunner,context)
    testRunner.cancel("just stop the testCase")
    return null;
    }
    log.info(it.name)
    }

     

    Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.:smileywink:

3 Replies

  • def tc=testRunner.testCase.testSuite.getTestCaseByName("TestCaseName")
    tc.getTestStepList().each{

    if(it.name.toString()=="StepName"){
    it.run(testRunner,context)
    testRunner.cancel("just stop the testCase")
    return null;
    }
    log.info(it.name)
    }

     

    Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.:smileywink:

    • jmahant's avatar
      jmahant
      Occasional Contributor

      Thanks for the response but I just realized (after using your solution) that I forgot to mention that I am using a session start step before this groovy step and to run any specific test case through groovy I also have to pass on  the session.

      And the problem is I am not able to pass on the session using groovy.

      Here is the test case structure:

      Step #1 Session Start

      Step#2 Groovy to run a specific test step among next 5 steps (Test1...Test5)

      Step#3 Test1

      Step#4 Test2

      Step#5 Test3

      Step#6 Test4

      Step#7 Test5

      • jmahant's avatar
        jmahant
        Occasional Contributor

        Never Mind. I figured the way to pass on the session.

        Thanks for your help though.