[英]Using REST Assured library for testing SOAP webservices
是否可以使用REST保證庫來測試SOAP Web服務? 我在SOAP UI中有一堆測試套件,我需要檢查是否有使用REST保證的可能性。 誰能建議這是否可能? 非常感謝您的任何評論。
這里我給你看一個例子
標頭SOAPAction
和Content-Type
是必需的 。 您需要找到最適合您情況的SOAPAction標頭,有時是網址中最后一個“ /”的下一部分
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")
參數o body()是帶有請求xml的字符串
headers("SOAPAction", "findSoapAction", "Content-Type", "text/xml")
“ findSoapAction”是一個帶有您應該猜測的SOAPAction標頭的值的字符串,而“ text / xml”是應設置為Content-Type標頭的內容。
xmlPath.get("fatherNode.childNode");
返回節點的值。 例:
<fatherNode>
<childNode>value of the node</childNode>
</fatherNode>
get(“ fatherNode.childNode”)返回“節點的值”
REST保證不直接支持測試SOAP服務,但是可以通過手動設置SOAPAction
和Content-Type
標頭並執行HTTP POST
等操作來實現。然后,您可以像對普通REST服務一樣在響應上運行XPath斷言在REST保證下。
我建議您還評估Karate,因為它具有對SOAP的內置支持,並且還使XML操作更加容易。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.