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

问题描述 投票:0回答:5

我有一组 Cypress 测试失败,仅在我的 Jenkins 环境中。整个

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 环境使用自定义的 sorry-cypress 设置,由于某种原因,仪表板没有注册测试,所以我无法查看任何屏幕截图或视频(这是一个完全独立的蠕虫问题) ).

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

编辑:截图

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

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

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

(抱歉所有绿色,这是专有应用程序)

什么给予?

javascript jenkins cypress end-to-end
5个回答
8
投票

scp

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


2
投票


0
投票


0
投票
Vite + Cypress :如何防止重新加载(由于优化的依赖项)导致测试失败?

解决该问题的唯一方法是在最初的重新加载引发了测试。 defaultCommandTimeout: 10000



-3
投票

我来自:

describe( 'ensure xyz works', { retries: { runMode: 2, openMode: 1 } }, () => { it('Should ...', () => { cy.visit('/...') cy.contains('Continue').click() // previously would consistently get stuck here cy.url().should('include', '/next-page') ... }) } )

cy.get('#mat-options-text').click()

© www.soinside.com 2019 - 2024. All rights reserved.