Serenity-core: Add extension to the Chrome Options using SerenityBDD

Created on 28 Jan 2019  路  5Comments  路  Source: serenity-bdd/serenity-core

Hi,

I am trying to add an extension to the chrome using serenity.properties file. But I am not able to achieve it. Is there any way to do it?

waiting for feedback

Most helpful comment

For anyone that comes across this, use chrome.extension = path/to/extension.crx

All 5 comments

How would you code this in plain Selenium?

Just did a quick check, this works:

public class ChromeDriverWithExtension implements DriverSource {
   @Override
    public WebDriver newDriver() {
        try {
            ChromeOptions options = new ChromeOptions();
            options.addExtensions(new File("extension.crx"));
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
            return new ChromeDriver(options);
        }
        catch (Exception e) {
            throw new Error(e);
        }
    }

    @Override
    public boolean takesScreenshots() {
        return true;
    }
webdriver.driver = provided
webdriver.provided.type = mydriver
webdriver.provided.mydriver = au.com.acme.ChromeDriverWithExtension
thucydides.driver.capabilities = mydriver

Using a custom driver is probably the best option at this atage

For anyone that comes across this, use chrome.extension = path/to/extension.crx

Was this page helpful?
0 / 5 - 0 ratings