【问题标题】:WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specifiedWebDriverException:消息:'浏览器似乎在我们连接之前已经退出。输出为:错误:未指定显示
【发布时间】:2013-09-20 03:41:39
【问题描述】:

在运行我的测试用例时,我的任何测试程序都尝试启动 firefox,但出现错误。我正在使用机器人框架、Selenium2Library 和 python 2.7。

1Login   [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open
| FAIL |
WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n'

我的 CentOS 服务器上有 Xwindows。我使用yum 安装了Firefox。我的firefox安装在firefox: /usr/bin/firefox /usr/lib64/firefox /usr/share/man/man1/firefox.1.gz

这里有什么问题?有没有人有类似的经历?有什么参考或建议吗?谢谢

编辑:

结果,在我运行demos之后。

==============================================================================
Login Tests                                                                   
==============================================================================
Login Tests.Invalid Login :: A test suite containing tests related to inval...
==============================================================================
[ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open
Invalid Username                                                      | FAIL |
Parent suite setup failed:
WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n'
------------------------------------------------------------------------------
Invalid Password                                                      | FAIL |
Parent suite setup failed:
WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n'
------------------------------------------------------------------------------
Invalid Username And Password                                         | FAIL |
Parent suite setup failed:
WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n'
------------------------------------------------------------------------------
Empty Username                                                        | FAIL |
Parent suite setup failed:
WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n'
------------------------------------------------------------------------------
Empty Password                                                        | FAIL |
Parent suite setup failed:
WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n'
------------------------------------------------------------------------------
Empty Username And Password                                           | FAIL |
Parent suite setup failed:
WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n'
------------------------------------------------------------------------------
Login Tests.Invalid Login :: A test suite containing tests related... | FAIL |
Suite setup failed:
WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n' 

6 critical tests, 0 passed, 6 failed
6 tests total, 0 passed, 6 failed
==============================================================================
Login Tests.Valid Login :: A test suite with a single test for valid login....
==============================================================================
[ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open
Valid Login                                                           | FAIL |
WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n'
------------------------------------------------------------------------------
Login Tests.Valid Login :: A test suite with a single test for val... | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Login Tests                                                           | FAIL |
7 critical tests, 0 passed, 7 failed
7 tests total, 0 passed, 7 failed
==============================================================================
Output:  /root/Downloads/robotframework-selenium2library/demo/output.xml
Log:     /root/Downloads/robotframework-selenium2library/demo/log.html
Report:  /root/Downloads/robotframework-selenium2library/demo/report.html

【问题讨论】:

  • 请添加引发错误的代码。
  • 它在 Windows 上运行良好。但是当我将它移到 Linux 时,出现错误。所以它不应该是代码错误。当我在 Linux 上配置我的项目时,我似乎错过了一些东西。我正在使用机器人框架和 Selenium2Library 和 python2.7。
  • 你有简单的例子可以测试整个环境是否正常工作吗?或任何参考资料?
  • 我在运行demos 后编辑了结果。 @理查德
  • 以防万一您已经尝试了所有方法但它还没有工作,如果您的 firefox 版本是 47,则将您的 firefox 降级到版本 45。版本 47 中存在一些错误。

标签: python selenium webdriver selenium-webdriver robotframework


【解决方案1】:

Selenium 需要一个显示器,而 Linux 没有,您需要下载一个虚拟显示器 (xvnc/xvfb)。然后启动虚拟显示服务器和export显示。

那么应该可以了

【讨论】:

  • 我已经安装了xorg-x11-server-Xvfb-1.13.0-11.el6.centos.x86_64。现在我导出DISPLAY=:1Demos 工作,但我的项目仍然出错。
  • 解决了。细节是:第一次启动 vncserver(例如vncserver :1)。第二组DISPLAY(例如DISPLAY=:1)。第三个更改目录到我的项目(例如cd /path/to/my/project)。第四次执行我的项目(例如pybot ··· ··· ···)。第 5 次杀死 vncserver(例如 vncserver -kill :1)。
【解决方案2】:

您的错误表明您没有指定显示器。这是一个很好的 qay 指定一个。

$ export  DISPLAY =<<name of server where viewer is configured>>:<<port associated>> 
$ xhost +

【讨论】:

    猜你喜欢
    • 2014-11-22
    • 2021-11-14
    • 2015-01-31
    • 2019-02-18
    • 1970-01-01
    • 2016-10-30
    • 2016-10-16
    • 2018-01-12
    • 2017-06-14
    相关资源
    最近更新 更多