question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support ability to set viewport in `before` or `Cypress.config` to persist new viewport across several tests (not reset to default viewport size in between each test)

See original GitHub issue

This looks like a bug but I may be misunderstanding the documentation, under Config -> Name And Value it states:

Any value you change will be permanently changed for the remainder of your tests.

I interpreted this as when I set cypress like so:

Cypress.config({
  viewportWidth: 375,
  viewportHeight: 812,
})

cy.viewport(375, 812)

Any further (non chained) tests should run in 375, 812 viewpoint but it seems to default back to the original cypress.json config.

Interestingly when I console log

const { viewportWidth, viewportHeight } = Cypress.config()
console.log('Actual', viewportWidth, viewportHeight)

It will give me the correct Actual, 375, 812 values

The reason I’m doing it this way is I am using the cypress-cucumber-preprocessor plugin which treats each cypress definition as a different “step” and doesn’t seem to persist cy.viewport() between them.

This is a little complicated to explain, let me know if I need more info etc.

Cheers

  • Operating System: MacOS 10.13.3
  • Cypress Version: 2.1.0
  • Browser Version: Chrome

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:17
  • Comments:28 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
jennifer-shehanecommented, Apr 22, 2020

Some of the work in #5346 should make it possible to persist a viewport size across a series of tests.

To be released

describe('page display on medium size screen', {
  viewportHeight: 1000,
  viewportWidth: 400
}, () => {
  it('does not display sidebar', () => {
    cy.get('#sidebar').should('not.be.visible')
  })
  it('shows hamburger menu', () => {
    cy.get('#header').find('i.menu').should('be.visible)
  })
})

So, keep track of that PR to see when it is merged and released within our product.

8reactions
vedmantcommented, Feb 7, 2019

Could it keep last set viewport and not reset each time to default while it’s within one describe section? Jumping between viewports visual experience is really unpleasant for eyes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

viewport | Cypress Documentation
Reset viewport via Cypress.config(). You can change the size of the viewport height and width for the remainder of the tests by setting...
Read more >
Cypress Viewport - YouTube
Cypress Viewport command controls the orientation and size of the screen of your application. Using this command, you can set the size of ......
Read more >
Cypress Viewport and Browser Configurations you Must Know.
Udemy Enrollment Form https://forms.gle/4dndSRQtntfo8puaA More information: https://docs. cypress.io/api/commands/ viewport Check my ...
Read more >
How Do I Use Mobile Viewports for Responsive Experiences?
Mobile viewports help you see how your Adobe Target activities look on Screens of various sizes. Find a list of popular device viewport...
Read more >
What's new? - Applitools
What's new with our automated visual testing software? Get the latest updates on product releases and integrations as well as Applitools Eyes and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found