How to run headless REMOTE chrome using robot framework

后端 未结 6 979
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 09:52

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 = webd         


        
6条回答
  •  萌比男神i
    2020-12-14 10:49

    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
    

提交回复
热议问题