I am recently new in cypress, and I am dealing with a complex test. In this test I have to bring the urls that are hosted on Contentful, and verify that the content page does not come with an error message. The problem is in the line const data= new Uint8Array(response.body);, which brings me the empty array (response comes with data) Any suggestion helps me a lot to solve this problem
import { getPagesFromContentful } from '../../support/getPagesFromContentful';
import '../../support/commands';
describe('Mi prueba', () => {
beforeEach(() => {
cy.clearLocalStorage(); // Limpiar el almacenamiento local
cy.clearCookies();
});
it('prueba pagina parte 1', () => {
getPagesFromContentful().then((response) => {
cy.wrap(response).as('pagesUrls');
console.log(response);
const errores = [];
cy.get('@pagesUrls').each((url) => {
cy.request({
url: url,
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
failOnStatusCode: false, // No detener la prueba en caso de error de estado
responseType: 'arraybuffer',
}).then((response) => {
console.log('hola', response);
const body = JSON.parse(response.body);
console.log(body);
// Realizar las comprobaciones en el contenido
try {
cy.wrap(body).should('not.contain', 'error-page');
} catch (error) {
const errorMensaje = `Error en la posición ${url}: ${
error.message
}\n\nContenido del arreglo: ${JSON.stringify(body)}`;
//debugger;
errores.push(errorMensaje);
cy.log(errorMensaje);
//debugger;
}
});
});
if (errores.length > 0) {
// Si hay errores, mostrarlos y fallar el test
const errorMessage = `Se encontraron ${errores.length} errores:\n\n${errores.join('\n\n')}`;
cy.log(errorMessage);
throw new Error(errorMessage);
}
});
});
});