简体   繁体   中英

Selenium Web Driver - How to run Firefox in the Background

Every time I run my tests on Firefox browser the browser takes active control and kind of disturbs/interrupts my work. Is there way/command to make it run on the background.

You can set position of the browser outside of your screen:

FirefoxDriver firefoxDriver = new FirefoxDriver();
firefoxDriver.manage().window().setPosition(new Point(-x, -y));

See Also:

As there isn't any accepted answer - you can download firefox addon and install it with your instance of firefox. Addon is named FireTray it can launch firefox minimized in tray so there won't be any poping up windows etc. It can hide 1 window but with litle tinkering with addon you can change that value to anything. Here is some code to help you understand what I'm talkim about :)

FirefoxProfile prof = new FirefoxProfile(new File(FIRE_TRAY_PATH));
WebDriver driver = new FirefoxDriver(prof);

Now you have pseudo-background firefox browser :)

You could try using an HtmlUnitDriver with Firefox capabilities for a 'headless' effect.

new HtmlUnitDriver(DesiredCapabilities.firefox())

HtmlUnitDriver doesn't play nice with javascript interactions all the time



Alternatively, add a resize to your existing driver on startup to hide the window.

driver.manage().window().setSize(new Dimension(0, 0));

This might have an impact on the driver's ability to resolve WebElements that are not on the page and change your behavior. I'm not sure

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM