2017-07-07 70 views
1

是否有可能使用REST Assured库来测试SOAP Web服务? 我有一堆SOAP UI中的测试套件,我需要检查是否有使用REST Assured的可能性。 任何人都可以建议,如果这是可能的? 非常感谢您的任何意见。使用REST Assured库来测试SOAP Web服务

回答

0

REST-放心不具备测试SOAP服务的直接支持,但可以通过手动设置SOAPActionContent-Type头,做一个HTTP POST等等,那么你可以在响应运行的XPath断言像你这样做正常REST服务中的REST保证。

我建议你也评估Karate,因为它内置了对SOAP的支持,同时也使XML操作变得更容易。

0

在这里,我告诉你一个例子

页眉SOAPActionContent-Type强制性。你需要找到至极你的情况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"; 

是的网址,其中,使所述请求

given().request().body("xml_text") 

的参数Ô体()是与所述请求

012的XML字符串

“findSoapAction”是一个带有您应该猜到的SOAPAction头的值的字符串,“text/xml”是您应该设置为Content-Type头的内容。

xmlPath.get("fatherNode.childNode"); 

返回节点的值。例如:

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

GET( “fatherNode.childNode”)返回

“的节点的值”