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

Download-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 .
  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.
Install-Java-Location
  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.
Set-Up-Java-Environment-Path
Set-Up-Java-Environment-Path

2. Installing the Eclipse

Download eclipse by the link http://www.eclipse.org/downloads/

Eclipse_Installation_1

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 

http://selenium-release.storage.googleapis.com/index.html

Select the version and click to install the selenium

  1. Download the driver for the internet explorer or any other browser
  2. Then download the third –party plugins, drivers bindings 
  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
  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.

b. after completion Run and validate the test script.

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
Close
Close