What is the purpose of timeout configuration in Cypress tests?
Timeout configuration controls how long Cypress waits for an action or assertion before it fails the test. It helps handle delays in loading or responses.
Click to reveal answer
beginner
How do you set a custom timeout for a single command in Cypress?
You add the { timeout: milliseconds } option to the command, for example: cy.get('.btn', { timeout: 10000 }) waits up to 10 seconds.
Click to reveal answer
beginner
What is the default timeout for most Cypress commands?
The default timeout is 4,000 milliseconds (4 seconds) for most commands like cy.get().
Click to reveal answer
intermediate
How can you globally change the default timeout for all commands in Cypress?
You can set defaultCommandTimeout in the cypress.config.js file, for example: defaultCommandTimeout: 10000 sets 10 seconds globally.
Click to reveal answer
intermediate
Why is it better to avoid very long timeouts in tests?
Long timeouts can make tests slow and hide real problems. It's better to use reasonable timeouts and fix slow app parts.
Click to reveal answer
What does the timeout option in cy.get() do?
AControls how long Cypress waits after the test ends
BChanges the speed of typing in input fields
CSets the delay between test retries
DSets how long Cypress waits for the element before failing
✗ Incorrect
The timeout option tells Cypress how long to wait for the element to appear before it stops and fails the test.
Where do you set the global default timeout for all Cypress commands?
AIn the <code>cypress.config.js</code> file
BInside each test file
CIn the browser settings
DIn the package.json file
✗ Incorrect
The global timeout is set in the cypress.config.js file using defaultCommandTimeout.
What is the default timeout for most Cypress commands?
A4000 ms
B30000 ms
C10000 ms
D1000 ms
✗ Incorrect
Most Cypress commands have a default timeout of 4000 milliseconds (4 seconds).
Why should you avoid setting very long timeouts in tests?
ABecause Cypress does not support long timeouts
BBecause it makes tests run faster
CBecause it hides real problems and slows tests
DBecause it causes syntax errors
✗ Incorrect
Long timeouts slow down tests and can hide real issues that should be fixed.
How do you set a 10-second timeout for a single cy.get() command?
Acy.get('.btn').timeout(10)
Bcy.get('.btn', { timeout: 10000 })
Ccy.get('.btn').wait(10000)
Dcy.get('.btn').setTimeout(10)
✗ Incorrect
You pass the timeout option as an object: { timeout: 10000 } means 10,000 milliseconds or 10 seconds.
Explain how timeout configuration works in Cypress and why it is important.
Think about waiting for things to appear on a webpage during tests.
You got /5 concepts.
Describe how to change the default timeout globally and for a single command in Cypress.
One is in config file, one is in the command itself.
You got /4 concepts.
Practice
(1/5)
1. What does the { timeout: 10000 } option do in a Cypress command?
easy
A. It disables the timeout for that command.
B. It makes Cypress skip the command after 10 seconds.
C. It repeats the command every 10 seconds.
D. It sets Cypress to wait up to 10 seconds before failing the command.
Solution
Step 1: Understand the timeout option in Cypress
The { timeout: ms } option tells Cypress how long to wait for a command to succeed before failing.
Step 2: Interpret the value 10000
10000 milliseconds equals 10 seconds, so Cypress waits up to 10 seconds.
Final Answer:
It sets Cypress to wait up to 10 seconds before failing the command. -> Option D
Quick Check:
Timeout option = wait time before failure [OK]
Hint: Timeout sets max wait time before failure [OK]
Common Mistakes:
Thinking timeout disables the command
Assuming timeout repeats the command
Confusing timeout with delay or skip
2. Which of the following is the correct syntax to set a 5-second timeout for a cy.get() command?
easy
A. cy.get('.btn', { timeout: 5000 })
B. cy.get('.btn').timeout(5000)
C. cy.get('.btn', timeout=5000)
D. cy.get('.btn').setTimeout(5000)
Solution
Step 1: Recall Cypress command options syntax
Cypress commands accept options as an object inside curly braces after the selector.
Step 2: Identify correct object syntax
The correct syntax uses { timeout: 5000 } as the second argument to cy.get().
Final Answer:
cy.get('.btn', { timeout: 5000 }) -> Option A
Quick Check:
Options object uses curly braces and key-value pairs [OK]
Hint: Use curly braces for options object in commands [OK]
Common Mistakes:
Using equals sign instead of colon in options
Calling timeout as a method on command
Passing timeout outside options object
3. What will happen if the following Cypress code runs and the element .submit-btn appears after 7 seconds?
cy.get('.submit-btn', { timeout: 5000 }).click()
medium
A. The test will pass because the element appears eventually.
B. The test will fail because the timeout is shorter than the wait time.
C. The test will wait indefinitely for the element.
D. The test will skip the click and continue.
Solution
Step 1: Analyze the timeout value
The timeout is set to 5000 milliseconds (5 seconds), so Cypress waits up to 5 seconds for the element.
Step 2: Compare element appearance time
The element appears after 7 seconds, which is longer than the 5-second timeout.
Final Answer:
The test will fail because the timeout is shorter than the wait time. -> Option B
Quick Check:
Timeout less than wait time causes failure [OK]
Hint: Timeout must be >= element load time to pass [OK]
Common Mistakes:
Assuming test waits longer than timeout
Thinking test passes if element appears later
Believing timeout disables failure
4. Identify the error in this Cypress code snippet:
cy.get('.nav-link', { timeout: '3000' }).click()
medium
A. Timeout value should be a number, not a string.
B. The selector '.nav-link' is invalid.
C. The click() command cannot follow get().
D. Timeout option is not supported in cy.get().
Solution
Step 1: Check the timeout option type
The timeout value must be a number representing milliseconds, not a string.
Step 2: Validate other parts
The selector is valid, click() can follow get(), and timeout is supported in cy.get().
Final Answer:
Timeout value should be a number, not a string. -> Option A
Quick Check:
Timeout must be numeric type [OK]
Hint: Timeout must be a number, not quoted string [OK]
Common Mistakes:
Passing timeout as a string
Misunderstanding selector validity
Thinking click() is invalid after get()
5. You want to wait up to 8 seconds for a button with class .save-btn to appear, but only 3 seconds for a loading spinner .spinner to disappear. Which code correctly sets these timeouts in Cypress?
hard
A. cy.get('.save-btn').click({ timeout: 8000 }); cy.get('.spinner').should('not.exist', { timeout: 3000 });