How to install and setup Selenium 3 ?

How to install and setup Selenium 3

In this article, you are going to learn how to install and setup selenium 3. This is a step-by-step guide for installing & setting up selenium. You will learn to write a simple automation test script in selenium. As Selenium v3 is released, you can start using it instead of selenium 2.

If you would like to learn about Selenium 3.0, you can read the following post:

What’s new in Selenium 3¬

Assumption: For this article, I am assuming that you have already installed Eclipse, this article is applicable for Eclipse only.

Steps to install and setup Selenium 3

Here are the steps to install and setup selenium 3:

  1. Download and install Eclipse latest version from Eclipse website.
  2. Install Java from Oracle website
  3. Verify Java installation
  4. Download and install Selenium 3 from official website.
  5. Download Gecko driver for Mozilla Firefox
  6. Configure Selenium 3 in Eclipse

You need to download drivers for other browsers as well. I will explain the same in next few posts. I will explain the installation and setup process in a step-by-step manner.

Step1 : Installing Eclipse

We are assuming that you have already installed Eclipse. If you have not, visit Eclipse website to download and install it. Make sure that you download the 32-bit or 64-bit version based on your machine

Step 2: Install Java

Java environment is needed to use with Selenium 3. The latest Eclipse installers check your machine for Java environment. It will redirect you to the Java download website. However, I am providing the URL for your reference:

Oracle Java download website

Downloading Java for Selenium

Here again, do check the version of Java relevant to your machine. If your machine is 64-bit Windows, download the windows x64 installer (last row).

Step 3: Verify Java installation

Once Java is installed, you can quickly verify it by opening the command prompt and typing “Java -version” as shown below:

 

Checking Java Version

Step 4: Download and install Selenium 3

The next step is to download Selenium 3. There is no installation involved but just extracting the files and configuring it. Selenium 3 can be downloaded from the Selenium official website. On the download page, go to the “Selenium Client & WebDriver Language Bindings” section and download the Java version as shown below. In case you are going to use another language for selenium, you can use that.

downloading-selenium-3

It will download a zip file namely “Selenium-java-…..zip”. The “…..” will indicate the version number. Extract the files to a suitable folder and name it properly. You will need it later.

Step 5: Download Geckodriver for Firefox

In this article, we are going to use Firefox, hence we are downloading Geckodriver. Every browser will need the specific driver. You can find the drivers for each of the browsers on the same download page mentioned above. Just scroll down to the “Third party drivers…” section as shown below:

download-gecko-driver

 

 

It’s a zip file and contains an .EXE file. It’s not an installer, just extract it to the same folder where you have kept selenium client files (you can keep it in any folder).

Step 6: Configure Selenium 3 in Eclipse

The last step is to configure Selenium 3 in Eclipse. There are multiple steps involved. Each step is described below.

Step A: Select File -> New -> Java project and it will open the following dialog box.¬

create-new-project-in-eclipse

Step B: Verify Java version

Let’s give the Java project a name “Selenium3Project”.¬†On the same dialog box, you can see the JRE version (see above image). By default, it should be the same JRE, you installed in Step 2. The next step is to configure Selenium 3.

Step C: Configure Selenium 3

After naming the Java project in Step A, click on next and you will see a new dialog box. In this dialog box, click on libraries TAB as shown below:

adding-selenium-jars

 

You can add selenium jars by clicking on the “Add External jars..” as shown above. Add all the jars from the folder, you have extracted the selenium-java-….zip file. Please make sure that you add the jar files in the “Lib” folders also including one jar file in the main folder namely “client-combined-3.0.1-nodeps.jar”.

This will complete all the steps involved in configuring and installing Eclipse.

Running an automation script

Let’s take a simple automation script to check the title of Yahoo.com to validate our installation and configuration. The complete code is below.

package basicSeleniumScripts;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class TitleCheck {

public static void main(String[] args) {

String Firefoxdriverpath = “E:\\Selenium 3\\geckodriver.exe”;
WebDriver driver;

System.setProperty(“webdriver.gecko.driver”, Firefoxdriverpath);

// create a new instance of the Firefox driver
driver = new FirefoxDriver();

// Open the page we want to open
driver.get(“http://www.yahoo.com”);

//Defining Expected Title
String expectedTitle = “Yahoo”;
//Getting the actual Title
String actualTitle = null;
actualTitle=driver.getTitle();

//Validating the test case
if (actualTitle.contentEquals(expectedTitle))
{
System.out.println(“Test Passed!”);
}
else
{
System.out.println(“Test Failed”);
}

driver.close();

driver.quit();

}

}

Please note the line in the code above:

String Firefoxdriverpath = “E:\\Selenium 3\\geckodriver.exe”;
WebDriver driver;

This is the path where you had extracted the Geckodriver. Run this script by clicking on run. It should do the following:

  • Open Firefox browser
  • Navigate to “www.yahoo.com”
  • Show a message “Test Passed!” in the Eclipse output window
  • Close the driver and browser.

In the next post, I am going to describe working with Chrome and other browsers.

About Techcanvass

Techcanvass is a software training organization offering hands-on and certification courses in Automation testing, business analysis and analytics. We offer following two courses in Selenium as shown below:

Selenium Training Course

Selenium Certification Course

Leave a Reply

Your email address will not be published. Required fields are marked *