Web services 使用REST-Assured库测试SOAP Web服务

Web services 使用REST-Assured库测试SOAP Web服务,web-services,soapui,rest-assured,Web Services,Soapui,Rest Assured,是否有可能使用REST-Assured库来测试SOAP Web服务? 我在soapui中有很多测试套件,我需要检查是否有可能使用REST-Assured。 有人能建议这是否可行吗? 非常感谢您的评论。REST assured没有对测试SOAP服务的直接支持,但是可以通过手动设置SOAPAction和Content-Type标题并执行HTTPPOST等操作来实现。然后,您可以像在REST-assured中对普通REST服务一样,对响应运行XPath断言 我建议您也进行评估,因为它内置了对SOAP的

是否有可能使用REST-Assured库来测试SOAP Web服务? 我在soapui中有很多测试套件,我需要检查是否有可能使用REST-Assured。 有人能建议这是否可行吗?
非常感谢您的评论。

REST assured没有对测试SOAP服务的直接支持,但是可以通过手动设置
SOAPAction
Content-Type
标题并执行HTTP
POST
等操作来实现。然后,您可以像在REST-assured中对普通REST服务一样,对响应运行XPath断言


我建议您也进行评估,因为它内置了对SOAP的支持,并且使XML操作更加容易。

这里我向您展示一个示例

标题
SOAPAction
Content Type
必需的。在您的例子中,您需要找到which是SOAPAction头,有时是url中最后一个“/”的下一部分

import static io.restassured.RestAssured.given;
import io.restassured.RestAssured;
import io.restassured.path.xml.XmlPath;
import io.restassured.response.Response;

XmlPath xmlPath;
Response response;

RestAssured.baseURI = "http://url";
response = 
                given()
                    .request().body("xml_text").headers("SOAPAction", "findSoapAction", "Content-Type", "text/xml").
                when()
                    .post("/path").
                then()
                    .assertThat()
                        .statusCode(200).extract().response();
System.out.println(response.asString());

//next we get the xmlPath of the response
xmlPath = response.xmlPath();
//and get the value of a node in the xml
String nodeValue= xmlPath.get("fatherNode.childNode");
System.out.println(nodeValue);
应设置代码中的元素:

RestAssured.baseURI = "http://url";
是发出请求的url

given().request().body("xml_text")
headers("SOAPAction", "findSoapAction", "Content-Type", "text/xml")
参数o body()是一个包含请求xml的字符串

given().request().body("xml_text")
headers("SOAPAction", "findSoapAction", "Content-Type", "text/xml")
“findSoapAction”是一个字符串,其值为您应该猜测的SOAPAction头,“text/xml”是您应该设置为内容类型头的值

xmlPath.get("fatherNode.childNode");
返回节点的值。例如:

<fatherNode>
    <childNode>value of the node</childNode>
</fatherNode>

节点的值
get(“fatherNode.childNode”)返回“节点的值”