Is there any way to ensure that the browser does not change from the initial window size. There are several things that are clicked during testing that are causing the window to maximize but i would like it to stay the same size throughout.
Asked
Active
Viewed 1.8k times
3 Answers
26
set it up once and for all in your env configuration (under test_settings
in the nightwatch config file):
"desiredCapabilities": {
"chromeOptions": {
"args": [
"window-size=1280,800"
]
}
}
note that this method will work because we're setting a chrome flag, so implementation may vary (e.g. safari does not have such flags).
for browsers that do not support these options, it's best to resize the window imperatively in the globals beforeEach
hook:
{
beforeEach: function (browser, done) {
browser.resizeWindow(1280, 800, done);
}
}
have a read on the nightwatch settings docs to see how globals are used.
using the above methods, you won't have to specify it in each test :)

Eliran Malka
- 15,821
- 6
- 77
- 100
-
1did you mean `browser.resizeWindow(1280, 800, done)`? you're right than, i updated the answer.. – Eliran Malka Jan 27 '17 at 14:47
-
1I did - whoops! Good of you to update it. Cheers. Deleted original comment so as not to confuse people with the wrong suggestion. See @Eliran Makla's comment – GrayedFox Jan 30 '17 at 19:03
-
link is broken. – Arst Mar 02 '22 at 03:30
13
You can fix the screen size before each test like that :
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();
}
}

Nicolas Pennec
- 7,533
- 29
- 43
0
here is the firefox fix they should approve the pr, and it will work, https://github.com/nightwatchjs/nightwatch/pull/2169

Ilan
- 197
- 1
- 5