如何使用机器人框架运行无头REMOTE chrome [英] How to run headless REMOTE chrome using robot framework

查看:105
本文介绍了如何使用机器人框架运行无头REMOTE chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过我的机器人框架测试套件无头运行chrome. 我设法使用selenium独立地使用python进行了以下操作:

I'm trying to run chrome headless with my robot framework tests suites. I managed to do it independtly with python using selenium as follows:

options = webdriver.ChromeOptions()
options.add_argument('--headless')
my_driver = webdriver.Remote(command_executer=my_remote_address, desired_capabilities=options.to_capabilities)

以下代码是我在机器人程序中执行的,但是没用:

The following code is what I did in robot but didn't work:

${options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys, selenium.webdriver
${options.add_argument}=  Set Variable  add_argument=--headless
Create WebDriver  Chrome  chrome_options=${options}

Open Browser   http://www.google.com   chrome

推荐答案

要无头运行,您需要设置参数并将其转换为功能,以便在使用Remote Driver选项时可以使用它们.此方法适用于Open BrowserCreate Webdriver导航至URL的方式.

To run headless you need to set the arguments and convert them to capabilities so that they can be used when using the Remote Driver option. This works for both the Open Browser as well as the Create Webdriver way of navigating to a URL.

*** Settings ***
Library    Selenium2Library

Suite Teardown    Close All Browsers

*** Test Cases ***
Headless Chrome - Create Webdriver
    ${chrome_options} =     Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${chrome_options}   add_argument    headless
    Call Method    ${chrome_options}   add_argument    disable-gpu
    ${options}=     Call Method     ${chrome_options}    to_capabilities      

    Create Webdriver    Remote   command_executor=http://localhost:4444/wd/hub    desired_capabilities=${options}

    Go to     http://cnn.com

    Maximize Browser Window
    Capture Page Screenshot

Headless Chrome - Open Browser
    ${chrome_options} =     Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${chrome_options}   add_argument    headless
    Call Method    ${chrome_options}   add_argument    disable-gpu
    ${options}=     Call Method     ${chrome_options}    to_capabilities     

    Open Browser    http://cnn.com    browser=chrome    remote_url=http://localhost:4444/wd/hub     desired_capabilities=${options}

    Maximize Browser Window
    Capture Page Screenshot

这篇关于如何使用机器人框架运行无头REMOTE chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