Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda