使用Robot Framework执行selenium示例时出错

时间:2013-02-15 15:52:19

标签: selenium python-2.7 selenium-webdriver robotframework

在我的系统上我有Python 2.6和Robot框架。我按照以下链接的说明安装了Selenium2Library: https://github.com/rtomac/robotframework-selenium2library  但是当我尝试运行该示例时,它给出了以下错误并且没有打开firefox窗口。

ERROR:  clean-python26-env]$ python testExeJS.py 
======================================================================
ERROR: test_exe_javascript (__main__.ExecuteJavascriptTestCase)
----------------------------------------------------------------------

Traceback (most recent call last):
  File "testExeJS.py", line 7, in setUp
    selenium.setTimeout("60000")
NameError: global name 'selenium' is not defined

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)

任何帮助都是真正的帮助

修改

我很抱歉我刚刚看到你的回复。可能这将有助于您更多地了解我的问题。 示例代码链接是: `http://www.wallix.org/2011/07/26/how-to-use-robotframework-with-the-selenium-library/

我的运行错误是:

$ pybot myFirstTest.txt 

==============================================================================
myFirstTest :: This is your first test                                        
==============================================================================
[ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open
Go To Google Page [Documentation] Go to google page and search som... | FAIL |
WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n'
------------------------------------------------------------------------------
[ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open
Open Selenium Page [Documentation] TestCase for open Selenium page    | FAIL |
No browser is open
------------------------------------------------------------------------------
myFirstTest :: This is your first test                                | FAIL |
2 critical tests, 0 passed, 2 failed
2 tests total, 0 passed, 2 failed
==============================================================================
Output:  /data/home/sadikhan/ironport/Selenium/output.xml
Log:     /data/home/sadikhan/ironport/Selenium/log.html
Report:  /data/home/sadikhan/ironport/Selenium/report.html

1 个答案:

答案 0 :(得分:1)

好的,所以我在这里注释日志,希望你能看到如何阅读它并在将来调试它。我为任何不准确之处道歉,因为我已经习惯了Selenium2Library:

$ pybot myFirstTest.txt 
==============================================================================
myFirstTest :: This is your first test                                        
==============================================================================
[ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open

好的,这是你的第一个线索 - selenium试图截取屏幕截图,但没有看到浏览器打开 - 你看到浏览器打开了吗?它是否可以打开正确的页面?

Go To Google Page [Documentation] Go to google page and search som... | FAIL |
WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n'

所以这是下一个线索 - The browser appears to have exited before we could connect. The output was: Error: no display specified - 所以这指出问题是你正在无头跑,SeleniumLibrary希望找到一个显示器(如果我错了请纠正我)所以你可能需要创建一个比听起来更容易的东西 - 你需要安装PyVirtualDisplay,然后再从机器人框架中安装 - 在使用SeleniumLibrary之前尝试使用| Library | pyvirtualdisplay.smartdisplay.SmartDisplay |

------------------------------------------------------------------------------
[ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open

这是第一个线索。

Open Selenium Page [Documentation] TestCase for open Selenium page    | FAIL |
No browser is open

这是因为早期的问题。

------------------------------------------------------------------------------
myFirstTest :: This is your first test                                | FAIL |
2 critical tests, 0 passed, 2 failed
2 tests total, 0 passed, 2 failed
==============================================================================
Output:  /data/home/sadikhan/ironport/Selenium/output.xml
Log:     /data/home/sadikhan/ironport/Selenium/log.html
Report:  /data/home/sadikhan/ironport/Selenium/report.html