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.

I've heard rumors that Selenium WebDriver can run without opening a real browser window, meaning it runs in the background. I am using the C# Client Drivers, FirefoxDriver within the automated tests, and launching a class library project (containing my code) using NUnit.

  • If so, how can this be done?
  • Also, what is the benefit to doing it this way?
  • Do you still have to keep the waits (thread.sleep and implicit waits) in the code since the browser isn't open?
share|improve this question
1  
Related: sqa.stackexchange.com/questions/2538/… –  user246 Feb 8 '12 at 16:12
add comment

4 Answers 4

up vote 5 down vote accepted

One option is HTMLUnit which is headless but has its own proprietry JavaScript rendering engine so it is possible that it will behave differently to existing browsers (If you do use HTMLUnit don't forget to enable JavaScript when you instantiate it).

The second option is to use XVFB, this will run the tests in a virtual frame buffer environemt. This has been reported quite a few times on the Selenium users mailing list as well as the Selenium blog, see this post for some XVFB implementations:

http://seleniumhq.wordpress.com/2012/01/25/a-smattering-of-selenium-76/

Linking directly to the turtorials:

http://www.xairon.net/2012/01/django-and-selenium-on-jenkinshudson-headless/ http://www.youtube.com/watch?feature=player_embedded&v=DL7gyuqkzzU

If you google for Selenium and XVFB you'll find lots more.

share|improve this answer
    
looks like some of these links broke –  MacGyver Mar 11 '13 at 2:01
    
Main site: wiki.jenkins-ci.org/display/JENKINS/Meet+Jenkins –  MacGyver Mar 11 '13 at 2:14
    
add comment

It is quite easy to hide the browser without XVFB. Just install PhantomJS. Then, change this line:

driver = webdriver.Firefox()

to:

driver = webdriver.PhantomJS()

The rest of your code won't need to be changed and no browser will open. For debugging purposes, use driver.save_screenshot('screen.png') at different steps of your code.

share|improve this answer
add comment

You can RUN the Test using HTMLUnitDriver, its the fastest and light weight of most of webdrivers

share|improve this answer
    
We use the C# drivers and NUnit, so I would have to re-write everything in Java, wouldn't I? –  MacGyver Feb 9 '12 at 16:19
    
The syntax changes from language to language, but the Logic what you are trying to test remains the same –  saikrishna Feb 13 '12 at 7:22
1  
@MacGyver: No, you don't have to switch the language, think of HTMLUnit as the browser that is started, not as a testing framework. It does not matter for you in what language it was written, like it does not matter for firefox etc. At the very minimum you can always start the selenium server and connect to it using the webdriver bindings, specifying you want HTMLUnit. In C#: IWebDriver drive = new RemoteWebDriver(DesiredCapabilities.HtmlUnit()); There might be also a HTMLUnitDriver (for connecting directly) in the C# bindings, as C# belongs to the four officially supported languages. –  zpea Jul 11 '12 at 18:47
add comment

You can attempt to run your tests inside an instance of the HtmlUnitDriver. I attempted to look at the documentation on this, but the chm file inside of the latest release seems to be botched.

There is also WebkitDriver, but that seems to be Java only for the time being.

share|improve this answer
3  
Reminder: if you use HtmlUnitDriver, there is no guarantee the same tests will actually work in a real browser. –  user246 Feb 8 '12 at 18:46
    
I read on the WebDriver wiki today that HTMLUnitDriver only works with the Java client drivers, so I won't be able to use this approach, since we use the C# client drivers. :-\ But I appreciate the input! –  MacGyver Feb 9 '12 at 16:21
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.