赛普拉斯超时值在设置时不起作用

Cypress timeout values not working when set

[2] Start: 18/03/2022, 17:10:16
[2]       1) Loading spinner should display first
[2] 
[2]   0 passing (7s)
[2]   1 failing
[2] 
[2]   1) Common
[2]        Page loading
[2]          Loading spinner should display first:
[2] 
[2]       AssertionError: Expected <div.ui.active.transition.visible.inverted.dimmer> not to exist in the DOM, but it was continuously found.
[2]       + expected - actual
[2] 
[2] 
[2]       at Context.eval (https://localhost:9090/__cypress/tests?p=integration/common.cypress.js:27567:12)
[2] 
[2] 
[2] 
[2] After Each: 18/03/2022, 17:10:22

所以从 StartAfter Each 是 6 秒。但是,我将超时值设置为远高于 6 秒:

  describe('Page loading', () => {
    it('Loading spinner should display first', () => {
      let sendResponse;
      const trigger = new Promise(resolve => {
        sendResponse = resolve;
      });

      cy.intercept(
        {
          method: 'GET',
          url: '/databases?Namespace=self',
          hostname: 'localhost',
        },
        request => {
          return trigger.then(() => {
            request.reply();
          });
        }
      );

      cy.visit('https://localhost:9090');
      log('Start: ' + new Date(Date.now()).toLocaleString());
      cy.getByTestId('loader-spinner', { timeout: 1000000000 })
        .should('be.visible', { timeout: 1000000000 })
        .then(() => {
          sendResponse();
          cy.getByTestId('loader-spinner', { timeout: 1000000000 }).should('not.exist', {
            timeout: 1000000000,
          }); // <--- second should
        });
    });

我不明白为什么第二个 should 没有等待。

您可以在 docs 中看到,目前您可以设置这些超时:

  1. 默认命令超时
  2. 执行超时
  3. 任务超时
  4. 页面加载超时
  5. 请求超时
  6. 响应超时

并且在您的测试中,您可以使用“defaultCommandTimeout”来更改默认超时

例如: cypress.json

{
  "defaultCommandTimeout": 5000
}

您可以在单个测试中只应用此配置。

it('slow test', { defaultCommandTimeout: 5000 },  () => {

  // will wait 5 seconds for element to appear in dom
  cy.get('slowElement')

})

Cypress.config() documentation

问题是我使用的测试库:

根据那个答案,getByTestId 立即失败,我应该使用的是 get