0% found this document useful (0 votes)
424 views4 pages

Cypress Cheat Sheet

The document provides a cheat sheet of useful commands for the Cypress testing framework, including commands to get DOM elements (.get()), assert values (.should()), interact with elements (.click(), .clear()), make HTTP requests (.request()), and skip tests (.skip()). It lists examples of getting elements by ID, class, child/parent relationships and attributes, asserting element attributes and styles, selecting options, and checking HTTP response payloads.

Uploaded by

harshinihari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
424 views4 pages

Cypress Cheat Sheet

The document provides a cheat sheet of useful commands for the Cypress testing framework, including commands to get DOM elements (.get()), assert values (.should()), interact with elements (.click(), .clear()), make HTTP requests (.request()), and skip tests (.skip()). It lists examples of getting elements by ID, class, child/parent relationships and attributes, asserting element attributes and styles, selecting options, and checking HTTP response payloads.

Uploaded by

harshinihari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Cypress cheat sheet

Below you’ll find some commands and selectors we think would be valuable for you to use
while doing the exercises:

.get() – gets one or more DOM elements by selector or alias

• Getting an element using Id:

cy.get('#thisIsAnId')

• Getting an element using Class:

cy.get('.thisIsAClass')

• Selects all HTML child elements specified by “child” of elements specified by


“parent”. You can also use .children()

cy.get('parent > child')


//or
cy.get('parent').children()

• Getting the first HTML child from parent:

cy.get('ul > li').first()

• Getting HTML child on index X from parent using eq():

cy.get('ul > li').eq(X-1)

• Getting the element with a given data attribute:

cy.get('[attribute="value"]')
.contains() – gets the DOM element containing the text/integer

• Gets the element containing the text ‘Click me!’

cy.contains('Click me!')

.should() – creates an assertion, usually chained off .get() and .contains()

• ‘Getters’ don’t do anything, but they enable you to write clear English sentences

o to , be , been , is , that , which , and , has , have , with , at , of , same

Assertions include, but not limited to:

• visible / hidden

cy.get('#errorMessageBox').should('be.visible')

• enabled / disabled

cy.get('Button').should('be.enabled');

• attr(name, value)

cy.get('.LinkToGoogle').should('have.attr', 'href', 'https://www.google.com');

• css(name, value)

cy.get('#redContainer').should('have.css', 'font-size', '20px');

.click() – clicks on a DOM element, chained off a yielded element

cy.get('.radioButton1').click();
.dblclick() – double clicks on a DOM element

cy.get('Button').dblclick();

.rightClick() – right clicks on a DOM element

cy.contains('Input').rightclick();

.select() – selects an option in a <select> dropdown menu

cy.get('.dropDownFruitMenu').select('Bananas');

.clear() – clear the value of an input or text field

cy.get('#textBox').clear()

.request() – makes a http request

cy.request('https://www.uio.no/studier/emner/matnat/ifi/IN3240/v21/')
• The request method yields the response as an object literal that contains properties
such as:

o Status

o Body

o Headers

o Duration

• We can then assert the response payload against certain values:

cy.request('https://www.uio.no/studier/emner/matnat/ifi/IN3240/v21/').then((
response) => {
expect(response.body).to.include('<html lang=\"no\">');
})

To skip a specified suite or test, append .skip() to the function – all nested suites will also
be skipped:

it.skip('Visits the Kitchen Sink', () =>{


cy.visit('https://example.cypress.io');
})

You might also like