1. 程式人生 > 實用技巧 >Cypress系列(43)- wait() 命令詳解

Cypress系列(43)- wait() 命令詳解

如果想從頭學起Cypress,可以看下面的系列文章哦

https://www.cnblogs.com/poloyy/category/1768839.html

作用

等待數毫秒或等待別名資源解析,然後再繼續執行下一個命令

語法格式

cy.wait(time)
cy.wait(alias)
cy.wait(aliases)
cy.wait(time, options)
cy.wait(alias, options)
cy.wait(aliases, options)

引數講解

正確格式

cy.wait(500)
cy.wait('@getProfile')

方法返回的物件

當傳了 time 時

cy.wait() 產生與上一個命令相同的主題

當傳了 alias 時

cy.wait() 產生一個物件,其中包含 XHR 的 HTTP 請求和響應屬性

別名的栗子

cy.server()
cy.route('activities/*', 'fixture:activities').as('getActivities')
cy.route('messages/*', 'fixture:messages').as('getMessages')

// visit the dashboard, which should make requests that match
// the two routes above
cy.visit('http://localhost:8888/dashboard') // pass an array of Route Aliases that forces Cypress to wait // until it sees a response for each request that matches // each of these aliases cy.wait(['@getActivities', '@getMessages']) // these commands will not run until the wait command resolves above cy.get('h1').should('contain', 'Dashboard')