Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing with a selenium driver in Java without opening any browser

I need to test with selenium chrome driver in Java. But chrome window should't be opened. Assume this a product and no window should be opened.

I've also looked at this one ; Is it possible to hide the browser in Selenium RC? But no solution for me. The testing should be operating system independent and I've tried HtmlUnitDriver for testing without opening any window but it has some problem. When there is finding components by id, it may not find the component by id. Some servers may send the component id according to browser and I can't know what id I should use to test.

Because of that I'm trying to use chrome driver.

Is there a way to use chromedriver without opening chrome window or another way to test without opening any window with Selenium in Java?

Thank!

like image 677
Ahmet DAL Avatar asked Jul 05 '12 13:07

Ahmet DAL


People also ask

Can I use Selenium without opening browser?

We can perform Selenium testing without a browser. This is achieved by triggering the execution in a headless mode. The headless execution can decrease the utilization of key resources and is being adopted widely.

Can I use ChromeDriver without Chrome?

Users provided relevant link to confirm that, "YES" a full Chrome installation is needed in addition to the actual chromedriver. Show activity on this post. In my case, I am using PowerShell.

Can we run Selenium in background?

Selenium Webdriver can run in the background, i.e. without opening a browser window, by running it in Headless mode. To do this you need to add the required capability to the set-up code for the driver.

Can I use Selenium without GUI?

We can run Selenium (Firefox) webdriver without a GUI. This means that the execution has to be kicked in headless mode. The headless execution is popular now since it results in less consumption of resources. Firefox, without GUI, can be executed after we set the geckodriver path.


1 Answers

Go with PhantomJS but if running them in chromedriver is required and you have the resources, this blog has a good recipe on running headless selenium with chrome. Requiring you to download the following...

  • VirtualBox
  • Vagrant
  • NodeJS

If you plan to implement Jenkins or any other CI in the future, I strongly suggest going with PhantomJS though.

like image 122
Russell Bradley Avatar answered Sep 29 '22 10:09

Russell Bradley