emma
emma

Reputation: 45

How to use Groovy script in soapUi to loop multiple time

I am new to SoapUi. I am exploring on how multiple request in soapUi is done using groovy script.

below is the example that im trying to do, based on example that i found through "googling"

import com.eviware.soapui.SoapUI;
import com.eviware.soapui.model.testsuite.*;
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
import java.util.Random 
import com.eviware.soapui.model.testsuite.TestRunner.Status



// Define your testCase pointer
//def testcase = testRunner.testCase.testSuite.project.testSuites["TestSuite - User Management REST API"].getTestCaseByName ("Authenticate User")

def counterUser = testRunner.testCase.testSuite.getPropertyValue( "counter" )

int value = counterUser.toInteger()
String tester = ""
30.times {
 value = value + 1
 tester = "tester " + value.toString()
 testRunner.testCase.testSuite.setPropertyValue( "userName", tester )

 testRunner.runTestStepByName("POST - createUser - Create a User")
}
testRunner.testCase.testSuite.setPropertyValue( "counter", value.toString() )

I want to create a 30 users which start from Tester1...tester2.....tester30. Is it possible to do this way? I keep getting an error such as NullPointerException at this line

int value = counterUser.toInteger()

Upvotes: 1

Views: 1978

Answers (1)

Rao
Rao

Reputation: 21359

I got what you say.

That is because, initially there is no value for counter which results to null and you are applying toInteger() over it.

Just change:

From:

int value = counterUser.toInteger()

To:

int value = counterUser?.toInteger() ?: 0

Upvotes: 1

Related Questions