Selenium 3.6.0 & webdriver = new FirefoxDriver(capabilities) - deprecated? - selenium

Since upgrading to the latest version of Selenium the following code seems to be deprecated:
Selenium 3.6.0 & webdriver = new FirefoxDriver(capabilities) - deprecated?
Full code:
System.setProperty("webdriver.gecko.driver", Base_Page.getConstant(Constant.GECKO_DRIVER_DIRECTORY));
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
webdriver = new FirefoxDriver(capabilities); //deprecated

From https://raw.githubusercontent.com/SeleniumHQ/selenium/master/rb/CHANGES
3.4.1 (2017-06-13)
==================
Firefox:
* Added new Firefox::Options class that should be used to customize browser
behavior (command line arguments, profile, preferences, Firefox binary, etc.).
The instance of options class can be passed to driver initialization using
:options key. Old way of passing these customization directly to driver
initialization is deprecated.
From the 3.4.1 version the FirefoxOptions should be used.

Changed the following code 'FirefoxDriver(capabilities) to firefoxOptions which uses .setCapcability()
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setCapability("marionette", true);
webdriver = new FirefoxDriver(firefoxOptions);

Try following:
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(firefoxOptions);

You can try this line;
FirefoxOptions ffOpt = new FirefoxOptions();
ffOpt.setCapabilities("marionette", true);
WebDriver driver = new FirefoxDriver(ffOpt);

Related

How can i set the Property strictFileInteractability

geckodriver 0.24.0 introduces the capability strictFileInteractability see below,
but I haven't found a possibility to set this capability.
Code trials:
FirefoxProfile profile=new FirefoxProfile();
// Has no effect
profile.setPreference("strictFileInteractability", true);
...
FirefoxOptions options = new FirefoxOptions();
// Has no effect
options.setCapability("strictFileInteractability", true);
...
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
// Has no effect
capabilities.setCapability("strictFileInteractability", true);
Did someone manage to successfully set this capability?
Changelog:
github.com/mozilla/geckodriver/releases
w3c.github.io/webdriver/
GeckoDriver v0.24.0 introduced us to strictFileInteractability capability.
As per the Capabilities section within WebDriver W3C Living Document:
Capability Key Value Type Description
---------- --- ---------- -----------
Strict file interactability "strictFileInteractability" boolean Defines the current session’s strict file interactability.
As per the discussion Add support for 'strictFileInteractability' W3C capability strictFileInteractability capability was added from [java] Adding a type-safe option for strictFileInteractability capability pull request.
Example
Using Java, Option Class and Firefox:
Code Block:
System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
FirefoxOptions opt = new FirefoxOptions();
opt.setCapability("strictFileInteractability", true);
FirefoxDriver driver = new FirefoxDriver(opt);
driver.get("https://www.google.com/");
System.out.println(driver.getTitle());
driver.quit();
Console Output:
Google
Using Java, DesiredCapabilities Class and Firefox:
Code Block:
System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("strictFileInteractability", true);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
FirefoxDriver driver = new FirefoxDriver(opt);
driver.get("https://stackoverflow.com");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();
Console Output:
Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers

How to load a specific firefox profile using Selenium webdrivermanager?

I'm trying to use webdrivermanager library to load firefox driver in my selenium tests. I'm unable to load a specific firefox profile using this library. Here is what i'm trying to do:
FirefoxDriverManager.getInstance().setup() // To instantiate the firefox driver
ProfilesIni Prof = new ProfilesIni();
FirefoxProfile profile = Prof.getProfile("C:\\Users\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\6xv9ndwh.SELENIUM");
WebDriver driver = new FirefoxDriver(profile);
But this instantiates a new driver and does not force the driver instantiated by firefoxdrivermanager to use the specific profile.
I tried using default gecko driver too that does not load the profile either. Here is the code that i'm trying:
System.setProperty("webdriver.gecko.driver", "C:\\geckodriver\\geckodriver-v0.20.0-win64\\geckodriver.exe");
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile Profile = allProfiles.getProfile('default');
Profile.setAcceptUntrustedCertificates(true);
Profile.setAssumeUntrustedCertificateIssuer(false);
driver = new FirefoxDriver(Profile);
Can someone help me on this please?
First of all create a new firefox profile
steps for it are
1. Run this command firefox.exe -p in run window
It will show this dialog box create profile with new name and exit the window.
After that perform this command in webdriver
System.setProperty("webdriver.firefox.marionette", "Path to the exe of firefox driver");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("UrProfile Name which u created");
WebDriver driver = new FirefoxDriver(myprofile);
driver.get("http://www.google.com");
Hope it may help u...
This worked for me (though not using webdrivermanager) for instantiating webdriver using Gradle:
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
capabilities.setCapability("acceptInsecureCerts", true);
driver = {new FirefoxDriver(capabilities)}

