Migrating from Firefox WebDriver to Marionette - selenium

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);

Related

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)}

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/");

Selenium Webdriver 3.0.1 not loading Firefox Profile I chose

I read everywhere that this is the code used to load an existing profile:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver driver = new FirefoxDriver(ffprofile);
I have created one profile with that name and everything is ok. But it keeps loading the default selenium profile.
I'm using Selenium 3.0.1 with Java and Firefox 50.0.2 which is the last version in my country at least.
Any idea of why this is happening? thanks!
You should put profile to capabilities at first.
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver driver = new FirefoxDriver(ffprofile);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
WebDriver driver = new FirefoxDriver(capabilities);

I am writing a Selenium script in Firefox but I am getting "Untrusted Certificate"

written a code like this
FirefoxProfile profile=new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
WebDriver driver=new FirefoxDriver();
driver.get("url");
Not working in firefox how to resolve this one.
You're not creating the driver with the profile - you're creating it with an empty constructor. Try WebDriver driver=new FirefoxDriver(profile);
You can use Selenium WebDriverJS
var WebDriver = require('selenium-webdriver');
var driver = new WebDriver.Builder().withCapabilities(
WebDriver.Capabilities.firefox()
).build();
driver.get('url');

getting error with chromedriver using RemoteWebdriver

Getting error:
FAILED CONFIGURATION: #BeforeMethod setUp
org.openqa.selenium.WebDriverException: The path to the driver
executable must be set by the webdriver.chrome.driver system property;
for more information, see
http://code.google.com/p/selenium/wiki/ChromeDriver. The latest
version can be downloaded from
http://chromedriver.storage.googleapis.com/index.html
My code :
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
String strChromePath = System.getProperty("user.dir")
+ "\\webdrivers\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", strChromePath);
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
capability);
On the above code chromedriver it self is not getting invoked.
Then i tried with code:
ChromeDriverService chromeService = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("webdrivers/chromedriver.exe"))
.usingAnyFreePort().build();
chromeService.start();
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
capability);
On executing above code the executable is launched but chrome is not invoked. It throws the same error. Code is working fine for firefox. Any help please?
Download the relevant Chrome driver as per your system(32-bit/64-bit), from here . Try setting the property of ChromeDriver first, like this:
File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
Then use this code:-
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),capability);
If there is no need of using "RemoteWebDriver", you can code just use this below :
File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driver = new ChromeDriver();
Try below :
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "properties/chromedriver.exe");
driver = new ChromeDriver();
driver.get("www.google.com");
Put chrome driver in properties folder.