I use "cypress": "2.1.0"
for website functional test.
Also I have condition in tests:
if (WIDTH < 1025 && WIDTH > 480) {
it('Open search sidebar', function () {
cy.wait(500);
cy.get('.FilterStroke_resultsLabel_7gBlM').safeClick();
});
}
My question is how to get screen size (WIDTH, HEIGHT)
?
You can change the size of the viewport height and width for the remainder of the tests by setting the new values for viewportHeight or viewportWidth within Cypress. config().
To get the global window object, use the cy. window() command. You can use the yielded window object to call the methods on that window directly. For example, if the application code adds a method getAppName to the window object, you can execute the method from the spec.
In cypress, we can control the screen size/users' visible area on a web page. Cypress default viewport: Cypress sets the width to 1000px and the height to 660px by default. Overriding the default viewport: cy.viewport() command is used to override.
Use cy. visit() in a new test to navigate to the URL already opened in the new window, then fill in the fields and click the buttons as you would in a Cypress test.
It depends on how you are using viewPorts. If you are using cy.viewport(...) command, then you are easily able to store arguments to a variable.
However, I'm assuming, that you are trying to get width and height of the browser without explicitly setting viewport before the test. In this way, cypress takes the default windows width and height from the configuration.
You are able to access the configuration trough the global Cypress
variable, e.g.:
Cypress.config("viewportWidth") // => 800
OR
Cypress.config().viewportWidth // => 800
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With