Selenium - FirefoxDriver not accepting arguments in code

I am unable to use arguments for new FirefoxDriver as per code:
File pathBinary = new File("C:\\Users\\myname\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(firefoxBinary,firefoxProfile);
//WebDriver driver = new FirefoxDriver();
I get an error saying "remove arguments to match FirefoxProfile();
When I try using just new FirefoxDriver() I get:
org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN8_1
I am using:
geckodriver-v0.19.1-win32
selenium-server-standalone-3.7.1
Any help most appreciated.
You need to pass them in as Firefox options try the following
FirefoxProfile ffprofile = new FirefoxProfile();
FirefoxBinary ffBinary = new FirefoxBinary(new File("path to your firefox
executable"));
FirefoxOptions options = new FirefoxOptions();
options.setProfile(ffprofile);
options.setProfile(ffBinary);
options.setCapability(FirefoxOptions.FIREFOX_OPTIONS,options);
WebDriver driver = new FirefoxDriver(options);

How to handle untrusted certificate in firefox using Selenium Web Driver?

I'm facing some issues while handling "Untrusted Certificate" in firefox.
We can't use FirefoxDriver(new FirefoxProfile) as it is deprecated
I used the following code but couldn't achieve it.
FirefoxProfile profile=new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
FirefoxOptions options=new FirefoxOptions().setProfile(new FirefoxProfile());
WebDriver driver=new FirefoxDriver(options);
driver.get("Web Link");
Could anyone suggest me the solution to achieve in Selenium 3.
Try this in Firefox
DesiredCapabilities handlSSLErr = DesiredCapabilities.firefox ();
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new FirefoxDriver (handlSSLErr);
driver.get("Your URL link");
For chrome
DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome ();
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new ChromeDriver (handlSSLErr);
driver.get("Your URL link");
Below works fine for me
DesiredCapabilities cap = new DesiredCapabilities().merge(DesiredCapabilities.firefox());
cap.acceptInsecureCerts();
FirefoxDriver driverF = new FirefoxDriver(cap);
driverF.get("https://expired.badssl.com/");

Migrating from Firefox WebDriver to Marionette

I am trying to switch from FireFoxDriver to MarionetteDriver.
I managed to run firefox with MarionetteDriver by running:
public void runMarionnete(){
DesiredCapabilities dc = DesiredCapabilities.firefox();
OSUtils.setProperty("webdriver.firefox.bin", "C:\\Firefox\\firefox.exe");
OSUtils.setProperty("webdriver.gecko.driver","C:\\Drivers\\wires-0.6.2-win.exe"));
_driver = new MarionetteDriver(dc);
}
But I have 2 things I am not sure how to do:
1.How to add XPI extensions to the driver ?
in the old way I used:
FirefoxProfile.addExtension ...
2.How to configure all the firefox properties , like I used to do , for example:
profile.setPreference("browser.startup.homepage;about:home","about:blank");
profile.setPreference("startup.homepage_welcome_url","about:blank");
profile.setPreference("browser.usedOnWindows10.introURL","about:blank");
profile.setPreference("devtools.devedition.promo.url","");
profile.setPreference("xpinstall.signatures.required",false);
Thank you!
You can use the same FirefoxProfile class, just add it to the DesiredCapabilities in the following way:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.startup.homepage;about:home","about:blank");
firefoxProfile.setPreference("startup.homepage_welcome_url","about:blank");
firefoxProfile.setPreference("browser.usedOnWindows10.introURL","about:blank");
firefoxProfile.setPreference("devtools.devedition.promo.url","");
firefoxProfile.setPreference("xpinstall.signatures.required",false);
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);