All IT Courses 50% Off
Selenium Tutorials

5 Steps to set up and run a simple Java script in Selenium

Selenium is an automation testing tool. It is widely used because it is an open source and portable for software testing framework for web applications. Selenium supports multiple languages like JAVA, RUBY, PYTHON, C#.

Selenium with Java

The basic Java or core Java language is used to write the selenium script files. 

There are steps to set up and run a simple test with java through selenium.

The following components are needed to get started with the Selenium automation

  1. Java, which is a programming language to write the test scripts
  2. Eclipse, which is an environment that compiles and runs the java test scripts.
  3. Selenium client and web driver language bindings, is a framework for testing web applications.
  4. Configuring  Selenium webdriver with Java
  5. Creating and running first test.

1. Installation of Java


Java development kit which has JRE (Java Runtime Environment) is required to write and run Java scripts. JRE is a child of JDK. Download Java, install and set up the environment path. After the Java is installed, we need to set up the environment variables to use JDK with Eclipse.

  1. Right click on the My computer .
5 Steps to set up and run a simple Java script in Selenium
  1. Go To properties, the system window opens, then click on Advanced system settings.
  2. Then system properties window pops up. Click on the Environment variables under the Advanced tab.
  1. Click on the environment variables. Click on New under user variables.
  2. Under the Edit user variables window that pops up, set the variable name as path and variable value as the location of the Bin folder inside the JDK folder on your system. Create a new variable name JAVA_HOME and set the values as the location of the JDK folder.

2. Installing the Eclipse

Download eclipse by the link


Install the Eclipse by clicking the set up file on your system. 

  1. Installing the Selenium Web Driver
  2. Install the JAR files for selenium by the link

Select the version and click to install the selenium

5 Steps to set up and run a simple Java script in Selenium
5 Steps to set up and run a simple Java script in Selenium
  1. Download the driver for the internet explorer or any other browser
  2. Then download the third –party plugins, drivers bindings 
5 Steps to set up and run a simple Java script in Selenium
  1. Downloaded Jar files are stored in your system in the for of zip folders. Extract all files in your system.
  2. Configure the eclipse once all the JAR files of selenium have been added to the system folders.
  1. Create a Java project in Eclipse
  1. Open eclipse window 
  2. Right click and click New. A Projectname window is opened.
  3. Provide the projectname as selenium and click on Finish.
Description: Selenium Java Guide Step 5
5 Steps to set up and run a simple Java script in Selenium
  1. Create a  package under this project by right clicking ‘src’ folder
Java and Selenium Tutorial Step 6
  1. Create the class after the package is created.
Creating a new class under the package
  1. Once the class is created, add the selenium jars to the project.
  2. To add selenium jars, right click on the project folder and goto properties.
Navigating to Project Build Path in Eclipse
  1. From properties window select ‘Java Build path’ and click on add external JAR’s.
Java Build Path Configuration to include Selenium WebDriver Jars
  1. Add the downloaded selenium jars and click on apply. Write the test script and prepare to execute the test script.

5. Write an open program to open browser

a. After creating Package and class, write the program for example to open the Firefox browser.

5 Steps to set up and run a simple Java script in Selenium

b. after completion Run and validate the test script.

5 Steps to set up and run a simple Java script in Selenium

Keep a separate folder within the project to keep all jars. This is useful in better organisation. Selenium webdriver is not having built in report facility. Use the programming control flow statements or testing framework verification method which generates test results. Selenium overcomes the drawbacks of Selenium Remote Control which offers better support for dynamic pages where the elements on a page are changing without the support of page itself reloaded.Selenium uses each browser’s native support for automation.

Facebook Comments

Related Articles

Back to top button

Get Selenium Training Online
Course Now at 50%OFF!

Offer valid for 1st 20 seats only, Hurry up!!

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

H2kinfosys will use this information to be in touch with you for providing updates.