Test Overview
This test sets the browser viewport to a specific screen size and verifies that a responsive element is visible and correctly displayed at that size.
This test sets the browser viewport to a specific screen size and verifies that a responsive element is visible and correctly displayed at that size.
describe('Viewport size test', () => { it('sets viewport to 375x667 and checks mobile menu visibility', () => { cy.viewport(375, 667); cy.visit('https://example.cypress.io'); cy.get('.mobile-menu').should('be.visible'); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Set viewport size to 375x667 | Browser window resized to width 375px and height 667px | — | PASS |
| 2 | Visit the URL https://example.cypress.io | Page loads with mobile layout due to small viewport | — | PASS |
| 3 | Find element with class '.mobile-menu' | Mobile menu element is present in DOM | Check if '.mobile-menu' is visible on screen | PASS |
cy.viewport() in Cypress tests?cy.viewport()cy.viewport() syntaxcy.viewport(width, height).cy.viewport('iphone-6');
cy.viewport(800, 600);cy.viewport() call sets the final size.cy.viewport(1024);
cy.viewport(1024, 768).cy.viewport() multiple times to change screen size during a test.Pass the test and this pattern moves unknown