Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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)

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
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. :-) –  MacGyver Mar 14 '12 at 23:00
add comment

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.
share|improve this answer
    
Good point about cleaning the session data. I should have thought of that too :-) –  Sam Woods Mar 14 '12 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. –  MacGyver Mar 14 '12 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 '12 at 23:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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