viewport.spec.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /// <reference types="cypress" />
  2. context('Viewport', () => {
  3. beforeEach(() => {
  4. cy.visit('https://example.cypress.io/commands/viewport')
  5. })
  6. it('cy.viewport() - set the viewport size and dimension', () => {
  7. // https://on.cypress.io/viewport
  8. cy.get('#navbar').should('be.visible')
  9. cy.viewport(320, 480)
  10. // the navbar should have collapse since our screen is smaller
  11. cy.get('#navbar').should('not.be.visible')
  12. cy.get('.navbar-toggle').should('be.visible').click()
  13. cy.get('.nav').find('a').should('be.visible')
  14. // lets see what our app looks like on a super large screen
  15. cy.viewport(2999, 2999)
  16. // cy.viewport() accepts a set of preset sizes
  17. // to easily set the screen to a device's width and height
  18. // We added a cy.wait() between each viewport change so you can see
  19. // the change otherwise it is a little too fast to see :)
  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. // The viewport will be reset back to the default dimensions
  47. // in between tests (the default can be set in cypress.json)
  48. })
  49. })