Challenge - 5 Problems
Viewport Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the viewport size after this Cypress command?
Consider the following Cypress test code snippet:
What will be the viewport width and height set by this command?
cy.viewport(1024, 768);
What will be the viewport width and height set by this command?
Cypress
cy.viewport(1024, 768);
Attempts:
2 left
💡 Hint
The first argument is width, the second is height.
✗ Incorrect
The cy.viewport() command sets the browser's viewport size. The first parameter is width, the second is height, so cy.viewport(1024, 768) sets width to 1024 pixels and height to 768 pixels.
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies the viewport size?
You want to check if the viewport width is 375 pixels after setting it with cy.viewport(375, 667). Which assertion is correct?
Cypress
cy.viewport(375, 667); // Which assertion below correctly checks the width?
Attempts:
2 left
💡 Hint
The window object holds the viewport size properties.
✗ Incorrect
The window object's innerWidth property reflects the viewport width. Using cy.window().its('innerWidth') accesses this value for assertion. Other options either check wrong properties or use invalid commands.
🧠 Conceptual
advanced1:30remaining
What happens if you use cy.viewport() with a preset device name?
In Cypress, what does this command do?
Choose the correct explanation.
cy.viewport('iphone-6');Choose the correct explanation.
Attempts:
2 left
💡 Hint
Device presets set viewport size but do not emulate device pixel ratio or user agent.
✗ Incorrect
Using cy.viewport('iphone-6') sets the viewport size to iPhone 6 dimensions (375x667) but does not emulate device pixel ratio or user agent string. It only changes viewport size.
🔧 Debug
advanced2:00remaining
Why does this viewport test fail?
Given this test:
Why does the assertion fail?
cy.viewport(800, 600);
cy.window().its('innerWidth').should('equal', 600);Why does the assertion fail?
Attempts:
2 left
💡 Hint
Remember which value is width and which is height in cy.viewport().
✗ Incorrect
cy.viewport(800, 600) sets width to 800 and height to 600. innerWidth reflects the width, so expecting 600 causes the test to fail.
❓ framework
expert3:00remaining
How to test responsive design for multiple screen sizes efficiently in Cypress?
You want to run the same test on multiple screen sizes: 320x480, 768x1024, and 1280x720. Which approach is best to write this in Cypress?
Attempts:
2 left
💡 Hint
Think about reusability and clean test code.
✗ Incorrect
Using custom commands and data-driven tests allows running the same test logic for multiple viewport sizes cleanly and efficiently. Loops inside tests can cause flaky behavior, and separate tests cause duplication.