WebDriverException:Message:'在连接之前,浏览器似乎已退出。输出为:错误:未指定显示

2024-05-29 02:12:11 发布

您现在位置:Python中文网/ 问答频道 /正文

当运行我的测试用例时,任何我的测试程序尝试启动firefox,我都会出错。我正在使用robotframework、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: /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

Tags: thetobrowsermessageoutputhaveloginsuite
2条回答

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

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

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

然后应该可以了

相关问题 更多 >

    热门问题