How to run headless REMOTE chrome using robot framework

后端 未结 6 1002
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 10:52

    Try out these two keywords:

    Open Chrome
        [Arguments]    ${url}    ${lang}
        ${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
        Create Webdriver    Chrome    chrome_options=${chrome_options}
        Go To    ${url}
    
    Open Remote Chrome
        [Arguments]    ${url}    ${remote_url}    ${lang}
        ${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
        Open Browser    ${url}    Chrome    remote_url=${remote_url}    desired_capabilities=${chrome_options.to_capabilities()}
    

    First one will launch a local chrome, while the second one is to launch a remote chrome. If you need to be able to handle the remote vs. local into a single keyword, you can create a wrapper around these two with a boolean argument that will determine which keyword to call.

提交回复
热议问题