bpricilla
(Pricilla B)
August 30, 2020, 2:27pm
1
@odanylewycz , After watching your video I got a good understanding of the Cheerio usage in SOAP assertions. But I am facing some issues.
Below is the code snippet,
var cheerio = require(âcheerioâ);
pm.test(âCheerioâ,() => {
const $ = cheerio.load(responseBody,{
ignoreWhitespace: true,
xmlMode: true
});
//Render XML
console.log(âEntering logicâ);
console.log($.xml());
pm.test("Using Cheerio ", function ()
{
pm.expect($(âNumberToWordsâ).attr(âxmlnsâ)).to.eql(âhttp://www.dataaccess.com/webservicesserver/ â)
});
});
Using the Public SOAP API Calculator -> âAddâ folder
Getting the error "Using Cheerio | AssertionError: expected undefined to deeply equal âhttp://www.dataaccess.com/webservicesserver/ â"
odanylewycz
(Orest Danylewycz)
August 30, 2020, 4:14pm
2
Hi @bpricilla !
Welcome to the community !
Thanks for watching my video! Iâm glad it was helpful thus far.
As for your assertion error, can you explain what youâre trying to achieve? It looks like youâre trying to see if xmlns value equals that website text, right?
Can you print out the xml and the attribute statements? That should help us see if the values are being properly referenced and pulled out from the xml.
Best,
Orest
odanylewycz
(Orest Danylewycz)
August 30, 2020, 5:16pm
3
Also, @bpricilla , looks like doing a POST request to
https://www.dataaccess.com/webservicesserver/NumberConversion.wso
With an empty request body returns the following JSON
{
âidâ: 101
}
So using cheerio here would not be useful, unless I am missing something here with my request? And if so, let me know.
bpricilla
(Pricilla B)
August 30, 2020, 5:45pm
4
Yes body is as below
Request Body:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap=âhttp://schemas.xmlsoap.org/soap/envelope/ â>
soap:Body
<NumberToWords xmlns="http://www.dataaccess.com/webservicesserver/">
<ubiNum>500</ubiNum>
</NumberToWords>
</soap:Body>
</soap:Envelope>
Response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap=âhttp://schemas.xmlsoap.org/soap/envelope/ â>
<soap:Body>
<m:NumberToWordsResponse xmlns:m="http://www.dataaccess.com/webservicesserver/">
<m:NumberToWordsResult>five hundred </m:NumberToWordsResult>
</m:NumberToWordsResponse>
</soap:Body>
</soap:Envelope>
I am just trying to add some assertions using Cheerio, instead of accessing the response nodes directly. like below:
pm.test("Using Cheerio ", function ()
{
pm.expect($(âm:NumberToWordsResponseâ).attr(âxmlnsâ)).to.eql(âhttp://www.dataaccess.com/webservicesserver/ â)
pm.expect($(âm:NumberToWordsResultâ)).to.eql(âfive hundredâ)
});
You can try any assertion to this response, using cheerio.
odanylewycz
(Orest Danylewycz)
August 31, 2020, 2:48am
5
Hi @bpricilla ,
Thanks for the details! I canât seem to get the same response that you have, given the information provided. I receive a 415 Unsupported Media Type Error, refer to the screenshot below:
However, since you provided the response body, I was able to test against it by defining a static variable to contain the xml.
After enough testing, I was able to figure it out. To get value you are looking for, try this:
$('m\\:NumberToWordsResponse').attr('xmlns:m')
That should get you the text value of the xmlns:m attribute.
And applying it in a test as you have seemed to work as well.
I hope this helps!
Orest
1 Like
bpricilla
(Pricilla B)
August 31, 2020, 3:08am
6
Thanks a lot for your time and effort
I am just using the public SOAP API from
Also the snippet you shared is working, but when I try the same to do for other assertions its not working .
pm.test("Using Cheerio ", function ()
{
pm.expect($(âm\:NumberToWordsResponseâ).attr(âxmlns:mâ)).to.equal(âhttp://www.dataaccess.com/webservicesserver/ â)
pm.expect($(âm\:NumberToWordsResultâ)).to.eql(âfive hundredâ)
});
Please advice. Am I missing something?
Also should I save the response body directly to a variable or I should I store it in text format.
odanylewycz
(Orest Danylewycz)
August 31, 2020, 10:25am
7
Hi @bpricilla ,
Thanks for showing me what youâre using. Not sure why it wasnât working for me, but nonetheless when I see you assertion for the screenshot, it looks like you want to compare the actual text from the tag. In this case, you want it to look like the following:
pm.expect($(âm\\:NumberToWordsResultâ).text()).to.eql(âfive hundredâ)
That should get you the inner text you are looking to compare.
https://cheerio.js.org has some great documentation as well that will be really helpful .
1 Like
bpricilla
(Pricilla B)
August 31, 2020, 10:37am
8
@odanylewycz Thanks a lot, its working Great help!!
1 Like
odanylewycz
(Orest Danylewycz)
August 31, 2020, 12:59pm
9
Youâre welcome @bpricilla ! Glad itâs working as expected and always glad to help!
I ran into the same issue of 415 unsupported media type using postman. My resolution was to change the Content-Type header from application/xml to text/xml