You could use Selenium Grid so that the browser is opened on a completely different machine (or virtual machine) that you can then connect to via VNC or Remote Desktop Connection if you wanted to see the browser. Also, another option: if you run a Jenkins foreground process on that remote server, it can execute your test project on the desktop.
You can wrap Selenium RC in a Windows service. http://support.microsoft.com/kb/137890 . Except that permissions constraints on later versions of windows will probably prevent Selenium from accessing the desktop like Windows 2000 used to allow us to do.
Another option would be to use something like WebDriver HTMLUnitDriver, which doesn't launch a 'real' browser. http://code.google.com/p/webdriver/ . Also there is a PhantomJS option as well as a 'headless Chrome' that you could use.
Of course there's also the option of using a service like SauceLabs, where you can get your tests to be run in the cloud. After your tests have completed you can watch a video of them running.
For having the tests run completely hidden, I think you don't have much solutions if you're on windows.
What I'd do it to dedicate a computer in your LAN to be online all the time and have a selenium RC server running. So you use that computer's IP instead of localhost to run your tests. For example:
(considering that that's the ip of the computer running the server).
Having that setup, you run your tests in you computer, the browsers and the RC server window are in another computer and the go back to yours once done.
If you're on Windows, one option is to run the tests under a different user account. This means the browser and java server will not be visible to your own account.
Python code for running headless would look like this:
from selenium import webdriver
from xvfbwrapper import Xvfb
display = Xvfb()
display.start()
# now Firefox will run in a virtual display.
# you will not see the browser.
driver = webdriver.Firefox()
driver.get('http://www.google.com')
print(driver.title)
driver.quit()
display.stop()
On Linux, you can run your test browser on a virtual display. You will need the xvfb package for creating a virtual X server. On Debian based distros, just run
sudo apt-get install xvfb
There is a nice tool ephemeral-x.sh that will conveniently set up any command to run on the virtual display. Download it and make it executable:
There is a PhantomJS related project called GhostDriver , that is meant to run PhantomJS instances in a Selenium Grid using webdriver wire JSON protocol. That is probably what you are looking for, although this question is 4 years old now.
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.
On MacOSX, I haven't been able to hide the browser window, but at least I figured out how to move it to a different display so it doesn't disrupt my workflow so much. While Firefox is running tests, just control-click its icon in the dock, select Options, and Assign to Display 2.
By the way this is a feature needed by any developer running e2e that logically will spawn browsers. In a development environment it is annoying to deal with the window that keeps popping up and which which you can accidentally interact making the test fail.
In many cases PhantomJS will not completely suit your needs, I would like to elaborate on the headless chrome option mentioned in Dave Hunt's answer.
chrome 57 has just launched this feature. You can use it by passing the --headless flag via ChromeDriver, for more info see the discussion in this question
Using headless Chrome would be your best bet, or you could post directly to the site to interact with it, which would save a lot of compute power for other things/processes. I use this when testing out web automation bots that search for shoes on multiple sites using cpu heavy elements, the more power you save, and the simpler your program is, the easier it is to run multiple processes at a time with muhc greater speed and reliability.