Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda