Nightwatch testing: Set browser to fixed size

compsci45000 picture compsci45000 · Jun 6, 2015 · Viewed 15.6k times · Source

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.

Answer

Eliran Malka picture Eliran Malka · Jan 2, 2017

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 :)