Forum Discussion

lucky009's avatar
lucky009
New Contributor
10 years ago

[R]Help with groovy script for executing certain test steps

Hell Guys,

I'm trying to execute a test suite with groovy script to read the csv file.

My order of test case:

1) Groovy Script:
Will fetch data from csv. The csv has 4 columns A, B, C and D.

If (A==1 && B!=1 && C!=1 && D!= 1)
{
testRunner.goTotestStep("TestRequest1")
}
else if (A==1 && B==1 && C!=1 && D!= 1)
{
testRunner.goTotestStep("TestRequest1")
testRunner.goTotestStep("TestRequest2")

else if (A==1 && B==1 && C==1 && D!= 1)
{

testRunner.goTotestStep("TestRequest2")

..
..
..
..else {
testRunner.gotoStepByName("End")
}


2) Test Request1
3) Test Request 2
4) Test Request 3
5) Test Request 4
6) Conditional ToGo - Target as Groovy script

The problem is my script is not looping through given condition.

It is executing all Test Request1, Test Request2, Test Request3, Test Request4 for the first condition instead of just execute Test Request1.

Can you guys englighten me here?

Thanks for your help in advance.

2 Replies

  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    It is because you are using GoToStep. Try runTestStepByName

    The API explains how the GoToTestStepByName transfers the testRunner to that step and then it will continue to run. RunTestStepByName will just run that step.

    Also, disabling the steps would be important. If not the test runner will just go on to the next step.


    PS. Once your testRunner hits any of your clauses, the testRunner goes to that step immediately and will not return to your groovy script so everything following would not be executed. I will just post what is being ignored:

    If (A==1 && B!=1 && C!=1 && D!= 1)
    {
    testRunner.goTotestStep("TestRequest1")
    }
    else if (A==1 && B==1 && C!=1 && D!= 1)
    {
    testRunner.goTotestStep("TestRequest1")
    testRunner.goTotestStep("TestRequest2")//This line is completely ignored. testRunner left the groovy script already and went to TestRequest1
    else if (A==1 && B==1 && C==1 && D!= 1)
    {

    testRunner.goTotestStep("TestRequest2")//Anything below this will be ignored. testRunner left the groovy script already and went to TestRequest2
    ..
    ..
    ..
    ..else {
    testRunner.gotoStepByName("End")
    }
  • lucky009's avatar
    lucky009
    New Contributor
    Thanks PaulM. It worked.

    I've used runTestStepByName and disabled the test requests in my test suite.

    All I have to do is run the groovy script and it will iterate through loop for numbers of records from CSV file.