Am trying to use GeckoDriver
for firefox in selenium-java 3.11
. The firefox version is 59
. Things are working fine and am able to invoke the firefox driver. The only challenge is I need to add DesiredCapabilities
to my firefox instance.
The old method WebDriver driver = new FirefoxDriver(capabilities);
in latest selenium version seems to be deprecated and am not able to figure out the new way to specify the capabilities.
Here is the code:
public static WebDriver createDriver(String userAgentKey, String PROXY) {
File modifyHeaders = null;
try {
modifyHeaders =
ResourceUtils.getFile("classpath:modify_headers-0.7.1.1-fx.xpi"); //am adding the extension using DesiredCapabilities
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
Proxy proxy = new Proxy();
proxy.setHttpProxy(PROXY).setFtpProxy(PROXY).setSslProxy(PROXY);
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("javascript.enabled", true);
profile.setPreference("brower.link.open_newwindow", 1);
profile.setPreference("modifyheaders.config.active", true);
profile.setPreference("modifyheaders.config.alwaysOn", true);
profile.setPreference("modifyheaders.headers.count", 1);
profile.setPreference("modifyheaders.headers.action0", "Add");
profile.setPreference("modifyheaders.headers.name0", "Proxy-Authorization");
profile.setPreference("modifyheaders.headers.value0", "Basic dnNodWtsYUBleHBlZGlhLmNvbTpxZWxsYWZraw==");
profile.setPreference("modifyheaders.headers.enabled0", true);
profile.addExtension(modifyHeaders);
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability(FirefoxDriver.PROFILE, profile);
cap.setCapability(CapabilityType.PROXY, proxy);
System.setProperty("webdriver.gecko.driver","/Users/vshukla/Music/geckodriver");
WebDriver driver = new FirefoxDriver(cap); //this is deprecated
return driver;
How can I add the extension to instance using DesiredCapabilities? What are other options to achieve this?
Use firefox options :