KeyError:'值'使用robotframework xvfb模块运行无头浏览器测试时

时间:2017-06-13 09:26:04

标签: python robotframework

我正在尝试使用我的ubuntu机器上的机器人框架进行无头浏览器测试。以下是我每次执行脚本时都会遇到的错误。有人可以指导如何修复此错误。

    *** Settings ***
    Documentation     This example demonstrates how to use current library
    Library      Selenium2Library
    Library      XvfbRobot

    *** Test Cases ***

    Create Headless Browser
        Start Virtual Display    1920    1080
        Open Browser   https://www.google.com
        Set Window Size    1920    1080
        ${title}=    Get Title
        Should Be Equal    Google    {title}
        [Teardown]    Close Browser


    root@hyi01lr0bsaehost92:/var/robot-tests# pybot headless.robot 
    ==============================================================================
    Headless :: This example demonstrates how to use current library              
    ==============================================================================
    [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open
    Create Headless Browser                                               | FAIL |
    KeyError: 'value'
    ------------------------------------------------------------------------------
    Headless :: This example demonstrates how to use current library      | FAIL |
    1 critical test, 0 passed, 1 failed
    1 test total, 0 passed, 1 failed
    ==============================================================================
    Output:  /var/robot-tests/output.xml
    Log:     /var/robot-tests/log.html
    Report:  /var/robot-tests/report.html

我也尝试过使用Python脚本,但是我也遇到了同样的错误。

    #!/usr/bin/env python

    from pyvirtualdisplay import Display
    from selenium import webdriver

    display = Display(visible=0, size=(800, 600))
    display.start()

    # now Firefox will run in a virtual display. 
    # you will not see the browser.
    browser = webdriver.Firefox()
    browser.get('http://www.google.com')
    print browser.title
    browser.quit()
    display.stop()


root@hyi01lr0bsaehost92:/var/robot-tests# python seleniumheadless.py 
Traceback (most recent call last):
  File "seleniumheadless.py", line 13, in <module>
    browser = webdriver.Firefox()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 155, in __init__
    keep_alive=True)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 183, in start_session
    self.capabilities = response['value']
KeyError: 'value'

尝试使用webdriver.Chrome()

时出现以下错误
root@hyi01lr0bsaehost92:/var/robot-tests# python seleniumheadless.py 
Traceback (most recent call last):
  File "seleniumheadless.py", line 11, in <module>
    browser = webdriver.Chrome()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 238, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
  (Driver info: chromedriver=2.26.436382 (70eb799287ce4c2208441fc057053a5b07ceabac),platform=Linux 3.13.0-119-generic x86_64)

root@hyi01lr0bsaehost92:/var/robot-tests# which google-chrome
/usr/bin/google-chrome

0 个答案:

没有答案