Forum Discussion

mastercoffee's avatar
mastercoffee
New Contributor
16 years ago

How can I conditionally execute a test step based on the value of a property?

I would like to execute an HTTP request step N times during a load test. I was hoping I could set a property value to some value like "100" and then decrement it in a groovy script during each iteration of the load run. Once the counter reaches "0" I would no longer execute that http request step. How can I do this?
Thanks

1 Reply

  • Here is the outline of how I do a similar task:
    1) In the testcase Setup Script, I initialize two variables... One is the setting of a variable to 0 to be used as a global index value.  The other is the N times to iterate.

    2) groovy script test step to increment the global index value.

    3) process desired request(s).

    4) groovy script test step to compare global index value to N.


    Here is the detail of the above outline:
    1)  Test Case Setup Script - reads the number of lines in a data file and sets the desired number of iterations to the number of lines contained in the data file...

    def globalIntCount = 0
    // Set the count of lines in the file...
    def inFile = 'H:/DATA/SoapUI Projects/Test Data Functionality/UAT JCAPS Troubleshoot/SearchByIDRequests.txt'
    new File(inFile).splitEachLine(',')
    {
      globalIntCount++
    }
    testRunner.testCase.properties["globalIndx"].value = 0
    testRunner.testCase.properties["globalCount"].value = globalIntCount
    testRunner.testCase.setPropertyValue("dataFile", inFile);


    2) groovy script test step to increment the global index value (titled "Groovy Script Data Read"...

    def lineIndx = 0
    def tmpIndx = Integer.parseInt(testRunner.testCase.properties["globalIndx"].value)
    def inFileData = testRunner.testCase.properties["dataFile"].value

    new File(inFileData).splitEachLine(',')
      {
          fields ->
            if (lineIndx == tmpIndx)
            {
                def propBaseRead = testRunner.testCase.getTestStepByName( "PropertiesFromFile" );
                propBaseRead.setPropertyValue("jcaps_searchMembersByIdmemberID", fields[1]);
    //            log.info("=======");
    //            log.info("dT = " + fields[0] + " ### " + fields[1] + " ### " + fields[2] );
            }
            lineIndx++
      }
    tmpIndx++
    testRunner.testCase.properties["globalIndx"].value = tmpIndx


    3) process desired request(s) - step 2 above set a properties test step that a subsiquent request can use...

    4) groovy script test step to compare global index value to N -  If the end is not met, then travel back to the first test step titled "Groovy Script Data Read" which is the title of the test step from 2 above...

    def tmpIndx = Integer.parseInt(testRunner.testCase.properties["globalIndx"].value)
    def tmpCount = Integer.parseInt(testRunner.testCase.properties["globalCount"].value)
    //log.info("=======");
    //log.info(" = " + tmpIndx + " ### " + tmpCount );
    if (tmpIndx >= tmpCount)
    {
      //  testRunner.gotoStepByName( "Groovy Script Exit" );
      log.info("= End of Run =");
    }
    else
    {
      testRunner.gotoStepByName( "Groovy Script Data Read" );
    }



    I hope you can gleen some ideas to help with your situation from this example.
    Regards Todd