I have not found any obvious way to do this and have trawled through the phantomjs docs, Ghost Driver issues etc. I know it can be done natively with phantomjs, but I don't know how to do it via Nightwatch.
Ideally we could do it via the desiredCapabilities settings for Phantom, as calling some sort of hacky phantomjs call before each test just to resize in case I'm testing with Phantom and not FF/Chrome is not great.
Open to suggestions :) if it can be done, I apologize for not finding it, a link here would be great. Keep up the good work!
Would this work as an alternative: http://nightwatchjs.org/api#windowSize
That works just wonderfully... and now I'm a bit embarrassed as to how I missed it.
Thank you. :blush:
No problem :)
@GrayedFox How did you managed to get this working? Could you please provide a simple snippet? Would be awesome, because I'm trying without any luck. Thanks!
client.maximizeWindow();
Should work? You might be using browser in place of client, in which case you would use:
browser.maximizeWindow();
Just place it as the first instruction at the beginning of each test. You could even go one step lazier and have it as part of your 'pre-test' script which is run before each individual test. Nightwatch has native support for this.
Vote to reopen this issue. I am stuck again now that we need to run tests on Phantom, and I simply cannot get Phantom to properly set its viewport and screensize. Any help would be much appreciated.
@GrayedFox it's working for me, although I find it super annoying to have to do this in every test that could be affected... any way to set in the config like
"mobile": {
"exclude": ["./pages", "./commands"],
"filter": "**/*.spec.js",
"launch_url" : "http://localhost",
"selenium_port" : 5555,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : true,
"path" : "tests/functional/screenshots"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"chromeOptions": {
"args": [
"--user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_2 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A4449d Safari/9537.53",
"--window-size=320,568"
]
}
}
}
FYI, http://nightwatchjs.org/api#resizeWindow did the trick for me.
@mmahalwy thanks
@mmahalwy any idea how to do that with phantom?
+1, I've tried using browser.maximizeWindow() and browser.resizeWindow(1280, 1024); to no avail 馃槩
EDIT: It works perfectly with the Chrome WebDriver, just not with PhantomJS
Most helpful comment
+1, I've tried using
browser.maximizeWindow()andbrowser.resizeWindow(1280, 1024);to no avail 馃槩EDIT: It works perfectly with the Chrome WebDriver, just not with PhantomJS