Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
787 views
by The go-to Tester (391 points)
How may I test a browser extension with Selenium WebDriver?
by The go-to Tester (181 points)
which browser extension do you want to test?
by The go-to Tester (181 points)
Also specify the name of the browser. Chrome or Firefox?
by The go-to Tester (391 points)
It is an extension that is being built for internal use. It will support Chrome, Firefox and Opera.

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
edited by
Chrome:
 
1. Install Your Chrome Extension 
2. Download the Chrome Extension Source Viewer from the Google Web Store. - Using this you can see the source of CRX file.
3. Now you can identify the page you want to test.
4. Use below code to initiate the chrome browser with extension
 
ChromeOptions options = new ChromeOptions ();
File[] files = new File[1];
files[0] = new File("/path/to/extension.crx");
options.addExtensions(files);
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
 
5. Now you can navigate to extension page
driver.get('chrome-extension://UNIQUEID/SPECIFICPAGE.html')
 
Opera:
 
This API is similar to the FirefoxDriver.
 
File file = new File("extension.oex"); // Must end with ".oex"
OperaProfile operaProfile = new OperaProfile();
operaProfile.addExtension(file);
 
// Option 1: Locally
WebDriver driver = new OperaDriver(operaProfile);
 
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.profile", operaProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
 
 
Firefox
 
File file = new File("extension.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
 
// Option 1: Locally
WebDriver driver = new FirefoxDriver(firefoxProfile);
 
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
 
 
Hope that helps!


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...