I'm using the code below to start chrome using webdriver (selenium 2)
Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", "BlackBerry PlayBook");
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
driver = new ChromeDriver(capabilities);
How can I also load a Chrome extension while also keeping the options above?
Use below code:-
Hope it will help you :)
Finally figured it out!
Per the ChromeDriver capabilites page, you need to convert the .crx file into a base-64 encoded string. So the final answer will look something like this:
Where
Data.base64encoder()
is my custom method for encoding. There are plenty of examples of how to do that based on the version of Java you're running. Basically send it the location, have it read in the binary, and return a string.