2

I've faced with a problem that I'm not able to open Chrome with any extension. I've already added an extension but don't know how to run it properly with Selenide framework. Could you please help me

@BeforeClass
public static void setUp() {
   Configuration.browser = "chrome";
   System.setProperty("selenide.browser", "chrome");
   ChromeOptions options = new ChromeOptions();
   options.addExtensions(new File("src/main/resources/uBlock Origin.crx"));
        }
Rajagopalan
  • 5,465
  • 2
  • 11
  • 29
hamvee
  • 141
  • 3
  • 13

3 Answers3

2

Selenide : http://selenide.org/2018/01/12/selenide-4.10/

You can set custom capabilities in Configuration, and Selenide will use them when opening a browser:

Configuration.browserCapabilities = new DesiredCapabilities();
Configuration.browserCapabilities.setCapability(SOME_CAP, "SOME_VALUE_FROM_CONFIGURATION");

Also you can set custom webdriver like in @dangi13 answer:

WebDriverRunner.setWebDriver(myDriverWithExtension);
Sers
  • 12,047
  • 2
  • 12
  • 31
1

I do not know how to do it in selenide but you can add extension in selenium like this :

public static WebDriver getChromeDriverWithAdblockCrx() {
          System.setProperty("webdriver.chrome.driver", "src//main//resources//chromedriver.exe");
          DesiredCapabilities capabilities = new DesiredCapabilities();
          ChromeOptions options = new ChromeOptions();
          options.addExtensions(new File("src//main//resources//uBlock Origin.crx"));
          capabilities.setCapability(ChromeOptions.CAPABILITY, options);

          return new ChromeDriver(capabilities);
    }

Hope that helps you:).

dangi13
  • 1,275
  • 1
  • 8
  • 11
1

@sers, @dangi13 Thanks a lot!

But capabilities were not added from Configuration.browserCapabilities. I wrote the following code:

@BeforeClass
public static void setUp() {
Configuration.browser = "chrome";
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("src/main/resources/uBlock Origin.crx"));
Configuration.browserCapabilities = new DesiredCapabilities();
Configuration.browserCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
}

It is known issue that is mentioned on github: https://github.com/codeborne/selenide/issues/676

As workarond I'm using the following option:

@BeforeClass
public static void setUp() {
System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver.exe");
Configuration.browser = "chrome";
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("src/main/resources/uBlock Origin.crx"));
WebDriver webDriver = new ChromeDriver(options);
setWebDriver(webDriver);
}
hamvee
  • 141
  • 3
  • 13