viewport.spec.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. context('Viewport', () => {
  2. beforeEach(() => {
  3. cy.visit('https://example.cypress.io/commands/viewport')
  4. })
  5. it('cy.viewport() - set the viewport size and dimension', () => {
  6. // https://on.cypress.io/viewport
  7. cy.get('#navbar').should('be.visible')
  8. cy.viewport(320, 480)
  9. // the navbar should have collapse since our screen is smaller
  10. cy.get('#navbar').should('not.be.visible')
  11. cy.get('.navbar-toggle').should('be.visible').click()
  12. cy.get('.nav').find('a').should('be.visible')
  13. // lets see what our app looks like on a super large screen
  14. cy.viewport(2999, 2999)
  15. // cy.viewport() accepts a set of preset sizes
  16. // to easily set the screen to a device's width and height
  17. // We added a cy.wait() between each viewport change so you can see
  18. // the change otherwise it is a little too fast to see :)
  19. /* eslint-disable cypress/no-unnecessary-waiting */
  20. cy.viewport('macbook-15')
  21. cy.wait(200)
  22. cy.viewport('macbook-13')
  23. cy.wait(200)
  24. cy.viewport('macbook-11')
  25. cy.wait(200)
  26. cy.viewport('ipad-2')
  27. cy.wait(200)
  28. cy.viewport('ipad-mini')
  29. cy.wait(200)
  30. cy.viewport('iphone-6+')
  31. cy.wait(200)
  32. cy.viewport('iphone-6')
  33. cy.wait(200)
  34. cy.viewport('iphone-5')
  35. cy.wait(200)
  36. cy.viewport('iphone-4')
  37. cy.wait(200)
  38. cy.viewport('iphone-3')
  39. cy.wait(200)
  40. // cy.viewport() accepts an orientation for all presets
  41. // the default orientation is 'portrait'
  42. cy.viewport('ipad-2', 'portrait')
  43. cy.wait(200)
  44. cy.viewport('iphone-4', 'landscape')
  45. cy.wait(200)
  46. /* eslint-enable cypress/no-unnecessary-waiting */
  47. // The viewport will be reset back to the default dimensions
  48. // in between tests (the default can be set in cypress.json)
  49. })
  50. })