Kode_12
Kode_12

Reputation: 4798

How can I set the browser size in a Protractor Test

I'm looking for the Protractor to run in the maximum browser size before the actual tests start running.

I think you have to use a beforeAll() function, but not sure how to set the size? Any ideas?

Upvotes: 0

Views: 2320

Answers (3)

martin770
martin770

Reputation: 1288

If you're running on a virtual machine, sometimes the maximize() command doesn't do what you expect.

in protractor.conf.js onPrepare

var getScreenSize = function() {
    return browser.driver.executeScript(function() {
        return {
            width: window.screen.availWidth,
            height: window.screen.availHeight
        };
    });
};

getScreenSize.then(function(screenSize) {
    browser.driver.manage().window().setSize(screenSize.width, screenSize.height);
});

Upvotes: 0

LazyDeveloper
LazyDeveloper

Reputation: 619

The below code

var width = 200;
var height = 300;
browser.driver.manage().window().setSize(width, height);

Upvotes: 2

Frederick Mfinanga
Frederick Mfinanga

Reputation: 1155

browser.driver.manage().window().maximize();

Upvotes: 1

Related Questions