我希望 GitHub Actions 自动运行 cypress 测试,但运行 40 分钟后测试失败,我无法确定发生了什么。
name: Cypress Tests
on:
workflow_dispatch:
# The cron is set on UTC Time
schedule:
- cron: '0 15 * * *'
jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
# Install NPM dependencies, cache them correctly
- name: Yarn install
run: yarn install
# Get information date to put on the report file name
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
# Run Cypress Test
- name: Cypress run
id: cypress
continue-on-error: true
uses: cypress-io/github-action@v4
with:
build: yarn build
start: yarn start:staging
# Combine all the report in one file
- name: Combine Cypress reports
run: yarn mochawesome-merge ./cypress/reports/mochawesome-reports/*.json -o ./cypress/reports/combined-report-${{ steps.date.outputs.date }}.json
# Convert the report to HTML Format
- name: Generate HTML from JSON report
run: yarn marge ./cypress/reports/combined-report-${{ steps.date.outputs.date }}.json --reportDir ./cypress/reports --inline
# Upload file on the Github Action Job Summary
- name: Upload file
uses: actions/upload-artifact@v3
with:
name: 'Cypress-Test-Report-${{ steps.date.outputs.date }}'
path: /home/runner/work/frontend/frontend/cypress/reports/combined-report-${{ steps.date.outputs.date }}.html
# Get test failure information to send on Slack channel
- name: Get test failure information from Cypress report
id: set_var
run: |
content=`cat /home/runner/work/frontend/frontend/cypress/reports/combined-report-${{ steps.date.outputs.date }}.json`
content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"
echo "::set-output name=packageJson::$content"
# Send Cypress test information to Slack channel
- name: Send GitHub Action trigger data to Slack
id: slack
uses: slackapi/[email protected]
with:
channel-id: '#1_bug_reporting'
payload: |
{
"text": "Cypress Tests date: ${{ steps.date.outputs.date }}\nCypress Tests finished with ${{fromJson(steps.set_var.outputs.packageJson).stats.failures}} Failed\nSee results at: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Cypress Tests date: ${{ steps.date.outputs.date }}\nCypress Tests finished with ${{fromJson(steps.set_var.outputs.packageJson).stats.failures}} Failed\nSee results at: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
其中大多数的失败信息是
AssertionError: Timed out retrying after 4000ms: expected '/login' to equal '/orgs/dev-e2e-advanced'
at Context.eval (http://localhost:3000/__cypress/tests?p=cypress/support/e2e.ts:118:29)
你可以从基础开始:
您的 Yaml 文件:
name: End-to-end tests
on: [push]
jobs:
cypress-run:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
# Install NPM dependencies, cache them correctly
# and run all Cypress tests
- name: Cypress run
uses: cypress-io/github-action@v4
这个话题有解决方案吗?我面临着同样的问题。谢谢!