Though I am not able to find a good use case
when we'll need an extension while running our automation Se scripts but in case, you need an extension while running your SE scripts, here's how you can do
it:
Step 1) Download Your Chrome Extension. To do
this, get your webstore URL from the Google Web Store like
"https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en"
Step 2) Then go to http://crxextractor.com/ and
enter the Chrome web store URL that you get from Step 1 in the URL field to
download the .crx file of the required extension.
Step 3) Once you have the .crx file of that
extension, it's time to save it somewhere so that you can use it in your SE
script.
Step 4) Use addExtensions method of
ChromeOptions class in your SE script.
Sample code:
public class WithExt {
static WebDriver driver;
@Test
public static void chromeWithExtensions()
throws InterruptedException {
ChromeOptions options = new
ChromeOptions();
System.setProperty("webdriver.chrome.driver",
"/Users/dheerajgambhir/Library/AutomationSetUp/chromedriver");
options.addExtensions(new
File("/Users/dheerajgambhir/Downloads/extension.crx"));
driver = new ChromeDriver(options);
driver.get("https://testersdigest.blogspot.com");
driver.quit();
}
}
Comments
Post a Comment