Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

253
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!