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

251
Vistas
Posting result data to a website (like API or a telegram bot) after a test on Cypress

I've finished writing my first Cypress test. Everything is good except I'm struggling to post the result data to a website. Because I want to send the result data and also if any errors occurs the result screenshot to our coworker telegram group.

For the last two days I've tried everything and couldn't find any solution.

I've tried those in my test script (cypress/integration/test.js);

Cypress.on('test:after:run', (test, runnable) => {

  console.log('test,runnable', test, runnable)

  const details = {
    projectKey: Cypress.env('zephyr-project-key'),
    testName: test.invocationDetails.relativeFile,
    status: test.status,
    error: runnable.err.message,
    retries: runnable.retries.length,
    duration: test.wallClockDuration,
    startTime: test.wallClockStartedAt
  }
  
  cy.request('POST', 'http://mywebsite.com/notify.php', { body: details })

  fetch('http://mywebsite.com/notify.php')
         
})

Also this didn't work (cypress/plugins/index.js);

module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
    on('after:run', (results) => {
        if (results) {
        // results will be undefined in interactive mode
         console.log(results.totalPassed, 'out of', results.totalTests, 'passed')

          fetch('http://mywebsite.com/notify.php');
     
         }
     })
}

Edit: This is day 3 and I still couldn't solve this. What I've seen from Cypress help page is that cy.task() calls do not fire in 'test:after:run' event block;

https://github.com/cypress-io/cypress/issues/4823

I've seen some telegram groups who can do what I'm trying to do. All I need is to be able to get the results and post it to my website.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The third parameter to cy.request() is body, you don't have to wrap it.

Cypress.on('test:after:run', (test, runnable) => {

  const details = {
    projectKey: Cypress.env('zephyr-project-key'),
    testName: test.invocationDetails.relativeFile,
    status: test.status,
    error: runnable.err?.message,           // need err?.message if there is no error
    retries: runnable.retries.length,
    duration: test.wallClockDuration,
    startTime: test.wallClockStartedAt
  }
  
  cy.request('POST', 'http://mywebsite.com/notify.php', details)  // don't wrap details
    .then(res =>  expect(res.status).to.eq(201))                  // confirm result

})
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