如何确保页面在Cypress中完全加载

时间:2019-03-27 09:49:38

标签: user-interface cypress

我在柏树工作。 复制步骤

我只是通过cy.visit()-spinner加载来访问登录页面 通过类型旋转器传递的凭据仍在加载 单击提交。-spinner仍在加载  它的抛出错误..为什么因为登录页面XHR调用未完成而又是为什么仍可以看到微调器顶部加载并且我试图在加载之前单击提交按钮,原因可能是网络报告无效的凭据。 / p>

2 个答案:

答案 0 :(得分:1)

我相信您必须等待XHR请求完成并验证页面加载或执行其他操作。

这是一个样本

{{1}}

这是我之前提供的类似解决方案-Cypress:Is there any way to check invisibility of an element

答案 1 :(得分:0)

您检查按钮是否存在,然后单击按钮。如果

describe('check if button present', function () {
    it('check for button using CSS Selector', function () {
      cy.visit(url)
      let found = false
      let count=0
      while (!found) {

        const nonExistent = Cypress.$('.btn-selector')

        if (!nonExistent.length) {
          found = false
          count=count+1
          cy.wait(1000)
          if(count==60)
          {
            found = true
            cy.log('Element not found after 60 seconds..Exit from loop!!!')
          }
        } 
        else 
        {
          found = true
          cy.get('.btn-selector').click()
        }

      }

    })
  })
相关问题