A. cy.viewport must be called before assertions to set size correctly
B. cy.get selector #nav is invalid syntax
C. cy.viewport cannot accept numeric width and height
D. cy.viewport('iphone-x') is not a valid device name
Solution
Step 1: Check viewport usage order
The first cy.viewport(1024, 768) sets screen size, then assertion runs. But the second cy.viewport('iphone-x') is called after assertion, which won't affect that assertion.
Step 2: Understand test flow
Viewport must be set before assertions to test elements at that size. Changing viewport after assertion has no effect on that test step.
Final Answer:
cy.viewport must be called before assertions to set size correctly -> Option A
Quick Check:
Set viewport before assertions [OK]
Hint: Always set viewport before assertions [OK]
Common Mistakes:
Thinking viewport accepts only device names
Believing selector #nav is invalid
Assuming viewport after assertion affects previous checks
5. You want to ensure your website's navigation menu works on desktop, tablet, and mobile. Which Cypress test approach best ensures cross-device quality?
hard
A. Run tests only on desktop viewport since mobile users are few.
B. Run tests with cy.viewport('macbook-15'), then cy.viewport('ipad-2'), then cy.viewport('iphone-6'), checking menu visibility each time.
C. Run tests with cy.viewport('iphone-6') only, assuming it covers all smaller devices.
D. Run tests without setting viewport, relying on default browser size.
Solution
Step 1: Understand cross-device testing need
Testing on multiple device sizes ensures the menu works well on desktop, tablet, and mobile screens.
Step 2: Evaluate test approaches
Run tests with cy.viewport('macbook-15'), then cy.viewport('ipad-2'), then cy.viewport('iphone-6'), checking menu visibility each time. tests all relevant screen sizes explicitly. Other options test only one size or none, risking missed bugs on other devices.
Final Answer:
Run tests with cy.viewport('macbook-15'), then cy.viewport('ipad-2'), then cy.viewport('iphone-6'), checking menu visibility each time. -> Option B
Quick Check:
Test multiple viewports for cross-device quality [OK]
Hint: Test all device sizes for full coverage [OK]
Common Mistakes:
Testing only desktop or only mobile
Skipping viewport setting
Assuming one mobile size covers all devices
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.