0
0
Cypresstesting~5 mins

cy.viewport() for screen sizes in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does cy.viewport() do in Cypress?

cy.viewport() sets the size of the browser window to simulate different screen sizes during tests.

Click to reveal answer
beginner
How do you set a viewport size to 1280 pixels wide and 720 pixels tall in Cypress?

Use cy.viewport(1280, 720) to set the browser window to 1280x720 pixels.

Click to reveal answer
intermediate
Name three preset device sizes you can use with cy.viewport().

Examples include 'iphone-6', 'ipad-2', and 'macbook-15'.

Click to reveal answer
beginner
Why is using cy.viewport() important in testing?

It helps test how a website looks and works on different screen sizes, like phones, tablets, and desktops.

Click to reveal answer
intermediate
What happens if you call cy.viewport() multiple times in a test?

The viewport size changes each time, allowing you to test responsiveness by simulating different screen sizes in one test.

Click to reveal answer
Which command sets the viewport to simulate an iPhone 6 screen?
Acy.viewport('iphone-6')
Bcy.viewport(375, 667)
Ccy.viewport('ipad-2')
Dcy.viewport('macbook-15')
What is the correct way to set a custom viewport size of 1024x768 pixels?
Acy.viewport(1024, 768)
Bcy.viewport('1024x768')
Ccy.viewport([1024, 768])
Dcy.viewport('custom', 1024, 768)
Why might you use cy.viewport() in your tests?
ATo speed up test execution
BTo test website behavior on different screen sizes
CTo change the URL of the page
DTo clear cookies
Which of these is NOT a valid preset device name for cy.viewport()?
A'iphone-x'
B'ipad-2'
C'android-10'
D'macbook-15'
If you want to test responsiveness by changing viewport sizes multiple times in one test, what should you do?
AUse <code>cy.reload()</code> instead
BOnly set viewport once at the start
CChange viewport in the browser manually
DCall <code>cy.viewport()</code> multiple times with different sizes
Explain how cy.viewport() helps in testing responsive web design.
Think about how websites look different on phones and computers.
You got /4 concepts.
    Describe how to use cy.viewport() to test a website on both a mobile phone and a desktop screen in one test.
    Remember you can change viewport size multiple times in a test.
    You got /4 concepts.