【问题标题】:Robot Framework: Suite Teardown fails when using Close All Browsers机器人框架:使用关闭所有浏览器时套件拆解失败
【发布时间】:2019-05-20 22:17:17
【问题描述】:

我将 chromedriver、robotframework 与 SeleniumLibrary 一起使用,所有测试都运行良好,但套件拆解失败。我似乎无法找出原因。帮助将不胜感激。 日志显示:

父套件拆解失败:BadStatusLine: ''

*** Settings ***
Suite Setup Open Database Connection
Test Setup  Login
Suite Teardown   Suite shutdown

*** Test cases ***
...
...

*** Keywords ***
Suite shutdown
     Disconnect from Database
     Close All Browsers

已安装的版本

  • chromedriver 2.45.615291
  • 机器人框架 3.1.1
  • python 2.7.12
  • SeleniumLibrary 3.3.1
  • 硒 3.141.0

我注销了导致 BadStatusLine 错误的原因,希望这有助于找到解决方案

    09:26:28.700    FAIL    BadStatusLine: ''    
    09:26:28.700    DEBUG   Traceback (most recent call last):   
File "C:\Python27x86\lib\site-packages\SeleniumLibrary\__init__.py", line 372, in run_keyword
        return DynamicCore.run_keyword(self, name, args, kwargs)   
File "C:\Python27x86\lib\site-packages\SeleniumLibrary\base\robotlibcore.py", line 102, in run_keyword
        return self.keywords[name](*args, **kwargs)   
File "C:\Python27x86\lib\site-packages\SeleniumLibrary\keywords\browsermanagement.py", line 47, in close_all_browsers
        self.drivers.close_all()  
File "C:\Python27x86\lib\site-packages\SeleniumLibrary\keywords\webdrivertools.py", line 245, in close_all
        driver.quit()   File "C:\Python27x86\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 158, in quit
        self.service.stop()   
File "C:\Python27x86\lib\site-packages\selenium\webdriver\common\service.py", line 151, in stop
        self.send_remote_shutdown_command()   
File "C:\Python27x86\lib\site-packages\selenium\webdriver\common\service.py", line 127, in send_remote_shutdown_command
        url_request.urlopen("%s/shutdown" % self.service_url)   
File "C:\Python27x86\lib\urllib2.py", line 154, in urlopen
        return opener.open(url, data, timeout)   File "C:\Python27x86\lib\urllib2.py", line 429, in open
        response = self._open(req, data)   
File "C:\Python27x86\lib\urllib2.py", line 447, in _open
        '_open', req)   File "C:\Python27x86\lib\urllib2.py", line 407, in _call_chain
        result = func(*args)   
File "C:\Python27x86\lib\urllib2.py", line 1228, in http_open
        return self.do_open(httplib.HTTPConnection, req)   
File "C:\Python27x86\lib\urllib2.py", line 1201, in do_open
        r = h.getresponse(buffering=True)   
File "C:\Python27x86\lib\httplib.py", line 1136, in getresponse
        response.begin()   
File "C:\Python27x86\lib\httplib.py", line 453, in begin
        version, status, reason = self._read_status()   
File "C:\Python27x86\lib\httplib.py", line 417, in _read_status
        raise BadStatusLine(line)

【问题讨论】:

  • 您使用哪个网络驱动程序?
  • 套件关机按预期工作
  • 我正在使用最新的 chromedriver。 3天前下载的。
  • chromedriver=2.45.615291

标签: python selenium selenium-webdriver robotframework selenium2library


【解决方案1】:

您使用的 selenium 版本可能会导致此问题。

要查看哪些版本的 selenium 支持您使用的 python 版本,请查看。 https://github.com/robotframework/SeleniumLibrary/blob/master/README.rst#support

*** Settings ***
Suite Setup    Open Database Connection
Test Setup     Login
Suite Teardown    Suite shutdown
Library    SeleniumLibrary

*** Test cases ***
...
...

*** Keywords ***
Suite shutdown
    Disconnect from Database
    Close All Browsers

【讨论】:

  • 我有 2.7.12 Python 和 Selenium2Library 3.0.0,所以这应该不是问题
  • @LorandFazakas 尝试改用 SeleniumLibrary
  • 添加一个 run 关键字并忽略错误,只会使套件拆解不运行...我会先尝试使用 SeleniumLibrary。
  • 如果我没记错的话,我已经安装了 SeleniumLibrary,因此它也暴露为 Selenium2Library。运行 pip install --upgrade robotframework-selenium2library 说一切都是最新的
  • 我用 SeleniumLibrary 试了一下,还是出现了同样的错误。
【解决方案2】:

快速解决方法是将Run Keyword And Ignore Error 添加到您的 Suite Teardown 中,它仍然会执行有效的命令,但会跳过类似这样的错误命令

*** Settings ***


Library  Selenium2Library
Suite Teardown   Run Keyword And Ignore Error  Suite shutdown



*** Test Cases ***
Test Keyword
    Open Browser  http://google.com  chrome

*** Keywords ***
Suite shutdown
     Erro1234r # This should fail due to no keyword named Erro1234r, it skips this and closes all browsers
     Close All Browsers

【讨论】:

    【解决方案3】:

    错误BadStatusLine: '' 传播自 python 的 httplib - http 通信的核心模块(从它的名字可以明显看出 :)),并且来自 selenium 和 webdriver 之间的通信错误浏览器。
    它与 Robot Framework 的 SeleniumLibrary/Selenium2Library 没有任何关系——它只是 selenium 库的一个包装器(我必须承认它非常好)。

    因此,寻找那个方向的错误 - 您安装的 selenium 库的版本与已安装的 chromedriver 无法正常工作 - 一个发送到另一个数据,这对收件人来说是意外的。
    我建议升级到两者的最新版本 - 当一个(显着)比另一个更新时,确实会发生这种问题。

    【讨论】:

    • 我无法将 Python 升级到最新版本,因为它的公司政策。我试图将 chromedriver 降级到 2.4.3,因为它是适用于 chrome 71.0 的最新版本。不幸的是,仍然是同样的错误。架构差异是否会导致此类错误?
    • 我说的是 selenium library,而不是 python 本身 - 你能更新它吗?执行此操作的命令通常是“pip install --upgrade selenium”。较早的版本很可能无法与 chromedriver 一起使用。
    • 它已经是最新的 (3.141.0)。运行命令说Requirement already up-to-date: selenium in c:\python27\lib\site-packages (3.141.0)Requirement already satisfied, skipping upgrade: urllib3 in c:\python27\lib\site-packages (from selenium) (1.24.1)
    猜你喜欢
    • 2017-11-01
    • 2014-01-31
    • 2018-11-06
    • 2013-02-07
    • 1970-01-01
    • 2015-07-31
    • 2016-09-06
    • 2020-06-04
    • 2017-08-22
    相关资源
    最近更新 更多