亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

等待元素沒有類 - 然后其他元素在 Cypress 中消失

等待元素沒有類 - 然后其他元素在 Cypress 中消失

慕碼人2483693 2023-08-10 09:36:06
我有一個流程,我將一些東西放入網上商店的購物車中,然后發生這種情況:我選擇選項并單擊“添加到購物車”。小延遲(如200ms)出現一個覆蓋層,帶有加載指示器(大約 1000 毫秒)覆蓋層消失。小延遲(如200ms)“添加到購物車”按鈕達到加載狀態(帶有旋轉器)加載狀態(旋轉器)消失產品被添加到購物車。轉到購物車(確認產品已添加)。我如何在 Cypress 中將其鏈接在一起?嘗試1小小的延遲和事情的順序把事情弄亂了。cy.get('.add_to_cart_button').click(); // Step 1cy.get('.overlay').should( 'not.be.visible' ); // Step 4cy.get('.add_to_cart_button').should( 'not.have.class', 'loading' ); // Step 7cy.visit( Cypress.env( 'baseUrl' ) + '/cart' ); // Step 9但片狀是不真實的!有時它會進入購物車,顯示一個空購物車(如果它檢查覆蓋層并且按鈕的加載狀態在小延遲內達到)。嘗試2我什至嘗試添加一些快速修復,添加cy.wait(3000)幾個地方。但即便如此,它還是給了我這個錯誤:wait 3000!! TypeErrorThe following error originated from your application code, not from Cypress.  > Cannot read property 'indexOf' of undefinedWhen Cypress detects uncaught errors originating from your application it will automatically fail the current test.This behavior is configurable, and you can choose to turn this off by listening to the uncaught:exception event.Learn more理想情況下,我應該檢查覆蓋層是否顯示然后隱藏,以確保事物的順序按照上述順序發生。我只是擔心它的顯示時間如此之短,賽普拉斯會錯過它的存在,從而導致更多的不穩定。
查看完整描述

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,


查看完整回答
反對 回復 2023-08-10
  • 1 回答
  • 0 關注
  • 217 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號