Forum Discussion

sathyaraj's avatar
sathyaraj
Occasional Contributor
8 years ago

loop the test steps in soapui with the help of groovy

I have an JDBC request step to pull the data from database like the below.


<Results>
<ResultSet fetchSize="10">
<Row rowNumber="1">
<Dep_Airport>one</Dep_Airport>
<Dep_Airport>two</Dep_Airport>
<Dep_Airport>three</Dep_Airport>
</Row>
</ResultSet>
</Results>

 

In the test suite level i have created the property as Dep_Airport=one mnually..i want this all the dep airport will be looped one by one every time the the test suite completed their steps

 

For Example:

 

before run the suite first time i will insert the property as Dep_Airport=one mnually and when all the steps completed in the test suite including the jdbc request steps.

then it should change the Dep_Airport=two and it should run the suite one more time then it should change the Dep_Airport=three and run one more time.

 

kindly help me to sugggest the solution or idea

2 Replies

  • KarelHusa's avatar
    KarelHusa
    Champion Level 3

    I would suggest to loop at the test case level.

     

    1. you define properties on TestSuite (or TestCase) level:

    - airports with value: London,Prague,Paris

    - counter with value: 0

     

    2. create a 'Flight' TestStep and in your test step get the airport value and increment the counter:

     

     

    def s = testRunner.testCase.testSuite.getPropertyValue( "airports")
    def list = s.split(',')
    
    def i = Integer.parseInt(testRunner.testCase.testSuite.getPropertyValue( "counter"))
    
    // Do your action here
    log.info list[i]
    
    // increment the counter
    i++
    testRunner.testCase.testSuite.setPropertyValue( "counter", i.toString())

    3. Put a Groovy script test step called 'Continue ' afterwards, with a script:

     

     

    def s = testRunner.testCase.testSuite.getPropertyValue( "airports")
    def list = s.split(',')
    def i = Integer.parseInt(testRunner.testCase.testSuite.getPropertyValue( "counter"))
    
    if (i < list.size()) {
            // Looping as long as we have values
    	testRunner.gotoStepByName ('Flight')
    } else {
            // Otherwise we set counter to initial value
    	testRunner.testCase.testSuite.setPropertyValue( "counter", new Integer(0).toString())
    }

    3. This code prints following output:

    Thu Aug 04 14:26:53 CEST 2016:INFO:London

    Thu Aug 04 14:26:53 CEST 2016:INFO:Paris

    Thu Aug 04 14:26:53 CEST 2016:INFO:Prague

     

    I hope this helps, however the looping is not on a TestSuite level. TestSuite level looping is also possible, you need to utilize the TestSuite TearDown script for looping.

     

    • sathyaraj's avatar
      sathyaraj
      Occasional Contributor

      Thanks for the suggestions.i will try and update