Cypress - 4000 毫秒后重试超时:预计找到元素 - 仅在 Jenkins 中

2023-12-25

我有一组赛普拉斯测试失败了,仅在我的詹金斯环境中。整个describe块无法找到元素。块中的每个测试都以相同的命令开始:

describe("This section of tests", () => {
  it("Test for something in this section", () => {
    cy.login(); // custom login command, works in all other test blocks
    setupPage(); // page setup function, no problems in all other test blocks
    cy.wait(10000); // desperation wait

    cy.get("#toggle-detail-pane-button").click(); // issue here!
    // all tests in block run more assertions and commands after this
  });

  // more similar tests in block
});

// more describe blocks that also use cy.login and setupPage, with no issue

当我在 cypress 测试 UI 中运行这些测试时,它们都通过了。当我在我的机器上的终端中运行它们时npx cypress run,他们通过了。当我 ssh 到远程 OpenStack 终端时,该终端设置为运行我的项目并运行 cypress,然后运行npx cypress run,他们通过了。

当我在 Jenkins 中运行测试时(它使用一些相同的 OpenStack 实例并行运行 cypress),测试始终失败,并显示以下消息:

AssertionError: Timed out retrying after 4000ms: Expected to find element: `#toggle-detail-pane-button`, but never found it.

      at Context.eval (http://localhost:3000/__cypress/tests?p=cypress/integration/stuff/mytests.spec.js:519:8)

我尝试过重新组织我的测试、重写它们等等,但没有成功。我不明白这里出了什么问题。我的 Jenkins 环境使用自定义抱歉-柏树 https://github.com/sorry-cypress/sorry-cypress设置,由于某种原因,仪表板没有注册测试,所以我无法去查看任何屏幕截图或视频(这是一个完全独立的蠕虫问题)。

为什么只有这些测试只会在我的 CI/CD 环境中失败?我怎样才能开始调试这个呢?

编辑:截图

我能够使用屏幕截图和视频重新运行 CI/CD,然后我能够scp将文件从测试失败的实例中删除。在我的机器上运行时,cypress 找到元素没有问题:

当在我的机器上使用 cypress 选择器游乐场时,它也找到了它:

但在屏幕截图中,我从运行完全相同的测试的 openstack 实例中拉出,它找不到它:

(Sorry for all the green, this is a proprietary app)

是什么赋予了?


请使用以下行更新 cypress.config.js 文件中的默认命令超时:

defaultCommandTimeout: 10000

您可以使用任何以毫秒为单位的时间值,而不是 10000。使用这个,您的超时问题将得到解决。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Cypress - 4000 毫秒后重试超时:预计找到元素 - 仅在 Jenkins 中 的相关文章

随机推荐