Robot Framework:使用“关闭所有浏览器”时,套件拆解失败

时间:2018-12-20 11:35:37

标签: python selenium selenium-webdriver robotframework selenium2library

我在 SeleniumLibrary 中使用了 chromedriver robotframework ,并且所有测试都能正常进行,但是套件拆卸失败。我似乎无法找出原因。帮助将不胜感激。 日志显示:

  

父套件拆卸失败: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)

3 个答案:

答案 0 :(得分:0)

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

要查看所使用的硒版本支持哪些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

答案 1 :(得分:0)

一种快速的解决方法是将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

答案 2 :(得分:0)

错误BadStatusLine: ''从python的httplib(http通信的核心模块)传播(如其名称所示:)),并且是由于 selenium 与浏览器的网络驱动程序。
它与Robot Framework的SeleniumLibrary / Selenium2Library没有关系-它只是硒库的包装器(我必须承认这是一个很好的包装器)。

因此,请查找该方向上的错误-已安装的selenium库的版本与已安装的chromedriver不能很好地兼容-一个发送到其他数据,这对于接收者来说是意外的。
我建议升级到两者的最新版本-当其中一个(明显)新于另一个时,确实会发生打h。