Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to hide the browser in Selenium RC?

I am using Selenium RC to automate some browser operations but I want the browser to be invisible. Is this possible? How? What about Selenium Grid? Can I hide the Selenium RC window also?

like image 966
Yatendra Avatar asked Sep 13 '09 16:09

Yatendra


People also ask

Can we minimize the browser in Selenium?

Unfortunately, Selenium does not provide any built-in function for minimizing the browser window. There is only the function for maximizing the window.

Can Selenium be used 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.

Why Selenium RC is deprecated?

Selenium RC comprises an additional layer of JavaScript known as the core which makes it slower. Selenium RC has complicated and redundant APIs. Selenium RC is not compatible with the HTMLUnit browser (required for headless execution). Selenium RC has in-built HTML report generation features for test results.


2 Answers

There are a few options:

  • 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 run Selenium 'headless' on Linux in XVFB. I've never tried doing this and doubt it's really worth the effort. http://www.alittlemadness.com/2008/03/05/running-selenium-headless/

  • 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.

like image 57
Dave Hunt Avatar answered Oct 12 '22 07:10

Dave Hunt


On Linux, you can run WebDriver in a headless (virtual) display to hide the browser. This can be done with Xvfb (X virtual framebuffer).

You can control Xvfb directly from Python code using xvfbwrapper: https://github.com/cgoldberg/xvfbwrapper

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() 

Install dependencies on Debian/Ubuntu:

$ sudo apt-get install xvfb $ pip install xvfbwrapper 
like image 37
Corey Goldberg Avatar answered Oct 12 '22 09:10

Corey Goldberg