0
0
Cypresstesting~20 mins

cy.wait() for explicit waiting in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Explicit Wait Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Cypress test snippet?
Consider the following Cypress test code. What will be the value of counter after the test runs?
Cypress
let counter = 0;

cy.wait(1000).then(() => {
  counter += 1;
});

cy.wait(500).then(() => {
  counter += 2;
});
Acounter will be 2
Bcounter will be 1
Ccounter will be 3
Dcounter will be 0
Attempts:
2 left
💡 Hint
Remember that Cypress commands are queued and run in order.
assertion
intermediate
2:00remaining
Which assertion correctly waits for 2 seconds before checking the element?
You want to wait explicitly for 2 seconds before asserting that a button with id #submit is visible. Which option correctly does this in Cypress?
Acy.wait(2000); cy.get('#submit').should('be.visible');
Bcy.wait('#submit', 2000).should('be.visible');
Ccy.get('#submit').wait(2000).should('be.visible');
Dcy.get('#submit').should('be.visible').wait(2000);
Attempts:
2 left
💡 Hint
Think about the order of commands and what cy.wait() accepts as arguments.
🔧 Debug
advanced
2:00remaining
Why does this Cypress test fail intermittently?
This test sometimes fails because the element is not found. What is the likely cause?
Cypress
cy.get('#loadButton').click();
cy.get('#result').should('contain', 'Success');
AThe selector '#result' is incorrect and does not exist in the DOM.
BThe test does not wait for the result to appear after clicking the button.
CThe click command is not chained properly causing a syntax error.
DCypress does not support assertions on text content.
Attempts:
2 left
💡 Hint
Think about asynchronous behavior after clicking a button.
🧠 Conceptual
advanced
2:00remaining
What is the main difference between cy.wait() with a number and cy.wait() with an alias?
Choose the correct explanation of how cy.wait() behaves differently when passed a number versus an alias.
A<code>cy.wait(1000)</code> waits for an element; <code>cy.wait('@alias')</code> waits for a timer.
B<code>cy.wait(1000)</code> waits for a network request; <code>cy.wait('@alias')</code> pauses for 1 second.
C<code>cy.wait(1000)</code> retries the command until success; <code>cy.wait('@alias')</code> fails immediately if request not found.
D<code>cy.wait(1000)</code> pauses for 1 second; <code>cy.wait('@alias')</code> waits for a network request to complete.
Attempts:
2 left
💡 Hint
Think about what cy.wait() does with numbers and with network aliases.
framework
expert
2:00remaining
How to avoid flaky tests caused by cy.wait() in Cypress?
Which practice helps reduce flaky tests related to using cy.wait() for explicit waiting?
AReplace fixed <code>cy.wait()</code> times with waiting for specific elements or network calls.
BIncrease all <code>cy.wait()</code> times to very high values to ensure stability.
CRemove all <code>cy.wait()</code> commands and rely only on <code>cy.get()</code>.
DUse <code>cy.wait()</code> only inside <code>beforeEach()</code> hooks.
Attempts:
2 left
💡 Hint
Think about what causes flakiness and how Cypress commands can wait smartly.