Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
cypress test webservice response (xml)

Is there a simple way to test API calls and test the response of that calls? For now we do stuck at a simple xml response from within the reponse itself. We like to use xpath (cypress plugin) to crawl the xml like:

cy.request(`${DOCUMENT_FACADE}`).then((response) => {
  //response is a valid JSON and its body property holds a string (xml)  

  cy.get(response.body).xpath("//*[name() = 'myName']") //this fails by "Not a DOM Object"
  
  //Then we tried to give it a DOM object
  var parser = new DOMParser(),
      doc = parser.parseFromString(response.body, 'text/xml');
  cy.get(doc).xpath("//*[name() = 'myName']").should('have.length', 1) //fails with "expected undefined to have a length of 1 but got 0
});

Maybe we totally got something wrong about this quite important part of testing I assume.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You definitely need the DOMParser, otherwise you're just chopping up a string which xpath won't do too well.

But cy.get(doc) is using the DOM as a selector on the previously loaded page (which is not loaded).

You might get it done with cy.wrap(doc), which wraps that whole document and passes it to .xpath().

Or you might need to extract the body first cy.wrap(doc).its('body').xpath().

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!