簡體   English   中英

如何使用Java在SoapUI中設置和獲取TestStep屬性

[英]How to set and get TestStep properties in SoapUI using Java

我正在嘗試在Java的SOAPUI Project中設置SOAPUI TestStep的屬性,如下面的屏幕快照所示。

在此處輸入圖片說明

當我調試下面的代碼時,我總是在getPropertysetPropertyValue時為null。 我的意思是我想從無法執行的Java函數中設置屬性變量。 我在Google上搜索該問題時正在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());
    }
  }
}

我想在執行程序時即時設置城市的價值。 請幫我解決這個問題。

好吧..我自己解決了問題,方法是在TestCase級別而不是TestStep中添加自定義屬性。

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

現在,SoapUI請求主體部分看起來像這樣

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM