RobotFramework - adding chrome extension through Open Browser keyword

Viewed 1515

I am trying to add a chrome extension to robot framework. I am using the keyword Open Browser (by adding the desired_capabilities) but when I run this code no extension is added (but no error occurs). I checked the path for the crx file and it should be correct.

*** 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 Answers

This work for me:

   *** 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

Here with the open Browser keyword

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

You don't have to use the remote-debugging-port\=9222, this is something I have to do otherwise chrome wouldn't.

I didnt use additional parameters during browser opening, I`ve installed it after.

${EXTENSION URL}  https://chrome.google.com/webstore/detail/....
${EXT INSTALL BTN}  //*[contains(text(), "Add to Chrome")]

Open Browser  ${EXTENSION URL}  chrome
Wait Until Page Contains  Extension name here
Click Element  ${EXT INSTALL BTN}
Sleep  5 sec
Keyboard.Press Keys  left
Sleep  1 sec
Keyboard.Press Keys  enter
Wait Until Page Contains  Remove from Chrome
Related