Huy Hang
Huy Hang

Reputation: 1

Hide browser when using FirefoxDriver

I use Selenium with FirefoxDriver, when instance it, FireFox browser auto open, how we can hide it?

WebDriver driver = new FirefoxDriver();

Thanks,

Upvotes: 0

Views: 3370

Answers (4)

Aleh Douhi
Aleh Douhi

Reputation: 1978

Not sure, what you try to achieve, but as far as I understood you want firefox windows not to interrupt your work while selenium tests are running. So you can run your tests in another desktop. Use for example this tool: Desktops. Easy and cheap solution.

Upvotes: 0

Depado
Depado

Reputation: 4929

Also, I would add that typically the automated testing would be on a dedicated machine with no users. In which case it shouldn't matter weather or not you can see the browser.

Starting a GUI is longer than starting a non-gui browser. It's really important when you have a huge project and don't want your test to take an eternity to finish.

Upvotes: 0

harish kumar
harish kumar

Reputation: 51

if you don't want to open the real browser like Firefox, then you should use the Html Unit Driver (Remote Web Driver). Firstly add the namespace and then write your code. Best of Luck.

using OpenQA.Selenium; using OpenQA.Selenium.Remote;

class Program
{
    static void Main(string[] args)
    {
        ICapabilities desiredCapabilities = DesiredCapabilities.HtmlUnit();
        IWebDriver driver = new RemoteWebDriver(desiredCapabilities);

        //your code begins here

     }
 }

Upvotes: 1

Brandon J. Boone
Brandon J. Boone

Reputation: 16472

You might be able to attach to the window handle using Win32 and hide it, but other than that I don't think it can be done.

The FirefoxDriver in Selenium is meant for automating the real firefox browser (not some representation of it) for UI testing. Because of this the real browser needs to be running for it to work.

If you want a non-viewable UI driver you'll need to use the HtmlUnit driver.

However as the site says:

None of the popular browsers uses the JavaScript engine used by HtmlUnit (Rhino). If you test JavaScript using HtmlUnit the results may differ significantly from those browsers.

So I would be careful trusting the HtmlUnit driver.

src: http://seleniumhq.org/docs/03_webdriver.html#webdriver-implementations

EDIT

Also, I would add that typically the automated testing would be on a dedicated machine with no users. In which case it shouldn't matter weather or not you can see the browser.

Upvotes: 1

Related Questions