Domanda

We are using soupUI to perform load test on REST webservices, We have one testcase that accepts 3 parameters. Since we aren't using soupUI pro we are writing groovy to read textfile and send parameters to REST service. When groovy script ran it works fine and when we run testcase parameters are not passed. below is the groovy script.

import com.eviware.soapui.support.XmlHolder
def size
File fileValues = new File("C:/Input.txt")
List lines=fileValues.readLines()
size = lines.size.toInteger()
propTestStep = context.testCase.getTestStepByName("looper-props")
for( counter in 0..size-1) 
{
    tempValue = lines[counter]
    inputValues=[]
    inputValues=tempValue.split(",")
    userName= inputValues[0]
    workSpaceName= inputValues[1]
    productId= inputValues[2]
    iteration=inputValues[3]
    propTestStep.setPropertyValue("userName", userName)
    propTestStep.setPropertyValue("workSpaceName", workSpaceName)
    propTestStep.setPropertyValue("prdAreaId", productId)   
    propTestStep.setPropertyValue("count", iteration)
    testRunner.runTestStepByName("workSpace") 
}

And have created properties userName, workSpaceName, prdAreaId and count. How to pass these properties to rest request?

È stato utile?

Soluzione

I think i may have an approach that may work for you.

It is my understanding that you want to run a load test in soapUI of a rest service. In your test case, you are reading a text file(comma separated), setting the property values and running the rest test request.

I have created a Test Suite that demonstrate what you want to do. For the purpose of this demo i have made use of the GeoNames free webservice which returns a Json response. If you want to run my test suite i would suggest that you create your own username.

The text file looks like this. (notice i have no header row)

44.1,-22.4,55.2,-9.9, fr, demo
44.1,-22.4,55.2,-9.9,en, demo
44.1,-22.4,55.2,-9.9,de, demo
44.1,-22.4,55.2,-9.9,en, demo

I am using a method described at Mike Swooeeney's blog post.

My test Suite has the below structure

-Test Suite
    -Test Case
        -Rest Test Request
        -readNextLine Groovy step

At the test suite level i have the following properties. test suite level properties

In the test case setup script i am reading first row and assigning it to test suite level properties. The code for that is...

def fPath = context.expand('${#TestSuite#TestDataFilePath}')

//Create a new filereader object, using the context variable so it can be used between test components
context.fileReader = new BufferedReader(new FileReader(fPath))

//Read in the first line of the data file
firstLine = context.fileReader.readLine()

//Split the first line into a string array and assign the array elements to various test case properties
String[] propData = firstLine.split(",")
testCase.testSuite.setPropertyValue("north",propData[0])
testCase.testSuite.setPropertyValue("east",propData[1])
testCase.testSuite.setPropertyValue("west",propData[2])
testCase.testSuite.setPropertyValue("south",propData[3])
testCase.testSuite.setPropertyValue("lang",propData[4])
testCase.testSuite.setPropertyValue("username",propData[5])

log.info "Read data north=${propData[0]};east=${propData[1]};west=${propData[2]};south=${propData[3]};language=${propData[4]};username=${propData[5]}"

I am directly accessing these properties in my test request, which look like this.. Rest Test Request Properties

The last step (must be the last step) i am reading the next line and setting it to test suite level properties and then moving control to the first step in the test case. The code for that is...

/*Read in the next line of the file
  We can use the same fileReader created in the Setup script because it
  was assigned to the context variable.*/

nextLine = context.fileReader.readLine()

/*If the end of the file hasn't been reached (nextLine does NOT equal null)
  split the line and assign new property values and go back to the first 
  test request step*/

if(nextLine != null){
    String[] propData = nextLine.split(",")
    curTSuite = testRunner.testCase.testSuite
    curTSuite.setPropertyValue("north",propData[0])
    curTSuite.setPropertyValue("east",propData[1])
    curTSuite.setPropertyValue("west",propData[2])
    curTSuite.setPropertyValue("south",propData[3])
    curTSuite.setPropertyValue("lang",propData[4])
    curTSuite.setPropertyValue("username",propData[5])
    log.info "Read data north=${propData[0]};east=${propData[1]};west=${propData[2]};south=${propData[3]};language=${propData[4]};username=${propData[5]}"
    testRunner.gotoStep(0)
}

Finally, In the test case teardown script i am closing the file reader. The code for that is...

context.fileReader.close()

log.info "file closed"

I have created a load test for this test case and run it using Simple Strategy for 10 seconds with 5 threads and a delay of 1000 miliSecond with a random of 0.5. Below is a screen grab of load test run metrics. Load Test Run Numbers

I am also printing the properties being used so below is the data usage pattern.

Thu Apr 10 20:50:26 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:26 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:26 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:26 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:26 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:32 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:32 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:32 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:32 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:32 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:32 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:32 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:33 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:33 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:33 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:33 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:33 ADT 2014:INFO:file closed
Thu Apr 10 20:50:33 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:33 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:33 ADT 2014:INFO:file closed
Thu Apr 10 20:50:33 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:33 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:33 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:33 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:33 ADT 2014:INFO:file closed
Thu Apr 10 20:50:33 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:33 ADT 2014:INFO:file closed
Thu Apr 10 20:50:33 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:34 ADT 2014:INFO:file closed
Thu Apr 10 20:50:34 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:34 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:34 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:34 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:34 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:34 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:34 ADT 2014:INFO:file closed
Thu Apr 10 20:50:34 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:34 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:34 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:file closed
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:file closed
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:file closed
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:file closed
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:35 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:file closed
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:file closed
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language= fr;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:file closed
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:file closed
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:36 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:37 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:37 ADT 2014:INFO:file closed
Thu Apr 10 20:50:37 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:37 ADT 2014:INFO:file closed
Thu Apr 10 20:50:37 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:37 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=de;username= demo
Thu Apr 10 20:50:37 ADT 2014:INFO:Read data north=44.1;east=-22.4;west=55.2;south=-9.9;language=en;username= demo
Thu Apr 10 20:50:37 ADT 2014:INFO:file closed

Lastly, I want to know why you want to use soapUI for load testing. Although it has the load testing functionality but it is absolutely the wrong tool for that. Have a look at JMeter, loadrunner or other performance testing tool.

My test suite is available at Mega.co.nz

Hope this helps.

Remember to do a virus scan on the downloaded files before using them.

Altri suggerimenti

SoapUI is a functional testing tool. Are you certain you don't mean LoadUI?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top