Hey Harsha, you can load an extension in chrome browser using ChromOptions in Selenium Webdriver. You can follow these steps to add a chrome extensions to chromeOptions and then load it while running a browser:
-
Add "GET CRX" extension from Google Web Store.
-
Download your extension (in my case its Selenium IDE extension).
-
Go to Chrome Web Store >> Search for your extension (the one you've already downloaded) >> Click on Get CRX on top-right of the browser >> Click on Get CRX for this Extension. This would download the CRX file.
-
Now, write your test script by following this code snippet:
-
public class openChromeExtension {
public static String driverPath = "C:\\\\Users\\\\Rishabh\\\\Downloads\\\\chromedriver.exe";
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", driverPath);
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("C:\\Users\\Rishabh\\Downloads\\Selenium IDE.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
System.out.println("Opening extension");
driver.get("chrome-extension://mooikfkahbdckldjjndioackbalphokd/index.html");
driver.navigate().refresh();
System.out.println("Refresh successfully");
}
}