Use of Selenium 3.0 with Firefox V<47 - selenium

Selenium3 supports executable geckodriver to launch Mozilla Firefox just like other drivers; but executable geckodriver is not compatible with Mozilla Firefox < v47.
So How can we achieve backward compatibility with browsers V<47 i,e how can we use firefox browsers V<47 with Selenium3.

Disable the geckodriver capabilities so that FirefoxDriver can be used.
System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe");
DesiredCapabilities d = new DesiredCapabilities();
d.setCapability("marionette", false); // to disable marionette, by default true
WebDriver driver = new FirefoxDriver(d);
Little Background to geckodriver.exe and Firefox version support:
From geckodriver github page:
Firefox 47 is explicitly not supported
So, If you want to use <= Firefox 47 version, use Firefox driver but not geckodriver.
In case of selenium 2.53, you don't need to do any additional things (no need to setup geckodriver as selenium 2.53 uses Firefox driver by default).
In Selenium 3.0, we must set geckodriver path (as geckodriver is the default driver for Firefox in Selenium 3.0) using System.setProperty and set marionette to false, so geckodriver capabilities will be disabled and default Firefox driver is used.
References:
https://github.com/mozilla/geckodriver#supported-firefoxen
https://github.com/mozilla/geckodriver/issues/224
https://stackoverflow.com/a/40658421/2575259

You should use old FirefoxDriver, just make sure to set marionette on false if you are using RemoteDriver because I'm not sure is it enabled by default (caps.setCapability(FirefoxDriver.MARIONETTE, false);)
This driver doesn't need any .exe file, just import org.openqa.selenium.firefox.FirefoxDriver; in your code so you could use it.
driver = new FirefoxDriver();
or if you are using grid:
driver = RemoteWebDriver(url, DesiredCapabilities.firefox());

Related

which firefox version is compatible with selenium 3.5.0?

I tried with Selenium 3.5.3 GeckoDriver 0.19 Firefox 55 but getting below exception:
Error: org.openqa.selenium.WebDriverException: browser name not boolean
Code :
DesiredCapabilities cap = DesiredCapabilities.firefox();
WebDriver driver = null;
System.setProperty("webdriver.gecko.driver", "<path to gecko>\geckodriver.exe");
cap.setBrowserName("firefox");
URL sURL= null;
cap.setCapability("firefox_binary", "<FIREFOX_PATH>"));
//Grid
sURL = new URL("http://localhost:5555/wd/hub");
driver = new RemoteWebDriver(sURL, cap);
Also saw this thread https://seleniumhq.wordpress.com/2017/08/09/firefox-55-and-selenium-ide/ that selenium ide would not be supported anymore in Firefox 55. Whether selenium jar would be still supported?
It was a bad news for the tester community since Selenium IDE no long works from Firefox 55 onwards. Now you have 2 choices:
1- Try with previous version of firefox (Temporary solution)
2- Use Selenium IDE alternatives (Highly Recommended)
I recommend you to use Firefox 54.0 and geckodriver v0.18.0.
Actually this links regarding Selenium IDE. You can use firefox 55 also.

Which Selenium JAR is compatible with Mozilla Firefox version 52 or, latest version

Previously I was using Selenium version 2.53 with Firefox version 46.1. But now Firefox is updated and I am trying to do with updated version.
So, respond me about "which Selenium JAR is compatible with Mozilla Firefox version 52 or, latest version"
To work with Selenium 3.4.0 along with latest gecko driver v0.16.0 & Mozila Firefox 53.0, you need to download the gecko driver from here and save it. Mention the absolute location of gecko driver in your code as follows:
public void sampleMethod()
{
System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");
WebDriver driver= new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://your_url.com");
}
No need to Update the selenium jars since your existing tests may not work properly with new selenium jars. Use the gecko driver to interact with firefox.
Add the path to gecko executable before initiating the Webdriver.
System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");

