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

238
Vistas
Cypress - extract value from XML response

I am having problems retrieving a value from an XML response when using Cypress to make the API request. The API returns a 200, and I can see the response body, as expected, in the browser console.

I have tried the following after much research online, however the 'Price' value returned is undefined.

Guidance would be much appreciated.

/// <reference types="cypress" />

it('Submit test', () => {
    cy
      .readFile('../fixtures/test1.xml')
      .then(fetchXML)
      .then(responseFromXML  => {
          expect(responseFromXML.status).to.eq(200)

      const parser = new DOMParser();
      const xmlDOM = parser.parseFromString(responseFromXML,"text/xml");
      const value = xmlDOM.getElementsByTagName("Price")[0];
      console.log("Extracted value is "+value)
      })
  
    function fetchXML(xml_body) {
      return cy.request({
        url: Cypress.env('test_endpoint'),
        method: 'POST',
        body: xml_body,
        headers: {
          'Content-Type': 'application/xml',
        },
      })
  }
})

Please see sample XML response below. I suspect the issue is with line

const value = xmlDOM.getElementsByTagName("Price")[0];

XML Response:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP:Body>
        <tns:CreateV2ResponseParameter xmlns:tns="http://ws.xxx.com/wsdl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <tns:PriceList>
                <tns:PriceDetails>
                    <tns:Price>211</tns:Price>
                </tns:PriceDetails>
            </tns:PriceList>
        </tns:CreateV2ResponseParameter>
    </SOAP:Body>
</SOAP:Envelope>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

looks like you pass incorrect value to the parser here:

parser.parseFromString(responseFromXML,"text/xml");

it should probably be responseFromXML.body:

parser.parseFromString(responseFromXML.body,"text/xml");
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