如何使用Java在SoapUI中设置和获取TestStep属性

时间:2016-02-08 06:07:28

标签: java soapui

我正在尝试使用Java在SOAPUI Project中设置SOAPUI TestStep的属性,如下面的屏幕截图所示。

enter image description here

当我调试下面的代码时,在getPropertysetPropertyValue时,我总是变为空。我的观点是我想从一个我无法做到的java函数中设置属性变量。当我解决问题时,我正在Groovy中获得帮助。有人可以帮助我在Java中如何做到这一点

public class SoapUITest
{
   public final static void main(String [] args) throws Exception {

    WsdlProject project = new WsdlProject("C:\\users\\vikram\\WebService\\WebServiceTest\\src\\main\\java\\weather.xml");
    WsdlTestSuite wsdlTestSuite = project.getTestSuiteByName("WeatherZip");
    WsdlTestCase wsdlTestCase = wsdlTestSuite.getTestCaseByName("Weatherbyzip");
    WsdlTestStep wsdlTestStep = wsdlTestCase.getTestStepByName("GetCityForecastByZIP");
    wsdlTestStep.setPropertyValue("City","21001");// Problem: Unable to set the property value
    WsdlTestCaseRunner wsdlTestCaseRunner = new WsdlTestCaseRunner(wsdlTestCase, new StringToObjectMap(wsdlTestCase.getProperties()));

    TestStepResult testStepResult = wsdlTestCaseRunner.runTestStep(wsdlTestStep);
    if (testStepResult instanceof WsdlTestRequestStepResult) {
        System.out.println(((WsdlTestRequestStepResult) testStepResult).getResponse().getContentAsString());
    }
  }
}

我想在执行程序时设置城市的值。请帮我解决这个问题。

1 个答案:

答案 0 :(得分:1)

好吧..我通过在TestCase级别而不是TestStep中添加自定义属性来弄明白自己。

wsdlTestCase.setPropertyValue("City","12345");

现在SoapUI请求正文Partlooks就像这样

<soapenv:Body>
  <weat:GetCityForecastByZIP>
     <!--Optional:-->
     <weat:ZIP>${#TestCase#City}</weat:ZIP>
  </weat:GetCityForecastByZIP>
</soapenv:Body>