1

当我尝试通过 cypress 执行断言并且只需要一些帮助时,我收到了一个奇怪的错误。我要做的只是显示一个选项已添加到投注单中。

我收到的错误是:

get Object{5}

assert expected { Object (0, length) } to be visible

Timed out retrying after 4000ms: Cannot read properties of undefined (reading 'toLowerCase')

这发生在这一步:

And ("The number of elements is {string}", (number) => {
  cy.get(elements.selection()).should('be.visible').should('have.length', number);
})

它指向的元素是:

class Elements {

    selection(){
        return cy.get('.__selection')
    }
}

export default Elements

   
4

1 回答 1

1

你已经翻倍了cy.get()

cy.get(elements.selection()).should('be.visible')

selection(){
  return cy.get('.__selection')
}

任何一个

elements.selection().should('be.visible')

selection(){
  return cy.get('.__selection')
}

或者

cy.get(elements.selection()).should('be.visible')

selection(){
  return '.__selection'
}
于 2021-09-10T23:39:31.293 回答