java - How to post complex XML using rest assured -
using rest-assured can perform get, post , other methods. in example below sending post api returns json response.
@test public void reservearide() { given(). header("authorization", "abcdefgh-123456"). param("rideid", "gffgr-3423-gsdgh"). param("guestcount", 2). when(). post("http://somewebsite/reserveride"). then(). contenttype(contenttype.json). body("result.message", equalto("success")); }
but need create post request complex xml body. body example:
<?xml version="1.0" encoding="utf-8"?> <request protocol="3.0" version="xxx" session="xxx"> <info1 param1="xxx" version="xxx" size="xxx" notes="xxx"/> <info2 param1="xxx" version="xxx" size="xxx" notes="xxx"/> </request>
how can this? thank in advance
i keep bodies in resources directory, , read them string using following method:
public static string generatestringfromresource(string path) throws ioexception { return new string(files.readallbytes(paths.get(path))); }
then in request can say
string myrequest = generatestringfromresource("path/to/xml.xml") given() .contenttype("application/xml") .body(myrequest) .when() .put("my.url/endpoint/") .then() statuscode(200)
Comments
Post a Comment