我已经借用了一些groovy脚本(来自另一个stackoverflow帖子),它基本上应该从xs文件中填充标签的csv文件中读取值,发布到web服务然后循环到csv中的下一条记录。登记/> 但是 - 当我尝试运行脚本时,我得到一个nullpointer异常。我已经修复了脚本的其他几个问题(缺少括号等)但我无法看到nullpointer的问题。
代码如下:
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()
}}
SoapUI中的错误响应只是第17行的空指针 - 第17行是testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);
如果有人能发现问题所在 - 我将非常感激!
干杯
答案 0 :(得分:0)
如果nullPointer
抛出:
testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);
问题是testStep
为空,这可能是因为您在此为testStep
指定了错误的名称,然后testStep
为空:
def testStep = testCase.getTestStepByName("TestRequest");
我认为testStep名称可能是Test Request
而不是TestRequest
(请注意Test
和Request
字之间的空格)我认为这是因为默认情况下创建时testStep名称为Test Request
(带空格)。
希望这有帮助,