/ chromeoptions

Robot Framework Selenium ChromeOptions

I've found that there is a lack of resources for defining Google Chrome settings in RobotFramework's SeleniumLibrary (formerly Selenium2Library). Recently, I needed to connect my Selenium containers with a proxy for a project I was working on. I needed to set the chromeOptions proxy-server flag. Unfortunately, I couldn't find much online for this use case. While the SeleniumLibrary documentation technically explains this, its definitely not clear and took a lot of trial and error before I figured this out. There are many ways to do this when you write a custom keyword of your own and use the native selenium library (SO example). You can use this method to set other ChromeOptions too

I used 4 spaces as my seperator. You can change that to whatever your RF project uses.

${list} =     Create List    --proxy-server=http://${ip address}:${port}
${args} =     Create Dictionary    args=${list}
${desired caps} =     Create Dictionary    platform=${OS}     chromeOptions=${args}
Open Browser    https://www.google.com    remote_url=${grid_url}    browser=${BROWSER}    desired_capabilities=${desired caps}

${desired caps} is where the compiled desired capabilities should go. By creating a list and then a dictionary, we create the object that Chrome expects for its ChromeOptions.

Here are the required data types broken down with some other examples and where too find out what data type is required.

desired_capabilites => dictionary
    browserName => string
    version => string
    platform => string
    chromeOptions => dictionary
        binary => string
        args => list of strings
        extensions => list of strings

The desired_capabilities are from the Selenium Wiki:
Screen-Shot-2017-10-24-at-2.11.03-PM

The chromeOptions are from this the Chrome Driver Docs:
Screen-Shot-2017-10-24-at-2.08.53-PM

My library versions for reference:

robotframework>=3.0.2
robotframework-seleniumlibrary>=3.0.0b1
selenium>=3.5.0

SO python method (instead of test-type, just set the proxy option):

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
capabilities.setCapability("chrome.binary", "<Path to binary>");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
webDriver = new ChromeDriver(capabilities);