问题描述
我最近在Red Hat服务器上安装了Python 2.7,Robot Framework和Selenium Library(我仍然不知道我是否已经成功),以便在Web应用程序上运行一些测试。
所以我尝试一个简单的测试用例,使用机器人框架来看看Selenium库是否有效,只是打开网页,没有更多的...
Selenium服务器根据ps的结果启动并运行,firefox二进制文件位于PATH ...
从机器人运行测试用例框架(与pybot testcasename.tsv)我得到一个例外:
错误:捕获到字符串截图的问题:java.awt.AWTException:无头环境
那么,无头环境是什么?
有没有人有想法,如果还有其他东西需要被配置或配置好吗?
使用X虚拟帧缓冲区(Xvfb):
我们可以使用xvfb为硒创建无头环境(例如,通过SSH运行)。 >
说明:
-
开始
xvfb
与以下选项:
$ Xvfb:89 -ac -noreset
(其中
:89
是创建的虚拟显示)。 > -
然后,将
DISPLAY
变量设置为此虚拟显示:
$ export DISPLAY =:89
-
在这一点上,我们可以运行硒服务器。
运行服务器Java存档:
$ java -jar selenium-server.jar
在Python中:
从selenium import webdriver
driver = webdriver.Firefox()
...
I recently installed Python 2.7, Robot Framework and the Selenium Library (I still don't know if I succeded though...) on a Red Hat Server to run some test on a web application.
So I tried a simple test case using the 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 istalled or to be configured as well?
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:
Start
xvfb
with the following options:$ Xvfb :89 -ac -noreset
(where
:89
is the virtual "display" created).Then, set the
DISPLAY
variable to be this virtual display:$ export DISPLAY=:89
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()
...
这篇关于硒和无头环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!