How to run selenium webdriver in the background?

13,793

Solution 1

Try PhantomJS which is a headless browser webkit. HTMLUnit is also similar to PhantomJs; however, usage of PhamtomJs is highly recommended.

PhantomJs uses Google chrome's JavaScript Engine but without a GUI.

Refer :http://phantomjs.org/

Solution 2

Found simple solutin for JAVA Seleniun Google Chrome

    System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("headless");
    return new ChromeDriver(options);

Solution 3

if the server is on linux, you can allocate a display just to run selenium using Xvfb to create a virtual display

if the server is on windows you can register the daemon to run as another user than the user logged in, giving the service a desktop. this only work for the local system admin account or by registry tweaking as detailed here note that you will have to set up internet explorer properties for the user the service is running as

Solution 4

Phantom is good headless option, but sssuming you want to stick with same tools you are using ... (the following assumes Linux as platform)

  1. install xvfb (apt-get install xvfb)
  2. You can then run selenium/firefox "headless" (assuming Linux) with the following command:-

DISPLAY=:1 xvfb-run java -jar [selenium JAR filename]

Now, when your test suite kicks off selenium, it will run using Firefox without browser windows popping up.

Solution 5

Give it a try : https://github.com/detro/ghostdriver.

It uses Headless approach to automate websites.

Share:
13,793
Bruno Sousa
Author by

Bruno Sousa

Updated on June 14, 2022

Comments

  • Bruno Sousa
    Bruno Sousa almost 2 years

    I've been using Selenium for 2 weeks.

    It's been really useful so far.

    When developing, I like having the browsers pop up so I can see what's going on, but in production, I don't want the server to keep opening and closing Firefox windows. I've looked through this forum, done Google searches, etc., but can't find a way to run the browsers in the background.

    Anybody have a tip on how to do this?

  • wittn
    wittn about 5 years
    Great, simple way.