Selenium Installation with java in Eclipse


Selenium Introduction

Selenium is a suite of tools to automate web app testing across many platforms. It is a GUI based automation tool. Initially it is built by Thought Works. It supports various browsers on various platforms

1.1 Selenium Projects

Selenium has many projects. Following projects are mostly used by testers.

1. Selenium IDE
2. Selenium Core
3. Selenium Remote Control
4. Selenium Grid

1.2 Selenium IDE (IDE)

Selenium IDE can be used only in FireFox. It is an add-on for FireFox. User can record the actions and can edit and debug the tests. It can be used to identify IDs, name and XPath of objects. Only one test at a time.

1.3 Selenium Core (CORE)

Selenium Core is the original Java script-based testing system. This technique should work with any JavaScript enabled browser. It is the engine of both, Selenium IDE and Selenium RC (driven mode), but it also can be deployed on the desired application server. It is used specifically for the acceptance testing. User can record the tests using Selenium IDE and can use the same tests to run in other browsers with minimal modifications. It provides support to run the tests in HTA (HTML Applications) Mode. This mode works only in IE.

1.4 Selenium Remote Control (RC)

Selenium Remote Control is a test tool that allows user to write automated web application UI tests in few programming languages against any HTTP website using any mainstream JavaScript-enabled browser. User can write the tests (More expressive programming language than the Selenese HTML table format) in Java, DotNet, Perl, Ruby and PHP. Also it supports few testing frameworks.

1.5 Selenium Grid

Selenium Grid allows easily to run multiple tests in parallel, on multiple machines, in an  heterogeneous environment by cutting down the time required for test execution. Using this, user can run multiple instances of Selenium Remote Control in parallel.

1.6 Selenium Supported Browsers

Selenium tools can run in following browsers.

* Internet Explorer
* FireFox
* Opera
 *Chrome
* Safari
* Seamonkey

1.7 Supported Operating Systems


Users can execute the selenium tests in following OS.

* Windows
* Linux
* Solaris
* OS X

1.8 Supported Programming languages

Below languages are supported by Selenium RC.

* C# (DotNet)
* Java
* Perl
* Ruby
* Python
* PHP

1.9 Step by Step Selenium Webdriver and Selenium RC installation in Eclipse

1.9.1 Download Eclipse - Selenium

This section will explain how to set up selenium in Eclipse.

1.Click Eclipse URL :  http://www.eclipse.org/downloads
2. Download Eclipse IDE for Java EE Developers 32 to 64 bit
3. Click on Arrow
4.Save the zip file in folder
5.Extract the file
6.Click on eclipse blue/purple color icon
7. Browse workspace location
8. For Uninstalling Eclipse: Help --Click Install new software--Click Already Installed link--Select Name--Click Uninstall

1.9.2 Download JDK and JRE for Selenium


1.Download JDK and JRE from www. java.sun.com
URL: http://www.oracle.com/technetwork/indexes/downloads/index.html
2. Save the files
3. Open eclipse

1.9.3 Download Selenium Client

1.Download Selenium Client and Webdriver from http://docs.seleniumhq.org/download/
2. Select Java Download (Please visit the website and check the laterst versions after two or three months. Update the version to avoid problems in runtime).
3.Save the files and extract the zip file

1.9.4 Create Java Project in Selenium

1. File--NewProject--Select Java Project--Click Next
2. Give Project name (JavaDemoProject)
3. Click Configure JREs in that screen. You will get a new window.
4. Click Add--Standard VM--next.
JRE Home--we need to specify path.C:\Program Files\Java\jre7
5.Use an execution environment JRE--JavaSE-1.7
6.Click Finish
7.You can see the new project in eclipse window with all jar files.

1.9.5 Configure Build Path in Selenium

1.Now Right click on JRE System Library[Java SE-1.7]
2.Select Build Path--Configure Build Path.
3.A new window will be opened. Select Libraries tab and click Add External Jars Button.
4.Select Selenium Client selenium-java-2.31.0 jar files (Select entire lib and two outside jar files).

Note:  Selenium Server JAR file should not be added in External jars.Only Selenium Client should be added in External jars.

5.You can see all Jar files under Libraries Tab
6.Click Ok
7.You can see the Referenced Libraries

1.9.6 Create Java Class

1.Right click on Project
2.Create Package and enter name
3.Right click package -- Create new Java Class
4.Enter class name
5.Select (String[] args) checkbox
6.Click Finish

Selenium driver Installation is done.Now write program and run


1.9.7 Run Program


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

 public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
}

(or)

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

System.setProperty("webdriver.gecko.driver", "C:\\Users\\prasanthi.podila\\Downloads\\geckodriver-v0.20.1-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
//System.setProperty("webdriver.chrome.driver","C:\\Users\\prasanthi.podila\\Downloads\\chromedriver_win32\\chromedriver.exe");
//WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
driver.get("https://qa.reventics.com/REVCDIUTROP/");
Thread.sleep(5000);
driver.quit();

Click Run menu --Click Run icon .Observe firefox browser opens automatically.Webdriver program works fine.



1.9.8 Working with Selenium RC

1. Download Selenium Server from http://docs.seleniumhq.org/download/
2.Save the file "selenium-server-standalone-2.31.0 "
3.Save file in Desktop in SeleniumSever folder
4.Open Notepad and type two lines in notepad.
cd C:\Users\Prasanthi\Desktop\SeleniumServer
java -jar selenium-server-standalone-2.31.0.jar -singleWindow
5.Enter without spelling mistakes and same spaces. Save files as .bat(dot bat format) in SeleniumServer folder.
6.Run .bat file,server should run,if not check the spelling mistakes.

Note: Never add Selenium Server file in Build path external jars under Libraries tab


Or You can create Server directly in Eclipse

1.Go to RUN Menu--External Tools--External tools configuration
2. Click Program
3. You will get new configuration window.
4. Give name selenium server (any name you can give).
5. Location ---click on Browse file systems.C:\Program Files\Java\jdk1.7.0\bin\java.exe  F:\Selenium_Scripts1\jdk1.5.0_11\bin\java.exe
6. Working Directory--- Browse file system --- F:\ Selenium_Scripts1\lib.
7. Arguments  -jar selenium-server.jar
8. Click Apply and Run

Your selenium server will run



*** Please refer software testing note book for more details.***