简体   繁体   English

如何在 GitHub 操作上使用 Cypress CI 运行和连接到仿真器?

[英]How to Run & Connect to Emulators with Cypress CI on GitHub Actions?

I am trying to run e2e Cypress tests on Github actions.我正在尝试对 Github 操作运行 e2e Cypress 测试。 I build functions, run an emulator and start cypress like to: npx nx build functions | firebase emulators:start | nx e2e frontend-e2e --watch我构建函数,运行模拟器并启动 cypress,例如: npx nx build functions | firebase emulators:start | nx e2e frontend-e2e --watch npx nx build functions | firebase emulators:start | nx e2e frontend-e2e --watch

This works well on localhost, but fails on GitHub Actions, when the first part of the code tries to connect to the emulators.这在本地主机上运行良好,但在 GitHub 操作上失败,当代码的第一部分尝试连接到模拟器时。

  cy.request(
    "DELETE",
    "http://localhost:9099/emulator/v1/projects/****/accounts"
  );

It can't reach the emulator on port localhost:9099 , as I would normally do on localhost.它无法到达端口localhost:9099上的模拟器,就像我通常在 localhost 上做的那样。

  1) Login
       runs setup:
     CypressError: `cy.request()` failed trying to load:

http://localhost:9099/emulator/v1/projects/****/accounts

We attempted to make an http request to this URL but the request failed without a response.

Is there something I need to do about connecting to localhost port on GitHub Actions ?关于连接到 GitHub Actions 上的本地主机端口,我需要做些什么吗?

Solved, The Firebase emulator was throwing an error: but I haven't seen it because I ran it on one line with other commands: npx nx build functions | firebase emulators:start | nx e2e frontend-e2e --watch已解决,Firebase 模拟器抛出一个错误:但我没有看到它,因为我在一行上与其他命令一起运行它: npx nx build functions | firebase emulators:start | nx e2e frontend-e2e --watch npx nx build functions | firebase emulators:start | nx e2e frontend-e2e --watch

I rewrote the job in the workflow:我重写了工作流程中的工作:

      - name: Cypress run
        uses: cypress-io/github-action@v2
        with:
          browser: chrome
          build: npm run integration:build
          start: |
            npm run integration:emulate
            npm run integration:test

Calling custom scripts from package.json like so:package.json调用自定义脚本,如下所示:

    "integration:build": "nx build functions && nx run frontend:build",
    "integration:emulate": "firebase use default && firebase emulators:start",
    "integration:test": "nx e2e frontend-e2e --watch",

Then I could see the Firebase error in the log and fixed them.然后我可以在日志中看到 Firebase 错误并修复它们。 There were two issues:有两个问题:

  1. Selecting a project before running the emulators (adding firebase use default )在运行模拟器之前选择一个项目(添加firebase use default
  2. Firebase login ( great answer from the Firebase team ) Firebase 登录( 来自 Firebase 团队的出色回答

After that, the emulators worked just as on localhost之后,模拟器就像在本地主机上一样工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 github 操作上运行 firebase 模拟器 - Run firebase emulators on github actions 如何在 gitlab CI 上运行的同一端口上运行本地赛普拉斯测试? - How to run locally Cypress test on the same port as they are run at gitlab CI? 赛普拉斯 CI:错误:连接 ECONNREFUSED 127.0.0.1:3000 - Cypress CI: Error: connect ECONNREFUSED 127.0.0.1:3000 npm CI && npm run build 在 github 操作中失败,我正在使用 firebase 部署项目 - npm CI && npm run build is failing in github actions, I'm using firebase to deploy the project 如何在 github 操作中连接到 docker 容器? - How can I connect to a docker container in github actions? 如何从 gitlab/github 上的 gitlab-ci CI/CD 运行 curl 命令? - How to run curl commands from gitlab-ci CI/CD on gitlab/github? 如何运行 firebase 实验:使用 GitHub 操作启用 webframeworks? - How can run firebase experiments:enable webframeworks with GitHub actions? 如何删除 Github 工作流程,Azure Webapp CD / CI with Github Repo - How to remove Github workflow, Azure Webapp CD / CI with Github Repo botocore.exceptions.NoRegionError:您必须指定区域。 GitHub 使用 AWS 的 CI/CD 管道的操作 - botocore.exceptions.NoRegionError: You must specify a region. GitHub Actions with CI/CD Pipeline with AWS AWS Credentials 如何在 GitHub Actions 中工作? - How AWS Credentials works at GitHub Actions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM