簡體   English   中英

賽普拉斯失敗的電子郵件通知

[英]Cypress failed email notification

我使用 cypress.io 作為自動化工具,當我的 cypress 測試失敗時,我需要發送電子郵件通知。 有什么辦法嗎?

您始終可以通過命令行將其鏈接到另一個工具。 基本上,您將退出代碼 (-1) 傳遞給 if 語句,然后運行郵件命令

一個例子是在這個 SO: https : //serverfault.com/questions/252448/bash-script-alert-on-error

cypress run
if [ $? -ne 0 ]
then
    mailx -s "FAIL" your@email.com

相反,您應該使用Module API 您可以從 javascript 文件運行 cypress 並獲取運行 cypress 的結果。

檢查這里。 https://github.com/cypress-io/cypress/issues/7441#issuecomment-632535986

下面是一個示例 javascript。

// e2e-run-tests.js
const cypress = require('cypress')

cypress.run({ headless: true, browser: 'chrome' })
  .then(result => {
    const testResults = JSON.stringify(result, null, 2);
    // Module API uses "if (result.failures)", that didn't worked for me. That's why I check with "totalFailed > 0"
    if (result.totalFailed > 0) {
      console.log('Failure(s) in tests! Will send an e-mail')
      sendEmail(testResults);
    }
    process.exit(0);
  })
  .catch(err => {
    console.log('Cypress didn't worked due to some error')
    process.exit(0);
  });

另外,請注意,在sendEmail方法中,您應該調用process.exit(0); 郵件發送后。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM