Selenium 和 Headless 环境

发布于 2024-10-05 10:33:43 字数 424 浏览 0 评论 0原文

我最近在 Red Hat 服务器上安装了 Python 2.7、Robot Framework 和 Selenium 库(虽然我仍然不知道是否成功......),以在 Web 应用程序上运行一些测试。

所以我使用Robot Framework尝试了一个简单的测试用例,看看Selenium库是否功能正常,只是为了打开一个网页,仅此而已......

Selenium服务器根据ps的结果启动并运行,并且Firefox二进制文件在PATH中...

从机器人框架运行测试用例(使用 pybot testcasename.tsv)我得到一个异常:

错误:将屏幕截图捕获到字符串时出现问题:java.awt.AWTException:无头环境

那么,什么是无头环境?有谁知道是否还需要安装或配置其他东西?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恋你朝朝暮暮 2024-10-12 10:33:43

使用 X 虚拟帧缓冲区 (Xvfb):

我们可以使用 xvfb 为 selenium 创建无头环境(例如,通过 SSH 运行)。


说明:

  1. 使用以下选项启动xvfb

    $ Xvfb :89 -ac -noreset

    (其中 :89 是创建的虚拟“显示”)。

  2. 然后,将 DISPLAY 变量设置为此虚拟显示器:

    $ 导出 DISPLAY=:89

  3. 此时,我们可以根据需要运行 selenium 服务器。示例如下。

运行服务器 Java 存档:

$ java -jar selenium-server.jar

在 Python 中:

from selenium import webdriver

driver = webdriver.Firefox()
...

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()
...
南街女流氓 2024-10-12 10:33:43

这是一个简单的机器人库,就是为了这个目的。

Here is a simple Robot library just for that purpose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文