2

I am coming from Ruby background, I know how to do this in Ruby Selenium Binding, but I don't know how to do it Java Selenium Binding,

I have this code to create Firefox profile

 FirefoxProfile firefoxProfile = new FirefoxProfile(pathToProfile);
 WebDriver driver=new FirefoxDriver(firefoxProfile);

It works in selenium 2.53 but it's throws error in very recent selenium binding 3.11.0, Can anyone tell me what's the alternative?

And also I wanted to switch off the marionette to connect to Legacy Firefox driver, I can do this with the following code

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", false);
WebDriver driver=new FirefoxDriver(capabilities);

But if I use the above line, then it gives the FirefoxDriver is deprecated. Can anyone guide me how to create profile as well as how to switch off the marionette?

2
  • Let me know if you are open to consider other answers. May 4, 2018 at 10:03
  • @DebanjanB Sure, Please go on! May 4, 2018 at 10:03

2 Answers 2

6

Yes FirefoxDriver(desiredCapabilities) is deprecated.

Alternate way would be to go with options:

FirefoxOptions foptions =  new FirefoxOptions(capabilities);
WebDriver driver=new FirefoxDriver(foptions);  

Update : [In order]

FirefoxOptions foptions =  new FirefoxOptions();
FirefoxProfile firefoxProfile = new FirefoxProfile(pathToProfile);
foptions.setProfile(firefoxProfile);
foptions.setCapability("marionette", false);
foptions.setBinary("C:\\Program Files\\Mozilla Firefox 52\\firefox.exe"); 
WebDriver driver = new FirefoxDriver(foptions);
12
  • how to pass the profile argument now? first question. May 4, 2018 at 9:37
  • how to combine both? Need to pass the Firefox profile and foptions(your example variable)? May 4, 2018 at 9:39
  • with options you and set the capabilities too ! May 4, 2018 at 9:43
  • Can you please order the lines? May 4, 2018 at 9:45
  • in which order you want ? May 4, 2018 at 9:46
1

To use an existing Firefox Profile for your Test Execution first you have to create a Firefox Profile manually following the instructions at Creating a new Firefox profile on Windows. Now you have to pass the Firefox Profile to a FirefoxOptions class object. Additionally as you would be using the Legacy Firefox Browser you have to set marionatte to false through a DesiredCapabilities class object which you need to merge() into the FirefoxOptions class object as follows :

System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("debanjan");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(testprofile);
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("marionatte", false);
options.merge(dc);
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com");

Update

I am not sure about your usecase and why you want to use Legacy Firefox Driver. But as per the GitHub discussion Unable to Start Firefox Using the Legacy Driver on a 3.5.3 Grid @jimevans clearly mentions :

The legacy Firefox driver won't work with Firefox 53 or so. You might get the browser to launch, but the language bindings will be entirely unable to communicate with the driver (because Firefox will refuse to load the browser extension that is the legacy Firefox driver).

@barancev also mentions :

A binding should not pass OSS capabilities in W3C-compliant parts of payload, in "capabilities" block. They are allowed in "desiredCapabilities" block only. Perhaps, Mozilla broke Selenium compatibility in Firefox 48 in release channel, but restored it in version 52 in esr channel. It was unexpected, but it's true.

It's all upto you to take a informed descission.

9
  • First line is not necessary,right? because we are using Legacy driver? May 4, 2018 at 10:06
  • But If have to use Legacy driver, then first line is not necessary, eh? May 4, 2018 at 10:08
  • @Rajagopalan Legacy Driver will not require the first line but in absence of GeckoDriver I am not sure if Legacy Driver will be compatible with Selenium 3.11.0 and functions e.g. merge(). Update me the status please. May 4, 2018 at 10:17
  • I have been using WATIR which is using recent Ruby Selenium Binding, it works fine for me. May 4, 2018 at 10:37
  • @Rajagopalan Won't comment on watirimplementation. I have added an update with the comments from Selenium Committers of the Selenium Factory. Keep me updated about the status. May 4, 2018 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.