RobotFramework-通过打开浏览器关键字添加Chrome扩展

时间:2019-06-13 15:58:44

标签: python selenium google-chrome robotframework

我正在尝试向机器人框架添加chrome扩展。我正在使用关键字“打开浏览器”(通过添加desirable_capabilities),但是在运行此代码时,未添加任何扩展名(但不会发生错误)。我检查了crx文件的路径,该路径应该正确。

*** Settings ***
Library           SeleniumLibrary
Library           Process
Library           Collections
Suite Teardown    Close Browser   

***Variables***
${BROWSER}                  Chrome
${SELENIUM}                 http://hub:4444/wd/hub

*** Test Cases ***
Open Chrome with extension

    ${options} =        Create List          add_extension   ${CURDIR}/office-extension.crx
    ${arguments} =      Create Dictionary    args=${options}
    ${capabilities} =   Create Dictionary    chromeOptions=${arguments}

    Open Browser    chrome://extensions/    remote_url=${SELENIUM}    browser=${BROWSER}    desired_capabilities=${capabilities}
    Capture Page Screenshot

2 个答案:

答案 0 :(得分:0)

为我工作:

   *** Test Cases ***
Open Chrome with extension
    ${ChromeOptions} =     Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${ChromeOptions}    add_argument    remote-debugging-port\=9222
    Call Method    ${ChromeOptions}    add_argument    ${args}
    Call Method    ${ChromeOptions}    add_extension    ${EXECDIR}${/}Resources${/}BrowserAddons${/}test1.crx
    ${Options}=     Call Method         ${ChromeOptions}    to_capabilities      
    Create Webdriver    Chrome          desired_capabilities=${Options} 
    Go to     about:blank
    Maximize Browser Window

在此处打开浏览器关键字

Open Chrome with extension
    ${ChromeOptions} =     Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${ChromeOptions}    add_argument    remote-debugging-port\=9222
    Call Method    ${ChromeOptions}    add_argument    ${args}
    Call Method    ${ChromeOptions}    add_extension    ${EXECDIR}{/}test1.crx
    ${Options}=     Call Method         ${ChromeOptions}    to_capabilities      
    Open Browser    about:blank   Chrome            desired_capabilities=${Options}
    Maximize Browser Window

您不必使用remote-debugging-port \ = 9222,这是我必须要做的,否则chrome不会。

答案 1 :(得分:0)

我在浏览器打开时没有使用额外的参数,我是之后安装的。

select c.*,
       (select f.name
        from faculty f join
             course_faculty cf
             on cf.fk_facultyid = f.pid
        order by cf.isprimary desc
        limit 1
       ) as contact_faculty
from course c;