Bird
Raised Fist0
Cypresstesting~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of using cy.wait() in Cypress tests?
easy
A. To pause the test for a specific time or until a request finishes
B. To skip a test step temporarily
C. To restart the test from the beginning
D. To automatically retry failed assertions

Solution

  1. Step 1: Understand the function of cy.wait()

    cy.wait() is used to pause the test execution either for a fixed time or until a network request completes.
  2. Step 2: Compare with other options

    Skipping steps, restarting tests, or retrying assertions are not functions of cy.wait().
  3. Final Answer:

    To pause the test for a specific time or until a request finishes -> Option A
  4. Quick Check:

    Pause test = cy.wait() [OK]
Hint: Remember: cy.wait() pauses test execution explicitly [OK]
Common Mistakes:
  • Thinking cy.wait() skips test steps
  • Confusing cy.wait() with test retries
  • Assuming cy.wait() restarts tests
2. Which of the following is the correct syntax to wait explicitly for 3 seconds in Cypress?
easy
A. cy.wait(3s)
B. cy.wait('3000')
C. cy.wait(3)
D. cy.wait(3000)

Solution

  1. Step 1: Check the correct argument type for cy.wait()

    The argument must be a number representing milliseconds, so 3000 means 3 seconds.
  2. Step 2: Validate each option

    cy.wait(3000) uses a number 3000 correctly. cy.wait('3000') uses a string which is invalid. cy.wait(3) uses 3 which means 3 milliseconds, not 3 seconds. cy.wait(3s) uses an invalid unit '3s'.
  3. Final Answer:

    cy.wait(3000) -> Option D
  4. Quick Check:

    Milliseconds number = cy.wait(3000) [OK]
Hint: Use milliseconds as number, no quotes or units [OK]
Common Mistakes:
  • Passing time as string instead of number
  • Using seconds instead of milliseconds
  • Adding units like 's' inside wait argument
3. Consider this Cypress code snippet:
cy.intercept('GET', '/api/data').as('getData')
cy.visit('/dashboard')
cy.wait('@getData')
cy.get('#result').should('be.visible')

What will cy.wait('@getData') do here?
medium
A. Pause test until the GET request to '/api/data' finishes
B. Pause test for 1 second regardless of request
C. Immediately continue without waiting
D. Cause a syntax error because of wrong alias

Solution

  1. Step 1: Understand alias usage with cy.wait()

    The alias '@getData' refers to the intercepted GET request to '/api/data'. Using cy.wait('@getData') waits for that request to complete.
  2. Step 2: Check other options

    It does not wait a fixed time (not 1 second), nor does it continue immediately. The alias is correctly defined, so no syntax error.
  3. Final Answer:

    Pause test until the GET request to '/api/data' finishes -> Option A
  4. Quick Check:

    Wait for request alias = cy.wait('@getData') [OK]
Hint: Wait for alias pauses until that request finishes [OK]
Common Mistakes:
  • Confusing alias wait with fixed time wait
  • Assuming immediate continuation
  • Mistaking alias syntax causing errors
4. You wrote this Cypress code:
cy.wait(5000)
cy.get('.submit-btn').click()

But the test fails because the button is not clickable after 5 seconds. What is the likely problem?
medium
A. The selector '.submit-btn' is invalid syntax
B. The wait time 5000 is too long and causes timeout
C. Using fixed wait instead of waiting for the button to be ready
D. cy.wait() cannot be used before cy.get()

Solution

  1. Step 1: Analyze the use of fixed wait

    Waiting a fixed 5 seconds does not guarantee the button is ready or clickable. The button might appear later or be disabled.
  2. Step 2: Consider better waiting strategy

    Better to wait for the button to exist or be enabled using assertions or wait for network requests instead of fixed time.
  3. Final Answer:

    Using fixed wait instead of waiting for the button to be ready -> Option C
  4. Quick Check:

    Fixed wait ≠ reliable readiness [OK]
Hint: Wait for element readiness, not fixed time [OK]
Common Mistakes:
  • Assuming fixed wait always works
  • Blaming selector syntax without checking
  • Thinking cy.wait() must come after cy.get()
5. You want to wait for two different API calls to finish before checking the page content. Which code correctly waits for both requests using cy.wait()?
hard
A. cy.wait('@apiCall1', '@apiCall2')
B. cy.wait('@apiCall1'); cy.wait('@apiCall2')
C. cy.wait(['@apiCall1', '@apiCall2'])
D. cy.wait('@apiCall1') && cy.wait('@apiCall2')

Solution

  1. Step 1: Understand how to wait for multiple aliases

    Cypress requires chaining cy.wait() calls sequentially for different aliases to ensure both requests complete.
  2. Step 2: Evaluate each option

    cy.wait('@apiCall1'); cy.wait('@apiCall2') correctly chains the waits using semicolon separation, which queues them in Cypress. cy.wait('@apiCall1', '@apiCall2') passes multiple arguments incorrectly. cy.wait('@apiCall1') && cy.wait('@apiCall2') uses logical AND which does not chain Cypress commands properly. cy.wait(['@apiCall1', '@apiCall2']) uses an unsupported array argument.
  3. Final Answer:

    cy.wait('@apiCall1'); cy.wait('@apiCall2') -> Option B
  4. Quick Check:

    Chained waits = cy.wait('@apiCall1'); cy.wait('@apiCall2') [OK]
Hint: Chain cy.wait() calls for multiple aliases [OK]
Common Mistakes:
  • Passing multiple aliases as separate arguments
  • Using && instead of proper chaining
  • Using unsupported array of aliases
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard