如何在Github Actions上运行端到端测试?
我正在尝试找出如何启动服务器,以便可以在其上运行端到端测试套件。
我们的示例中有一个Rails应用程序,其中包含一些Cucumber和Cypress测试。
如何在Github Actions上运行端到端测试?
我正在尝试找出如何启动服务器,以便可以在其上运行端到端测试套件。
我们的示例中有一个Rails应用程序,其中包含一些Cucumber和Cypress测试。
http.server
来运行服务器,或者启动一个rails服务器。.github/workflows
,然后在/workflows内创建test.yaml
文件。# .github/workflows/test.yml
name: Test
on: push # Trigger on push
jobs:
test:
name: Run tests
runs-on: ubuntu-16.04 # Specific version for Cypress
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.6' # Specify your version
- name: Cache gems # You can cache your gems to make the workflow run faster
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Install gems
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Start server in the background
run: |
bundle exec rails server &
sleep 5 &&
curl http://localhost:3000 -I
# Add step for running cucumber tests here
- name: Run Cypress
uses: cypress-io/github-action@v1
with:
browser: chrome
headless: true
- name: Upload screenshots as artifacts
uses: actions/upload-artifact@v1
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
- name: Upload videos as artifacts
uses: actions/upload-artifact@v1
if: always()
with:
name: cypress-videos
path: cypress/videos
当你提交并推送文件后,请前往你的 Github 仓库的“Action”选项卡,检查它是否正常工作或者需要调试。
此外,我建议你查看这篇文章:https://boringrails.com/articles/building-a-rails-ci-pipeline-with-github-actions/。