Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Focus Protractor/Webdriver browser test window

I'm trying to focus Protractor/Webdriver browser test window when testing starts. By focus I mean that the test window should come on top of the other windows displayed on screen, right now it appears under the other windows.

Using Selenium chromedriver and starting Protractor from WebStorm.

I tried the following at the beginning of the scenario spec but it didn't have any effect:

browser.driver.switchTo().defaultContent();
browser.driver.switchTo().window(browser.driver.getWindowHandle());
browser.switchTo().window(browser.getWindowHandle());
browser.driver.executeScript('window.focus();')
like image 886
Răzvan Flavius Panda Avatar asked Nov 02 '22 10:11

Răzvan Flavius Panda


1 Answers

This isn't something Webdriver can do since it only controls your testing window, not your operating system's window manager. However, there is a Chrome flag that might do the trick:

capabilities: {
    'browserName': 'chrome',
    'chromeOptions': {
        'args': ['--start-maximized']
    }
}

This belongs in your protractor.conf.js file.

As soon as the Chrome window opens, it will maximize. On my system this puts it in front. Your mileage may vary.

like image 138
Isaac Lyman Avatar answered Nov 13 '22 21:11

Isaac Lyman