Reputation: 11
I am using WebdriverIO for automation and am required to resize an open window to check the display of various UI elements compared to a maximized display.
I've tried each of the following separately with no success:
browser.setViewportSize({width:1200,height:662})
browser.windowHandleSize(1200, 662);
I also have checks to make sure the window has been properly resized:
expect(browser.getViewportSize('width')).to.be.lessThan(1300);
expect(browser.getViewportSize('width')).to.be.greaterThan(1000);
Unfortunately, nothing happens visually and the expects fail, as expected. I'm not sure if I'm not understanding how to use setViewportSize or windowHandleSize properly (maybe they're only intended to be used to resize new windows rather than existing ones?), or if this functionality exists in WebdriverIO at all.
Upvotes: 1
Views: 5912
Reputation: 1330
In case someone else comes here and is confused, the API call is setWindowSize, with the arguments (width, height)
:
browser.setWindowSize( 700, 500 );
See: https://webdriver.io/docs/api/browser/setWindowSize.html
Note that the above command resizes the window but not the content. The setWindowRect
command from the default WebDriver interface sets an absolute content size:
browser.setWindowRect( 0, 0, 700, 500 );
See: https://webdriver.io/docs/api/webdriver.html#setwindowrect
Upvotes: 1
Reputation: 316
I've used the following command in my WebdriverIO Config in setup hooks, but also just tested it in the middle of a test that's already running to both resize it smaller and then back to larger. Hope it helps!
browser.windowHandleSize({width:700, height:500});
browser.windowHandleSize({width:1280, height:870});
http://webdriver.io/api/protocol/windowHandleSize.html
Just to note as there have been several updates, please make sure your browser drivers, WebdriverIO, and Selenium Server are the latest versions!
Upvotes: 2