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:
- Java, which is a programming language to write the test scripts
- Eclipse, which is an environment that compiles and runs the java test scripts.
- Selenium client and web driver language bindings, is a framework for testing web applications.
- Configuring Selenium webdriver with Java
- 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.
- Right click on the My computer .
- Go To properties, the system window opens, then click on Advanced system settings.
- Then system properties window pops up. Click on the Environment variables under the Advanced tab.
- Click on the environment variables. Click on New under user variables.
- 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 http://www.eclipse.org/downloads/
Install the Eclipse by clicking the set up file on your system.
- Installing the Selenium Web Driver
- Install the JAR files for selenium by the link
Select the version and click to install the selenium
- Download the driver for the internet explorer or any other browser
- Then download the third –party plugins, drivers bindings
- Downloaded Jar files are stored in your system in the for of zip folders. Extract all files in your system.
- Configure the eclipse once all the JAR files of selenium have been added to the system folders.
- Create a Java project in Eclipse
- Open eclipse window
- Right click and click New. A Projectname window is opened.
- Provide the projectname as selenium and click on Finish.
- Create a package under this project by right clicking ‘src’ folder
- Create the class after the package is created.
- Once the class is created, add the selenium jars to the project.
- To add selenium jars, right click on the project folder and goto properties.
- From properties window select ‘Java Build path’ and click on add external JAR’s.
- 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.