Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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'
        ]
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.7k users

...