Difference between webdriver.firefox.marionette & webdriver.gecko.driver

I am now learning Selenium and have met a problem.
I am aware that Selenium supported old Firefox version by default without a driver. And for recent versions of Firefox, we have to download the driver and define it using System.setProperty.
According to this link, for Firefox 45 and 46, start driver code could look like this:
WebDriver driver = new FirefoxDriver();
My Firefox is version 45.5.1., but above code still won't work. So according to this link, I have added:
System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");
And it worked.
Then I realized that I haven't installed geckodriver.exe on my computer. To see how it goes, I have changed to the code below:
System.setProperty("webdriver.firefox.marionette","");
It still works.
So, here comes my first problem: What happened? I am sure that no geckodriver.exe exists in my environment. If no location has been pointed, then why should I have to set property?
Also, I have seen code like:
System.setProperty("webdriver.gecko.driver", "/tools/marionette/wires.exe");
My second question is that what is the difference between webdriver.gecko.driver and webdriver.firefox.marionette or wires.exeand geckodriver.exe?
Up to version 45 (pushed to version 47), the driver used to automate Firefox was an extension included with each client. But this extension was dropped, probably due to the change of policy which now requires all the extensions to be signed by Mozilla.
Marionette is the new driver that is shipped/included with Firefox.
This driver has it's own protocol which is not directly compatible with the Selenium/WebDriver protocol.
The Gecko driver (previously named wires) is an application server implementing the Selenium/WebDriver protocol.
It translates the Selenium commands and forwards them to the Marionette driver.
For the Java client, the default behavior is to use the Gecko driver, but it can be overridden to use the legacy extension as a driver with the webdriver.firefox.marionette property:
System.setProperty("webdriver.firefox.marionette", "false");
or with the marionette capability through FirefoxOptions :
FirefoxOptions options = new FirefoxOptions()
.setLegacy(true);
WebDriver driver = new FirefoxDriver(options);
// or with a remote server
WebDriver driver = new RemoteWebDriver(remoteUrl, options.toDesiredCapabilities());
or directly with the DesiredCapabilities:
DesiredCapabilities capa = DesiredCapabilities.firefox();
capa.setCapability("marionette", false);
WebDriver driver = new FirefoxDriver(capa);
// or with a remote server
WebDriver driver = new RemoteWebDriver(remoteUrl, capa);
And to define the location of the Gecko driver, either place the driver in a folder present in the PATH environment variable, or define the location in the property webdriver.gecko.driver:
System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");
or launch a remote server with the property assigned in the command line:
java -Dwebdriver.gecko.driver="C:\\geckodriver.exe" -jar selenium-server-standalone-3.4.0.jar
Till Firefox 47.x releases the legacy driver was implemented as a Firefox extension. This extension was installed in the profile used by the driver whenever WebDriver launched Firefox.
Hence we we used:
WebDriver driver = new FirefoxDriver();
driver.navigate().to("https://gmail.com");
Firefox 48 disabled the browser extension and introduced WebDriver. Since then GeckoDriver the Marionette-based solution, being developed and maintained by Mozilla is for use automating Mozilla Firefox Browser.
Marionette
According to Mozilla's Official Documentation on developer.mozilla.org. Marionette is the Automation Driver. It uses the remote protocol of Firefox which can control the UI. Marionette accepts requests and executes them in Gecko. It also have a client. The client sends instructions to the server and the server executes the instructions within the browser.
Hence we started using Marionette:
System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.navigate().to("https://gmail.com");
Wires
There are some references to rename the executable file to ‘wires.exe’ and add it to your path. Hence the following was used:
System.setProperty("webdriver.firefox.marionette","C:\\wires.exe");
WebDriver driver = new FirefoxDriver();
driver.navigate().to("https://gmail.com");
GeckoDriver
GeckoDriver is the executable file that we need to download within our system and mention its location in our scripts/programs while executing our testcases. GeckoDriver in turn will start the Mozilla Firefox Browser.
These excerpts have been taken out of Jim Evan's epic answer to the question What are the benefits of using Marionette FirefoxDriver instead of the old Selenium FirefoxDriver for a Selenium tester? which provides us a detailed understanding of how GeckoDriver and Marionette came into practice.
Hence we started using geckodriver.exe:
System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.navigate().to("https://gmail.com");
Now in current scenario you still have the option to execute your Automation through legacy Firefox 47.x browser and recent Firefox 53.x browser releases as well.
Usecase 1:
In case of using the legacy Firefox 47.x browsers you have to explicitly set "marionette" to false through DesiredCapabilities class as follows:
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability("firefox_binary", "C:\\Program Files\\Mozilla Firefox47\\firefox.exe");
dc.setCapability("marionette", false);
WebDriver driver = new FirefoxDriver(dc);
driver.navigate().to("https://gmail.com");
Usecase 2:
In case of using the legacy Firefox 47.x browsers, if you skip setting "marionette" to false or if you set "marionette" to true, you will observe a IllegalStateException
Usecase 3:
In case of using the Firefox 53.x browsers you can choose to skip setting "marionette" to true as follows which will show the Marionette INFO logs e.g. Marionette INFO Listening on port 11105 :
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.navigate().to("https://gmail.com");
Usecase 4:
In case of using the Firefox 53.x browsers you can explicitly set "marionette" to true through DesiredCapabilities class which will show the Marionette WARN logs as well e.g. WARN TLS certificate errors will be ignored for this session
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(dc);
driver.navigate().to("https://gmail.com");
Usecase 5:
In case of using the Firefox 53.x browsers if you forcefully set "marionette" to false through DesiredCapabilities class you will observe a UnreachableBrowserException.
Marionette is the new driver that is shipped/included with the latest Firefox versions.
However, Geckodriver is a Proxy for using W3C WebDriver-compatible clients to interact with Gecko-based browsers. Geckodriver provides HTTP API described by the WebDriver protocol to communicate with Gecko browsers, such as Firefox version above 47.
System.setProperty("webdriver.gecko.driver","path of/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
If still you are getting issues (due to incompatibility of FF versions) you can use the following capabilities:
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);

