Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make protractor test occupy the entire screen

I have seen a couple questions online related to this issue (How to set default browser window size in Protractor/WebdriverJS) but they don't address my issue.

I have the tests that I want to be able to run successfully on a laptop screen or desktop screen of ant size. I had tried all of these methods below but unsuccesfully.

The issue with this one is that I have to hardcode a width and height. I want to detect the screen size automatically

browser.driver.manage().window().setSize(width, height);

The issue with this one is that it only seems to maximize the height and not the width.

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

I want to be able to get the screen's height and width and plug those in for the .setSize() function. But when I try this

browser.driver.manage().window().setSize(screen.width, screen.height);

I get ReferenceError: screen is not defined

If I try console.log($(window)); then window is not defined either

So what the best way to do this?

like image 897
es3735746 Avatar asked Aug 25 '14 20:08

es3735746


People also ask

How do you maximize a window with a protractor?

Protractor Browser Window Commands - Maximize Browser Window The browser window can be maximized using the Maximize command. Purpose: The function maximize() in the Window class is used to maximize the browser window.

How do you speed up a protractor test?

To do this is quite simple in protractor. Adding the shardTestFiles and maxInstences to your capabilities config should allow you to (in this case) run at most two test in parrallel. Increase the maxInstences to increase the number of tests run. Note : be careful not to set the number too high.

How do you run a protractor test in multiple browsers?

Testing Against Multiple Browsers If you would like to test against multiple browsers, use the multiCapabilities configuration option. Protractor will run tests in parallel against each set of capabilities. Please note that if multiCapabilities is defined, the runner will ignore the capabilities configuration.


2 Answers

In case of Chrome on Mac OS X, the following didn't make the browser maximized for me:

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

In this case, you need to either switch to Firefox, or start Chrome with --start-maximized:

capabilities: {
    browserName: 'chrome',
    chromeOptions: {
        args: [
            '--start-maximized'
        ]
    }
}
like image 148
alecxe Avatar answered Sep 26 '22 01:09

alecxe


We set browser size in onPrepare block in protractor.conf.js:

onPrepare: function() {
    browser.driver.manage().window().maximize();
},

not sure if this helps you with your second issue ..?

like image 21
nilsK Avatar answered Sep 24 '22 01:09

nilsK