Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

exception - Selenium and Headless Environment

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...