Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resize a WebDriverJS browser window?

I am using WebDriverJS, the JavaScript bindings for WebDriver, to do some simple frontend testing (driven by nodejs). However, I'm running into difficulties resizing the window, and the documentation is just a bit unclear to me.

var webdriver = require('selenium-wedriver');

driver = new webdriver.Builder()
           .withCapabilities(webdriver.Capabilities.chrome())
           .build();

driver.get("http://www.google.com")
.then(function() {
    driver.Window.setSize(400, 400);  // <-- should resize, does nothing
})
// more thenables...

Everything works normally and it gives no error, but the browser window does not resize. Am I referencing this setSize method incorrectly?

like image 401
mikeybaby173 Avatar asked Apr 22 '14 16:04

mikeybaby173


People also ask

How do I resize my browser tab?

- Use the default keyboard shortcut Ctrl+Shift+A (Command+Shift+A for Mac) to resize to the next window size in your list. Keep using the shortcut to rotate window sizes.

What method is used to resize a browser window?

The resizeTo() method is used to resizes a window to the specified width and height.

How do I change the resolution on my protractor browser?

Protractor allows setting the custom browser window size. Custom width and height can be mentioned in the Set Size function, the browser window will be resized to the mentioned width and height. Purpose: The function setSize() in the Window class is used to resize the browser window.


2 Answers

After more than a week of confused searching through the api docs and google, the answer was actually lying inside of the tests folder of the selenium-webdriver tests node module!!

driver.manage().window().setSize(x, y);
like image 104
mikeybaby173 Avatar answered Sep 19 '22 08:09

mikeybaby173


I don't know how selenium-webdriver works so I can't help you there but just in case you are interested, here is how it works with WebdriverJS:

var webdriverjs = require('webdriverjs');
var options = {
    desiredCapabilities: {
        browserName: 'chrome'
    }
};

webdriverjs
    .remote(options)
    .init()
    .windowHandleSize({width:1024,height:768})
    .url('http://www.google.com')
    .title(function(err, res) {
        console.log('Title was: ' + res.value);
    })
    .end();
like image 36
ChristianB Avatar answered Sep 19 '22 08:09

ChristianB