- ️setCookie
cy.setCookie("cookie_consent", "agreed")
- visit
cy.visit("https://www.kiwi.com")
- absolutecy.visit("/account/login")
– relative, will use baseUrl fromcypress.json
config
- go
cy.go("back") / cy.go("forward")
, same ascy.go(-1) / cy.go(1)
- reload
cy.reload()
- ️get
cy.get("h1.title")
/cy.get("[data-test='uniqueSelectorJustForTests']")
cy.get("#todos").as("todos") …then… cy.get("@todos")
- ️contains
cy.contains("Register")
cy.get("button").contains("Submit")
- focused
cy.focused()
- should
cy.get(…).should("have.class", "active")
cy.get(…).should("have.length", 5)
cy.get(…).should("be.disabled")
cy.get(…).should("contain", "Joe")
cy.get(…).should("not.contain", "Joe")
➡️ List of Assertions ⬅️
- click & dblclick
cy.get(»selector«).click()
cy.get(»selector matching multiple elements«).click({ multiple: true })
– use with caution!cy.get(»selector matching element which is hidden«).click({ force: true })
– use with caution!
- type & clear
cy.get(»input«).type("Brno")
cy.get(»input«).type("Br{downarrow}{enter}")
– e.g. testing autocompletecy.get(»input«).type("Slow typing", { delay: 1000 })
– use only when necessarycy.get(»input with some text already«).clear().type("New value")
- check & uncheck
cy.get(»terms&conditions checkbox«).check()
- select
cy.get(»nationality«).select("cz")
- focus & blur
cy.get(»input«).focus().should("have.class", "active")
cy.get(»input«).type("joe@gmail").blur().should("have.class", "invalid")
- submit
cy.get(»form«).submit()
- 🐨 some people prefer clicking on submit button / pressing "Enter" instead
- viewport
cy.viewport(1280, 1024)
cy.viewport("macbook-15")
cy.viewport("iphone-5", "portrait")
- scrollIntoView
cy.get("footer").scrollIntoView()
- scrollTo
cy.scrollTo(0, 500)
–x/right
,y/down
cy.get(»sidebar«).scrollTo("bottom")
- wait – milliseconds!
cy.wait(5000)
– use only when necessarily
- screenshot
cy.screenshot()
– automatic filename from test filename and test suite structurecy.screenshot(»filename«)
⚠️ Prefer selectors directly inside cy.get(»selector«)
😐 | 🤩 |
---|---|
cy.get("button").first() |
cy.get("button:first") |
cy.get("button").eq(3) |
cy.get("button:eq(3)") |
cy.get("button").not(".unwanted") |
cy.get("button:not(.unwanted)") |
cy.get("»modal«").find(»close btn«) |
cy.get("»modal« »close btn«") |
cy.get("tr").filter(".odd") |
cy.get("tr.odd") |