Make protractor test occupy the entire screen
Asked Answered
B

3

7

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?

Busby answered 25/8, 2014 at 20:28 Comment(0)
C
19

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'
        ]
    }
}
Coexist answered 24/4, 2015 at 20:37 Comment(0)
W
5

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 ..?

Weariless answered 26/8, 2014 at 14:40 Comment(4)
it does not. same issue. Expands to bottom of screen but doesnt maximize occupy the screen horizontallyBusby
That's strange. I would have answered the same way. @user3735746 Could you give us more info please? On which browser(s), OS...?Kiersten
I'm running on O, I have my Mac connected to Dell Screen though. Is it possible that that's causing the issue? Although the screen is wider and taller than the Mac screen, and it expands to the size of the Dell Screen's height so not sure why it doesnt do it for the width. Working with chrome.Busby
I think this is an issue with OSX maximize logic, see: apple.stackexchange.com/questions/54888/…Levitation
F
3

Inexplicably, on OSX only '--start-fullscreen' worked for me.

Firdausi answered 24/10, 2017 at 0:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.