0
0
Cypresstesting~20 mins

First Cypress test - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cypress Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the test result of this Cypress code?

Consider this Cypress test code. What will be the test execution result?

Cypress
describe('My First Test', () => {
  it('Visits the Kitchen Sink', () => {
    cy.visit('https://example.cypress.io')
    cy.contains('type').click()
    cy.url().should('include', '/commands/actions')
  })
})
ATest fails because cy.visit URL is incorrect
BTest passes because the page contains 'type' and URL changes correctly
CTest fails due to syntax error in cy.contains line
DTest fails because cy.url assertion is wrong
Attempts:
2 left
💡 Hint

Check if the URL visited is valid and if the element with text 'type' exists on the page.

assertion
intermediate
1:30remaining
Which assertion correctly verifies the page title in Cypress?

You want to check that the page title is exactly 'Cypress.io: Kitchen Sink'. Which assertion is correct?

Acy.title().should('eq', 'Cypress.io: Kitchen Sink')
Bcy.title().should('equal', 'Cypress.io: Kitchen Sink')
Ccy.title().should('contain', 'cypress.io')
Dcy.title().should('include', 'Kitchen Sink')
Attempts:
2 left
💡 Hint

Check the exact match assertion syntax in Cypress.

locator
advanced
2:00remaining
Which locator is best practice to select a button with text 'Submit' in Cypress?

Choose the best locator to select a button with visible text 'Submit' for a Cypress test.

Acy.contains('button', 'Submit')
Bcy.get('button').contains('Submit')
Ccy.get('button:contains("Submit")')
Dcy.get('button').filter(':text("Submit")')
Attempts:
2 left
💡 Hint

Consider the Cypress recommended way to find elements by text and tag.

🔧 Debug
advanced
2:00remaining
Why does this Cypress test fail with 'Timed out retrying' error?

Given this test code, why does it fail with a timeout error?

Cypress
describe('Timeout Test', () => {
  it('Waits for element', () => {
    cy.visit('https://example.cypress.io')
    cy.get('#nonexistent-element').should('be.visible')
  })
})
AThe assertion 'should be visible' is invalid syntax
Bcy.get selector syntax is incorrect causing failure
Ccy.visit URL is unreachable causing timeout
DThe element with id 'nonexistent-element' does not exist on the page, causing timeout
Attempts:
2 left
💡 Hint

Check if the element selector matches any element on the page.

framework
expert
1:30remaining
What is the correct way to run setup code before all tests in a Cypress test suite?

You want to run some code once before all tests in a describe block. Which is the correct Cypress hook to use?

AbeforeEach(() => { /* setup code */ })
Binit(() => { /* setup code */ })
Cbefore(() => { /* setup code */ })
Dsetup(() => { /* setup code */ })
Attempts:
2 left
💡 Hint

Recall the difference between hooks that run once and those that run before each test.