How to check Firefox version when running Selenium tests in Jenkins?

Selenium plug has integrated Firefox. I would like to know how to check version of Firefox.
It's very easy. You should use the browser capatibilities. But it's not a plugin.
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
WebDriver driver = new FirefoxDriver();
Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();
String browserName = caps.getBrowserName();
String browserVersion = caps.getVersion();
System.out.println(browserName+" "+browserVersion);
From Firefox version 48 and forward, geckodriver capabilites are in place. With selenium you can get the Firefox version number using "browserVersion", like in this Python example:
driver.capabilities['browserVersion']

How to test multiple version of google chrome using chromedriver?

selenium web-driver with java then how to use chrome driver for test their lower version of Google chrome
From the official wiki page:
Overriding the Chrome binary location
You can specify the location of the Chrome binary by passing the "chrome.binary" capability, e.g. with a typical Chromium install on Debian:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.binary", "/usr/lib/chromium-browser/chromium-browser");
WebDriver driver = new ChromeDriver(capabilities);
I suggest you try this approach - tell where the binary of lower version is and start ChromeDriver. Never tried it, but I think it might work
You would use capabilities to point to the right binary file of the browser to be launced.But not all versions of chrome browser is supported by different versions of chromedriver. You will find exceptions stating that version of browser expected is greater or equal to 30.0.
For ex:- Chromium Browser(33.0.1729.0 )works fine with ChromeDriver 2.7 and not the with the older ones.
You can choose from all the chromedriver version available from the link below:-
http://chromedriver.storage.googleapis.com/index.html
Install chrome to custom location, be sure to turn off auto-update. Use following code to use non-default binary.
ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/binary");
DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver webDriver = new ChromeDriver(desiredCapabilities);