Execute test cases in Firefox ,Chrome and Internet Explorer using Selenium Webdriver

Selenium has launched Selenium v3.8.1 with so many new changes.In this post I will show you how to use Firefox in Selenium using geckodriver which will run the test.

You can check the new changes in Selenium v3.8.1 version.

If you are using Selenium 3 then to work with Firefox browser you need to use separate a driver which will interact with Firefox browser. If you have noticed then we have done the same thing for Chrome and IE browser as well.

One important thing in this post is even if you are using Firefox beta version then it will work. If you are using firefox 57 and so on then it will work.

We have used below system property for Chrome and IE

webdriver.chrome.driver for Chrome browser

webdriver.ie.driver for IE browser

Now we have to use webdriver.gecko.driver for Firefox as well

If you are still using Selenium 2 like 2.53 and 2.51 or any version then you don’t have to set this path.

Let’s run a basic program with Selenium v3.8.1 version

package com.blog.qaearth.acc;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Basic {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("https://qaearth.blogspot.in/p/testing-examples.html");
driver.quit();
}
}

Output console

The path to the driver executable must be set by the webdriver.gecko.driver system property;



Firefox in Selenium using geckodriver


As you can see to work with Firefox we have to set the property now. You can download the latest driver from Github and then you can extract and you will get .exe file.

Download URLhttps://github.com/mozilla/geckodriver/releases



Program for Firefox in Selenium using geckodriver

package com.blog.qaearth.acc;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Basic {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","D:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://qaearth.blogspot.in/p/testing-examples.html");
driver.quit();
}
}

In similar way we can execute scripts in IE and chrome browsers

Sample Code to launch Chrome Browser:

Download latest Chrome Driver from http://chromedriver.storage.googleapis.com/index.html 
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
Sample Code to launch IE Browser:

Download latest IEDriver Server from - http://selenium-release.storage.googleapis.com/index.html
System.setProperty("webdriver.ie.driver", "D:\\IEDriverServer.exe");
InternetExplorerDriver driver = new InternetExplorerDriver();

Now you can run the program and you will get expected output.