【问题标题】:Cypress: how to test loadmore button赛普拉斯:如何测试加载更多按钮
【发布时间】:2020-03-29 08:28:51
【问题描述】:

我有一个加载更多按钮加载帖子和一个涵盖加载操作的赛普拉斯测试。我怎么能告诉赛普拉斯重复该步骤直到按钮消失(例如,不再加载任何内容?)。如果不知道需要点击多少次?

一次迭代我检查以下方式:

cy.get('#loadmore').click();
cy.get('#loadmore').contains(text.loading);

cy.wait('@loadPosts')

cy.get('.blog').find('.article').should('have.length', n+5)
cy.get('#loadmore').contains(text.loadmore)

【问题讨论】:

    标签: cypress


    【解决方案1】:

    仅供参考,这不是 e2e 测试的正确行为,因为您应该始终知道必须单击按钮多少次。 但作为一种解决方法,我想你可以使用这样的东西:

    // your cypress test code
    it('does something different based on the class of the button', function () {
      // RERUN THIS TEST OVER AND OVER AGAIN
      // AND IT WILL SOMETIMES BE TRUE, AND
      // SOMETIMES BE FALSE.
    
      cy.get('button').then(($btn) => {
        if ($btn.hasClass('active')) {
          // do something if it's active
        } else {
          // do something else
        }
      })
    })
    

    参考链接https://docs.cypress.io/guides/core-concepts/conditional-testing.html#The-DOM-is-unstable

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-14
      • 1970-01-01
      • 2021-10-20
      • 2020-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多