What will happen if the page has only 3 elements with class todo-item?
medium
A. The first assertion fails, stopping the test; second assertion is not run.
B. Both assertions pass because the second does not depend on length.
C. The test passes but logs a warning about length mismatch.
D. The second assertion fails but the first passes.
Solution
Step 1: Analyze first assertion
The first assertion expects 4 elements with class 'todo-item'. If only 3 exist, this assertion fails.
Step 2: Understand test flow on failure
When an assertion fails, Cypress stops the test immediately, so the second assertion is not executed.
Final Answer:
The first assertion fails, stopping the test; second assertion is not run. -> Option A
Quick Check:
Failed assertion stops test execution [OK]
Hint: Failed assertions stop test; later checks won't run [OK]
Common Mistakes:
Assuming all assertions run despite failure
Thinking warnings allow test to pass
Confusing element count with content check
4. You wrote this Cypress test:
cy.get('.card').should('have.length', 5)
But the test fails even though the page shows 5 cards. What is the most likely reason?
medium
A. The assertion syntax is wrong; should use 'have.lengthOf' instead.
B. The selector '.card' is incorrect or does not match all cards.
C. Cypress cannot count elements; it only checks visibility.
D. The page needs a manual refresh before running the test.
Solution
Step 1: Verify selector correctness
If the page visually shows 5 cards but the test fails, the selector '.card' might not match all card elements.
Step 2: Check assertion syntax and Cypress behavior
The syntax should('have.length', 5) is correct. Cypress counts elements matching the selector, so counting works. Manual refresh is not needed.
Final Answer:
The selector '.card' is incorrect or does not match all cards. -> Option B
Quick Check:
Selector must match all elements to count correctly [OK]
Hint: Check your selector matches all elements before asserting length [OK]
Common Mistakes:
Using wrong or incomplete selectors
Misunderstanding assertion syntax
Assuming Cypress needs page refresh
5. You want to test a dynamic list where items can be added or removed. Which Cypress code correctly asserts that the list has at least 2 items but no more than 5 items?
hard
A. cy.get('.list-item').should('have.length.gte', 2).and('have.length.lte', 5)
B. cy.get('.list-item').should('have.length', 2, 5)
C. cy.get('.list-item').should('have.length').within(2, 5)
D. cy.get('.list-item').should('have.lengthBetween', 2, 5)
Solution
Step 1: Understand Cypress length assertions
Cypress supports chaining assertions like should('have.length.gte', 2) for "greater than or equal" and should('have.length.lte', 5) for "less than or equal".
Step 2: Evaluate each option
cy.get('.list-item').should('have.length.gte', 2).and('have.length.lte', 5) correctly chains two assertions for minimum and maximum length. Options B, C, and D use invalid or non-existent syntax.
Final Answer:
cy.get('.list-item').should('have.length.gte', 2).and('have.length.lte', 5) -> Option A
Quick Check:
Use chained length.gte and length.lte for range checks [OK]
Hint: Chain should('have.length.gte') and should('have.length.lte') for ranges [OK]
Common Mistakes:
Using invalid assertion methods
Trying to pass multiple lengths in one assertion
Assuming 'lengthBetween' exists
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.