Good enough for ~ 90 % of cases.
cy.get('
:
#firstname
→ Selects the element withid="firstname"
.intro
→ Selects all elements withclass="intro"
.name1.name2
→ Selects all elements with bothname1
andname2
set within its class attribute.name1 .name2
→ Selects all elements with name2 that is a descendant of an element with name1[class*=Workshop]
-> Selects all classes starting withWorkshop
[data-testid=Forex]
-> Select an element with an attributedata-testid
button.primary
→button
s with class containingprimary
.sidebar button
→ inside.sidebar
,button
sinput[type=text]
→input
s with attributetype
of valuetext
input[type=text]:first
→ above, but just firstinput[type=text]:eq(0)
→ same as aboveinput[required]
→input
s with attributerequired
(of any value)a[href^="https"]
→a
s with attributehref
starting withhttps
a[href*="axiory.com"]
→a
s with attributehref
containingaxiory.com
img[src$=".gif"]
→img
s with attributesrc
ending with.gif
input:not(.touched)
→input
s except those with class containingtouched
input:not([required])
→input
s except those with attributerequired
(of any value).class > a:nth-of-type(10)
-> Select the eleventha
element with the classclass
')
- Use Cypress testing library queries for accessibility testing
- Query priority: https://testing-library.com/docs/queries/about/
Testing Playground
Chrome extension: https://chrome.google.com/webstore/detail/testing-playground/hejbmebodbijjdhflfknehhcgaklhano- Example:
cy.findByRole('button', { name: /start trading/i })
-> Finds an element with a role/type button
and text start trading
.
cy.get('[data-testid=Button]')
-> Finds and element with a data-testid
Button.
Pros of using the library:
- a11y testing – semantics elements should be used
- translations testing
Cons of using the library:
- translations testing