【问题标题】:cypress should have class assertion not working柏树应该有类断言不起作用
【发布时间】:2021-06-28 23:38:53
【问题描述】:

以下测试工作正常

  it('button has "contact-next-disabled" class', () => {
    cy.get('a[rel="next"]')
  })

  it('button has "contact-next-disabled" class', () => {
    cy.get('.contact-next-disabled')
  })

但如果我将它们与应该断言结合起来

  it('button has "contact-next-disabled" class', () => {
    cy.get('a[rel="next"]').should('have.class', '.contact-next-disabled')
  })

Cypress 给我一个断言错误

Timed out retrying after 4000ms: expected '<a.contact-next-disabled>' to have class '.contact-next-disabled'

为什么会这样?

【问题讨论】:

    标签: reactjs cypress end-to-end


    【解决方案1】:

    您必须从类名中删除.,它应该可以工作。

    cy.get('a[rel="next"]').should('have.class', 'contact-next-disabled')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-27
      • 2021-04-25
      相关资源
      最近更新 更多