在进行端到端测试时如何正确 运行 我的应用程序?

How do I properly run my app when doing e2e tests?

我们有一个前端应用程序,我们想在 CI 服务器上对其进行端到端测试。最好的方法是什么?

整个测试应该 运行 在非图形用户界面 CI 上,使用单个命令可执行。

我会想到的是这样的:

concurrently "npm run serve" "npx cypress run"

但这似乎增加了巨大且不必要的开销。另外,我必须以某种方式确保在实际提供应用程序之前不会执行测试。

没有确定的解决方案,只是一些想法。我们正在使用一个 bash 脚本,它会导致使用一个命令启动测试。在那个 bash 脚本中我们有这个:


    # environment variables
    export HOME=${PWD}

    yarn install
    ./node_modules/.bin/cypress install
    ./node_modules/.bin/cypress verify

    ./node_modules/.bin/cypress run ${SMOKETEST}

如前所述Cypress continuous integration docs, you can use a npm package called wait-on等待你的服务器运行赛普拉斯:

npm run serve & # run this in the background
wait-on http://localhost:8000 && npm run cypress

使用 endly 自动化所有 e2e 工作流如何? e2e 测试运行程序。

启动应用程序并将测试委托给 cypress 可能如下所示

@test.yaml

pipeline:
  test:
    multiAction: true
    startApp:
      async: true
      action: exec:run
      commands:
        - npm run serve
    runTest:
      async: true
      action: exec:run
      commands:
        - wait-on http://localhost:8000 && npm run cypress