【问题标题】:soapui - error in groovy script which sources values from csv to populate XMLsoapui - 从 csv 获取值以填充 XML 的 groovy 脚本中的错误
【发布时间】:2015-03-26 11:43:36
【问题描述】:

我已经“借用”了一些 groovy 脚本(来自另一个 stackoverflow 帖子),它本质上应该从 csv 文件中读取值,填充 xml 中的标签,发布到 web 服务,然后循环到 csv 中的下一条记录。 但是 - 当我尝试运行脚本时出现空指针异常。我已经修复了脚本的其他几个问题(缺少括号等),但我只是看不出空指针的问题所在。

代码如下:

    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);

如果有人能发现问题所在 - 我将非常感激!

干杯

【问题讨论】:

    标签: xml csv groovy soapui


    【解决方案1】:

    如果nullPointer 被抛出,则无需分析其余代码:

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

    问题是testStep 为空,这可能是因为您在这里为testStep 指定了错误的名称,然后testStep 为空:

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

    我认为 testStep 的名称可能是 Test Request 而不是 TestRequest(请注意 TestRequest 之间的空格)我认为这是因为默认情况下,当您创建 testStep 时,名称是 Test Request(带空格)。

    希望这会有所帮助,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-19
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多