0

I need to launch a particular chrome extension in my automation. I am currently using Selenium with Java. But I am unable to launch my chrome extension.

Dev
  • 2,739
  • 2
  • 21
  • 34
John
  • 17
  • 4
  • 1
    Possible duplicate of [Open a chrome extension through Selenium WebDriver using Python](https://stackoverflow.com/questions/25557533/open-a-chrome-extension-through-selenium-webdriver-using-python) – Dev May 16 '19 at 18:09

1 Answers1

1

Basicaly there are two approaches.

1. install desired extension in runtime - https://dev.to/razgandeanu/testing-chrome-extensions-with-selenium-491b

2. manualy install desired extension do existing browser profile and use the existing profile in selenium. Like this:

package packageName;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class WebdriverSetup {   
    public static String chromedriverPath = "C:\\Users\\pburgr\\Desktop\\selenium-tests\\GCH_driver\\chromedriver.exe";

    // my default profile folder
    public static String chromeProfilePath = "C:\\Users\\pburgr\\AppData\\Local\\Google\\Chrome\\User Data";    

    public static WebDriver driver; 
    public static WebDriver startChromeWithCustomProfile() {
        System.setProperty("webdriver.chrome.driver", chromedriverPath);
        ChromeOptions options = new ChromeOptions();

        // loading Chrome with my existing profile instead of a temporary profile
        options.addArguments("user-data-dir=" + chromeProfilePath);

        driver = new ChromeDriver(options);
        driver.manage().window().maximize();
        return driver;
    }
    public static void shutdownChrome() {
        driver.close();
        driver.quit();
    }
}
pburgr
  • 1,722
  • 1
  • 11
  • 26
  • One note is that in headless mode you cannot install extensions, that's a ChromeDriver limitation: https://bugs.chromium.org/p/chromium/issues/detail?id=706008#c5 – Adi Ohana May 21 '19 at 14:00