Testing Nightwatch: Set Browser Fixed Size

Is there a way to ensure that the browser does not change from the initial size of the window. During testing, there are several things that cause a window to grow larger, but I would like it to stay at the same level.

+7
selenium testing e2e-testing
source share
2 answers

configure it once and for all in the env configuration (under test_settings in the test_settings configuration file):

 "desiredCapabilities": { "chromeOptions": { "args": [ "window-size=1280,800" ] } } 

note that this method will work because we set the chrome flag, so the implementation may be different (for example, safari does not have such flags).

for browsers that do not support these options, it is best to resize in the globals beforeEach hook:

 { beforeEach: function (browser, done) { browser.resizeWindow(1280, 800, done); } } 

read in dows docs to find out how global characters are used.

using the above methods, you do not need to specify it in each test :)

+14
source share

You can correct the screen size before each test as follows:

 module.exports = { tags: ['myTest'], before : function (browser) { browser.resizeWindow(800, 600); }, 'Test #1' : function (browser) { return browser .url('http://localhost/test1') .waitForElementVisible('body', 2000); }, 'Test #2' : function (browser) { return browser .url('http://localhost/test2') .waitForElementVisible('body', 2000); }, after : function (browser) { browser.end(); } } 
+10
source share

All Articles