Forum Discussion

cjamieson's avatar
Established Member
5 years ago

Groovy script to fail test run and skip to next line in datasource

Hi, I have a current issue where I am trying to write a groovy script where if criteria is met, then to proceed with the rest of the test steps and if criteria is not met then to skip to thenext ro...
  • jsheph01's avatar
    5 years ago

    Would you be able to use a groovy assertion inside of the request and then pass/fail the step if the criteria is met? If you can do that you could have a seperate groovy script to check if the request failed then skip to the data source loop step.


    def tStep = testRunner.testCase.getTestStepByName("Test step 1")
    def result = tStep.getAssertionList()
    // if you have more than one assertion result.size() will get the assertion count
    if (result[0].status.toString() == "FAIL"){
    	testRunner.gotoStepByName("DataSource Loop")

    If you are not able to run the groovy script as a request assertion you could disable all the test steps that should run only if the request passed. You can then use a groovy script to run the disabled test steps.

    def property1 = testRunner.testCase.getTestStepByName("step 1").getPropertyValue("property1")
    //if the assertion failed the script ends and the test steps will not be run
    assert property1 == 0
    testRunner.runTestStepByName("Test step 2")
    testRunner.runTestStepByName("Test step 3")