2
votes

I was able to make the following work in Java:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
driver.get("https://www.google.com");

Now, I am using the Java port of Selenium2Library for Robot Framework. How can I do something similar to the one above? I've tried the following:

${chrome_options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
${chrome_capabilities}=    Evaluate    sys.modules['selenium.webdriver'].DesiredCapabilities.CHROME    sys, selenium.webdriver
Call Method    ${chrome_options}    add_argument    disable-extensions
Set To Dictionary    ${chrome_capabilities}    ChromeOptions.CAPABILITY=${chrome_options}
Open Browser    https://www.google.com    Chrome    None    None        desired_capabilities=${chrome_capabilities}    None

There's a pop-up that appears every time I open a browser, that's why I need to disable chromeOptions. As mentioned above, I was able to make the pop-up disappear using the Java code. I just couldn't do the same with RF.

Thanks for your help.

2

2 Answers

0
votes

Pass the Chrome options via the desiredCapabilities argument to Open Browser as a JSON string. If you create a capabilities object in Java, use the toJson method to create a JSON object. Then use the getAsString method on the JSON object to get a string. Then pass that string as the value for desiredCapabilities. So, essentially you need to create a Java user keyword that returns a desired capabilities string.

# the below should return something similar to {'platform': 'ANY', 'browserName': 'chrome', 'version': '', 'chromeOptions': {'args': ['--disable-extensions'], 'extensions': []}, 'javascriptEnabled': True}
${desired caps}    Get Capabilities    # call custom keyword to get capabilities string
Open Browser    https://stackoverflow.com    gc    desiredCapabilities=${desired caps}

public String getCapabilities() {}
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--disable-extensions");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    return capabilities.toJson().getAsString();
}
-3
votes

Instead of using "Open Browser" use the "Create Webdriver" keyword.