使用 REST Assured 库测试 SOAP 网络服务
Using REST Assured library for testing SOAP webservices
是否可以使用 REST Assured 库来测试 SOAP 网络服务?
我在 SOAP UI 中有一堆测试套件,我需要检查是否有可能使用 REST Assured。
谁能建议这是否可能?
非常感谢任何评论。
REST-assured 不直接支持测试 SOAP 服务,但可以通过手动设置 SOAPAction
和 Content-Type
headers 并执行 HTTP POST
等。然后您可以 运行 对响应进行 XPath 断言,就像在 REST-assured.
中对普通 REST 服务所做的那样
我建议您也评估 Karate,因为它 built-in 支持 SOAP,并且还使 XML 操作更容易。
我给大家举个例子
Headers SOAPAction
和 Content-Type
是 强制性的 。您需要找到您的情况下的 SOAPAction header,有时是 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")
参数 o body() 是一个带有请求xml的字符串
headers("SOAPAction", "findSoapAction", "Content-Type", "text/xml")
"findSoapAction" 是一个带有 SOAPAction header 值的字符串,您应该猜到,而 "text/xml" 是您应该设置为 Content-Type header .
xmlPath.get("fatherNode.childNode");
returns节点的值。示例:
<fatherNode>
<childNode>value of the node</childNode>
</fatherNode>
get("fatherNode.childNode") returns "value of the node"
是否可以使用 REST Assured 库来测试 SOAP 网络服务? 我在 SOAP UI 中有一堆测试套件,我需要检查是否有可能使用 REST Assured。 谁能建议这是否可能? 非常感谢任何评论。
REST-assured 不直接支持测试 SOAP 服务,但可以通过手动设置 SOAPAction
和 Content-Type
headers 并执行 HTTP POST
等。然后您可以 运行 对响应进行 XPath 断言,就像在 REST-assured.
我建议您也评估 Karate,因为它 built-in 支持 SOAP,并且还使 XML 操作更容易。
我给大家举个例子
Headers SOAPAction
和 Content-Type
是 强制性的 。您需要找到您的情况下的 SOAPAction header,有时是 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")
参数 o body() 是一个带有请求xml的字符串
headers("SOAPAction", "findSoapAction", "Content-Type", "text/xml")
"findSoapAction" 是一个带有 SOAPAction header 值的字符串,您应该猜到,而 "text/xml" 是您应该设置为 Content-Type header .
xmlPath.get("fatherNode.childNode");
returns节点的值。示例:
<fatherNode>
<childNode>value of the node</childNode>
</fatherNode>
get("fatherNode.childNode") returns "value of the node"