【问题标题】:Cypress test not finding element when ran in Gitlab CI赛普拉斯测试在 Gitlab CI 中运行时未找到元素
【发布时间】:2021-09-19 06:48:16
【问题描述】:

我正在使用 Cypress 进行自动化测试。使用 Next.js 在 React 中构建的应用

测试在本地通过 cypress 打开和 cypress 运行但在 GitLab CI 中失败。

我访问 URL cy.visit('localhost:8000/cadastro/login/?next=/')

输入用户名cy.get('#id_username').type("username_here")

输入密码cy.get('#id_password').type("password_here")

然后点击登录按钮cy.get('.btn').click()

一切正常,但是当页面进入应用程序并重新加载到localhost:8000/#/时,我验证了一条包含“你好,名字!”的消息,

cy.get('#dropdownMenuButton').contains(`Hello, ${firstName}`);

我从 CI runner 得到这个错误输出:

AssertionError: Timed out retrying after 4000ms: Expected to find element: `#dropdownMenuButton`, but never found it.

我尝试增加超时但不起作用

【问题讨论】:

  • 您能否在您的 CI 中检查登录后显示的元素 Hello, ${firstName}

标签: gitlab continuous-integration gitlab-ci cypress gitlab-ci-runner


【解决方案1】:

听起来你需要在 Gitlab 中启动服务器,这里Next.js Cypress GitLab CI example 是一个如何做的例子

基本上,

package.json

{
  "scripts": {
    "cy:citest": "start-server-and-test start http://localhost:3000 cy:run",
    ...

【讨论】:

  • 其实我不认为这是这里的问题。它找不到元素,但服务器似乎正在运行。
【解决方案2】:

我目前有同样的问题。您是否尝试过清除 GitLab 运行器缓存并重新运行管道?这应该是第一件事。

目前,我还没有找到适合我的案例的解决方案,但我正在努力解决,当我找到解决方案时会通知您。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-16
    • 2019-12-27
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    • 2018-08-01
    相关资源
    最近更新 更多