4

When WebDriver initializes, there is a long waiting time when a browser window launches before the actual automated test begins. How can I speed this up? Is there a way to have a browser window running at all times, and just have WebDriver grab onto that window the next time it launches perhaps? If you have any clever ideas, please let me know.

Setup:

NUnit, Selenium C# client drivers, Mozilla Firefox driver, using Visual Studio 2010 to write tests (since I'm using the C#.NET client drivers)

2 Answers 2

3

Unfortunately the initialization of the firefox webdriver object takes that long and there is nothing you can do about it. You could set up your tests so that in the [TestFixtureSetUp] method you create the FirefoxDriver instance and then use that same FirefoxDriver instance for all of your tests.

The only potential problem there is that if the browser crashes or hangs (which could happen if you've got bad javascript on a page or for other reasons) then you wouldn't be able to recover, whereas if you start up a new window for each test you would be able to recover. You should be able to write some code that checks to make sure the browser is open and available before you start each test and if not, create a new instance of the FirefoxDriver.

1
  • I'll give you some points.. if you can help me answer some of my questions below, I'll add a few more to your comments. :-) Mar 14, 2012 at 23:00
2

You can switch to HTML Unit Driver if your project allows this (this might involve some tests update, since FireFox and HTMLUnit drivers have different js engines).
Otherwise, I agree with @SamWoods:

  • launch single browser (FireFox) instance before test suite run,
  • reuse it in all the tests, instead of launching another one.
  • don't forget to clean up the session data when needed.
  • don't forget to check if that browser window is still around and accessible.
3
  • Good point about cleaning the session data. I should have thought of that too :-)
    – Sam Woods
    Mar 14, 2012 at 21:29
  • does this require I use the Java client drivers? If that's the case, I'll continue using the C# drivers and just use the same browser window. Is there a way I can place the instance somewhere (on some other process) or serialize it and save the object to a file so I can easily grab it again? I'll have to research the cleaning up of session data--another thing I haven't done yet. Mar 14, 2012 at 22:57
  • You can still use the C# drivers and use HTML Unit Driver. The main downside to using this driver is that it has it's own javascript engine that is not the same as any real browser's javascript engine, so may behave differently than say IE or Firefox or Chrome. As far as placing the instance somewhere, I'm not sure what you mean... Are you executing nunit once for each test case? I was expecting that you execute nunit and it runs all of the tests in your dll. In that case, just make the Firefox Driver instance static and initialize it in the [TestFixtureSetUp] method.
    – Sam Woods
    Mar 14, 2012 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.