gpt4 book ai didi

java - 在 Java 中显示 SOAPUI TestRunner 响应

转载 作者:行者123 更新时间:2023-11-29 04:51:46 26 4
gpt4 key购买 nike

我正在使用来自 Java 的 SOAP UI API。我已经创建了我的 SOAP 项目并添加了一个测试套件和所需的测试用例和测试步骤。我只是想知道是否有任何方法可以获取 XML 格式的测试响应?因为我想在我的测试中进一步使用这些数据

import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.model.iface.MessageExchange;
import com.eviware.soapui.model.support.PropertiesMap;
import com.eviware.soapui.model.testsuite.TestCase;
import com.eviware.soapui.model.testsuite.TestRunner;
import com.eviware.soapui.model.testsuite.TestSuite;
import org.junit.Assert;
import java.util.List;
public class SoapUITest
{
public final static void main(String [] args) throws Exception {

WsdlProject project = new WsdlProject("C:\\WebService\\WebServiceTest\\src\\main\\java\\weather.xml");
List<TestSuite> testSuites = project.getTestSuiteList();
for (TestSuite testSuite: testSuites)
{
System.out.println("Running Test Suite: "+ testSuite.getName());
List<TestCase> testCases = testSuite.getTestCaseList();
for(TestCase testCase:testCases)
{
System.out.println("Running Test Case: " + testCase.getName());
TestRunner testRunner = testCase.run(new PropertiesMap(), false);
Assert.assertEquals(TestRunner.Status.FINISHED,testRunner.getStatus());

//Exception in the below line
//System.out.println(((MessageExchange)testRunner).getResponseContent());
}
}
System.out.print("Testing finished successfully");
}
}

我已经添加了这段代码 System.out.println(((MessageExchange)testRunner).getResponseContent()) 但出于显而易见的原因,我得到了以下异常。不确定我是否使用了正确的方法。

Exception in thread "main" java.lang.ClassCastException: com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner cannot be cast to com.eviware.soapui.model.iface.MessageExchange
at VMSSoapUI.main(SoapUITest.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

是否有人已经实现了这种发送请求并从 SOAPUITestRunner 获取 XML 格式响应的方式?感谢您的帮助。

最佳答案

runStepAndGetResponseContent 方法 将运行测试步骤并获取响应作为字符串 wsdl 请求测试步骤 type,我相信,就是你要找的那个。您可以根据需要为其他测试步骤类型实例添加条件。

public String runStepAndGetResponseContent(WsdlTestCaseRunner runner, TestStep testStep) {
TestStepResult result = runner.runTestStep(testStep);
if (result instanceof WsdlTestRequestStepResult) {
return ((WsdlTestRequestStepResult) result).getResponse().getContentAsString();
}
return null;
}

除了上面的新方法,你下面这行代码需要替换成下面的代码:

现有:
TestRunner testRunner = testCase.run(new PropertiesMap(), false);

替换为:这将循环遍历测试用例的测试步骤。

WsdlTestCaseRunner runner = new WsdlTestCaseRunner((WsdlTestCase) testCase, new StringToObjectMap(testCase.getProperties()) );
for(TestStep testStep: testSteps){
//calling the above get method here
String response = runStepAndGetResponseContent(runner, testStep);
System.out.print("Received response is :" + response);
}

关于java - 在 Java 中显示 SOAPUI TestRunner 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35193218/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com