admin管理员组文章数量:1405343
I have an api, which return xml data.
I am writing a testcase in cypress, through which I am requesting that api, which returns following data
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Student>
<Roll>55</Roll>
<Name>ABC</Name>
</Student>
How do I parse this response body and get Name
of the student from this response ?
I have an api, which return xml data.
I am writing a testcase in cypress, through which I am requesting that api, which returns following data
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Student>
<Roll>55</Roll>
<Name>ABC</Name>
</Student>
How do I parse this response body and get Name
of the student from this response ?
1 Answer
Reset to default 6Synchronously, with jQuery
const xml = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Student>
<Roll>55</Roll>
<Name>ABC</Name>
</Student>`
it('parses the student name from xml', () => {
function xmlProperty(xml, property) {
return Cypress.$(Cypress.$.parseXML(xml)).find(property).text()
}
const name = xmlProperty(xml, 'Name')
console.log(name)
})
or in a Cypress mand chain
const xml = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Student>
<Roll>55</Roll>
<Name>ABC</Name>
</Student>`
it('parses student name in a Cypress mand', () => {
cy.wrap(Cypress.$(xml))
.then(xml => xml.filter('student').find('name').text())
.should('eq', 'ABC')
})
本文标签: javascriptCypress parse XML responseStack Overflow
版权声明:本文标题:javascript - Cypress parse XML response - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744876643a2629951.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论