A. The button with class 'btn' is clicked and then has class 'active'.
B. The button is clicked but should not have class 'active'.
C. The button is selected but not clicked.
D. The button is checked for visibility only.
Solution
Step 1: Analyze command chain
cy.get('.btn') selects the button, click() clicks it, and should('have.class', 'active') asserts it has the 'active' class.
Step 2: Understand test purpose
This checks that clicking the button changes its class to 'active', common in complex UIs.
Final Answer:
The button with class 'btn' is clicked and then has class 'active'. -> Option A
Quick Check:
Click then check class = correct test [OK]
Hint: Click then assert class change means success [OK]
Common Mistakes:
Ignoring the click() effect
Thinking should() checks absence of class
Confusing selection with clicking
4. Identify the error in this Cypress code snippet for a complex UI:
cy.get('#submit').click.should('be.visible')
medium
A. 'should' cannot be chained after 'click'.
B. Incorrect selector syntax for 'get'.
C. Missing parentheses after 'click' command.
D. 'be.visible' is not a valid assertion.
Solution
Step 1: Check command syntax
The click command requires parentheses: click().
Step 2: Verify chaining correctness
With click() fixed, chaining should('be.visible') is valid to assert visibility.
Final Answer:
Missing parentheses after 'click' command. -> Option C
Quick Check:
click() needs parentheses [OK]
Hint: Always add () after commands like click [OK]
Common Mistakes:
Omitting parentheses on commands
Thinking selector syntax is wrong
Believing should() can't follow click()
5. In a complex UI, a button initially has class 'disabled' and its class toggles between 'enabled' and 'disabled' after each click. Which Cypress code correctly tests this toggle behavior?
hard
A. cy.get('#toggleBtn').click().click().should('have.class', 'enabled')
B. cy.get('#toggleBtn').click().should('have.class', 'disabled').click().should('have.class', 'enabled')
C. cy.get('#toggleBtn').should('have.class', 'enabled').click().should('have.class', 'disabled')
D. cy.get('#toggleBtn').click().should('have.class', 'enabled').click().should('have.class', 'disabled')
Solution
Step 1: Understand toggle sequence
The button starts with 'disabled', clicking toggles to 'enabled', then clicking again toggles back to 'disabled'.