We can also run the Firefox web browser with addons/extensions using capabilities to perform automation testing.
Here is the very basic program to run Firefox web browser with addons/extensions using capabilities.
Detailed explanation for the above program is as follows:
Following code is the required packages for Java File.
Following code is the required packages for Selenium Webdriver.
Following code is the required packages for Firefox browser and Selenium remote capabilities.
Following code is to initialize the webdriver.
Following code is to define Firefox profile.
Following code is to define filepath of firefox addon/extension.
Following code is to add extension into defined Firefox profile.
Following code is to define Firefox capability.
Following code is to set Firefox capability.
Following code is to initialize the firefox driver.
Following code is to open the hello selenium blog in firefox browser.
You can also use the following code is to open the hello selenium blog in browser.
Following code is to quit the driver instance.
You can also use the following code is to close the driver instance.
Here is the very basic program to run Firefox web browser with addons/extensions using capabilities.
Java Source code:
package com.helloselenium.selenium.test; import java.io.File; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.remote.DesiredCapabilities; public class RunFirefoxWithAddons{ public static void main(String[] args) { WebDriver driver = null; FirefoxProfile firefoxProfile = new FirefoxProfile(); File addonpath = new File("path of addon/extension (.xpi file)"); firefoxProfile.addExtension(addonpath); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(FirefoxDriver.PROFILE, profile); driver = new FirefoxDriver(capabilities); driver.get("http://www.helloselenium.com"); driver.quit(); } }
Detailed explanation for the above program is as follows:
Following code is the required packages for Java File.
import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.remote.DesiredCapabilities;
WebDriver driver = null;
FirefoxProfile firefoxProfile = new FirefoxProfile();
File addonpath = new File("path of addon/extension (.xpi file)");
firefoxProfile.addExtension(addonpath);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
driver = new FirefoxDriver(capabilities);
driver.get("http://www.helloselenium.com");
driver.navigate().to("http://www.helloselenium.com");
driver.quit();
driver.close();
0 Comments
What would you like to add in my list? I look forward to reading your comments below.