14

I recently installed Python 2.7, Robot Framework and the Selenium Library (I still don't know if I succeeded though...) on a Red Hat Server to run some test on a web application.

So I tried a simple test case using Robot Framework to see if Selenium Library is functional, just to Open a web page, nothing more...

Selenium Server is up and running according to the result of ps, and Firefox binaries are in the PATH...

Running the test case from the Robot Framework (with the pybot testcasename.tsv) I get an exception:

ERROR: Problem capturing a screenshot to string: java.awt.AWTException: headless environment

So, what is the headless environment? Does anyone have an idea if there is something else that needs to be installed or to be configured as well?

1
  • For everybody looking at this years later: there's now a few scriptable headless browsers. The most popular is probably being PhantomJS: phantomjs.org. Jan 5, 2017 at 16:28

2 Answers 2

19

Using the X Virtual Frame Buffer (Xvfb):

We can use xvfb to create a headless environment for selenium (for example, to run over SSH).


Instructions:

  1. Start xvfb with the following options:

    $ Xvfb :89 -ac -noreset

    (where :89 is the virtual "display" created).

  2. Then, set the DISPLAY variable to be this virtual display:

    $ export DISPLAY=:89

  3. At this point, we can run the selenium server as desired. Examples follow.

Run the server Java archive:

$ java -jar selenium-server.jar

In Python:

from selenium import webdriver

driver = webdriver.Firefox()
...
2
  • You're a genius! Thanks, <code>-ac -noreset</code> fixed my problem as well. Now I need to find out, why firefox doesn't have any fonts on my build machine .. hm.
    – peritus
    Mar 16, 2011 at 18:15
  • 1
    Also: I've found github.com/jordansissel/xdotool/blob/master/t/ephemeral-x.sh to be really handy when dealing with starting/stopping X servers and parallel builds.
    – peritus
    Mar 16, 2011 at 18:16
0

Here is a simple Robot library just for that purpose.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.