1 回答

TA貢獻1875條經驗 獲得超3個贊
我認為您錯過了一些步驟,因為就像在此網絡研討會中一樣,cypress 可以看到在實現步驟 1 并且加載尚未開始時頁面中缺少該元素,因此它給出了誤報斷言。我對這種情況的解決方案是向測試添加更多步驟,而不是使用固定cy.wait()
- 我的步驟如下:
cy.get('.add_to_cart_button').click(); // Step 1
cy.get('.overlay').should( 'be.visible' ); // Needed to see that the process is starting
cy.get('.overlay').should( 'not.be.visible' ); // Needed to see that the process has ended
cy.get('.add_to_cart_button').should( 'have.class', 'loading' ); // Needed to see that the process is starting
cy.get('.add_to_cart_button').should( 'not.have.class', 'loading' ); // Needed to see that the process has ended
cy.visit( Cypress.env( 'baseUrl' ) + '/cart' ); // Step 9
我還建議在 cypress.json 文件中使用以下行:
"defaultCommandTimeout": 60000,
"requestTimeout": 60000,
"responseTimeout": 60000,
添加回答
舉報