05 Cypress Methods - biswajitsundara/Cypress GitHub Wiki
Browser Related Commands
1. Visit URL [ cy.visit(url) ]
- Visit methods open URL in browser
cy.visit('https://www.google.com/')
This will open the url google.com
- Cypress recommends to use
"baseURL"
in conjuction with cy.visit()
method
- In
cypress.json
mention the "baseUrl"
and then in visit method just append the page.
- For example, if we set the
"baseUrl"
as "https://www.google.com/"
and cy.visit("/images")
- Then it will open
https://www.google.com/images
- You see the
cy.visit(url)
method always appends the url with base url
- If there's no
baseUrl
then it will open the url
provided inside the method.
- cypress doesn't support url that doesn't start with
"http"
or "https"
- We can also change the default time out while opening the url
cy.visit('/index.html', { timeout: 30000 })
- This will wait for the url to load
30 seconds
- The
cy.visit()
method waits for the page to fire it's load event
- It may time out waiting for the page to fire its
load event
.
2. Then Command [ .then() ]
- The then() command allows us to work with the subject yielded from the previous command
- It works in same way as promises work
- Then command can be used for
debugging
, extract values
, aliases
- Example:
cy.get('.nav').then(($nav) => {})