天天看點

Cypress web自動化10-Navigation 導航功能(go,reload,visit)

前言

web頁面上的導航功能,上一頁,下一頁,重新加載頁面,直接通路頁面。

cy.go()

cy.location('pathname').should('include', 'navigation')

cy.go('back')
cy.location('pathname').should('not.include', 'navigation')

cy.go('forward')
cy.location('pathname').should('include', 'navigation')

// clicking back
cy.go(-1)
cy.location('pathname').should('not.include', 'navigation')

// clicking forward
cy.go(1)
cy.location('pathname').should('include', 'navigation')
           

cy.reload()

cy.reload()

// reload the page without using the cache
cy.reload(true)
           

cy.visit()

cy.visit('https://example.cypress.io/commands/navigation', {
  timeout: 50000, // increase total time for the visit to resolve
  onBeforeLoad: function(contentWindow){
    // contentWindow is the remote page's window object
  },
  onLoad: function(contentWindow){
    // contentWindow is the remote page's window object
  }
})
           

繼續閱讀