0
votes

I've 'borrowed' some groovy script (from another stackoverflow post) which essentially should read values from a csv file populating tags in an xml, posting to a webservice and then looping around to the next record in the csv.
HOWEVER - I'm getting a nullpointer exception when I try and run the script. I've already fixed a couple of other problems with the script (missing brackets etc.) but I just cannot see what the problem is with the nullpointer.

Code is as follows:

    import com.eviware.soapui.impl.wsdl.teststeps.*

 def testDataSet = []
 def fileName = "C:\\sourcedata.csv"

 new File(fileName).eachLine { line -> testDataSet.add( line.split(",") ) }

 def myProps = new java.util.Properties();
 myProps = testRunner.testCase.getTestStepByName("Properties");

 def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
 def testCase = testRunner.testCase;

 def testStep = testCase.getTestStepByName("TestRequest");

testRunner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testCase, null);
testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);
testStep.run(testRunner, testStepContext);

while (true) {
 for ( i in testDataSet ) {

 def th = Thread.start(){
 myProps.setPropertyValue("parameter0",i[0]);
 myProps.setPropertyValue("username",i[1]);
 myProps.setPropertyValue("parameter1",i[2]);
 myProps.setPropertyValue("password",i[3]);

 testStep.getTestRequest().setUsername(myProps.getPropertyValue("username"))
 testStep.getTestRequest().setPassword(myProps.getPropertyValue("password"))

 testStep.run(testRunner, testStepContext);
 }

th.join()     
}}

The error response in SoapUI is just nullpointer at line 17 - line 17 is testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);

If anyone can spot what the problem is - I would be very grateful!

Cheers

1

1 Answers

0
votes

Without analyzing the rest of your code if the nullPointer is throw at:

testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);

The problem is that testStep is null, this is probably because here you're specifying the wrong name for your testStep and then testStep is null:

def testStep = testCase.getTestStepByName("TestRequest");

I think that probably the testStep name is Test Request not TestRequest (note the space between Test and Request words) I think this because by default when you create a testStep the name is Test Request (with space).

Hope this helps,