Selenium RC Set Up in Eclipse

24
Selenium Documentation July 13 th , 2010

Transcript of Selenium RC Set Up in Eclipse

Page 1: Selenium RC Set Up in Eclipse

Selenium Documentation

July 13th, 2010

Page 2: Selenium RC Set Up in Eclipse

Table of Contents

1. Selenium Introduction......................................................................31.1 Selenium Projects....................................................................................................................31.2 Selenium IDE (IDE).................................................................................................................. 31.3 Selenium Core (CORE)............................................................................................................31.4 Selenium Remote Control (RC)...............................................................................................31.5 Selenium Grid.......................................................................................................................... 31.6 Selenium Supported Browsers.................................................................................................41.7 Supported Operating Systems.................................................................................................41.8 Supported Programming languages........................................................................................4

2. Selenium Set up in Eclipse................................................................52.1 Required Software...................................................................................................................52.2 Procedure................................................................................................................................ 5

3. Selenium Commands.......................................................................133.1 Element Locator..................................................................................................................... 133.2 Important Selenium Commands.............................................................................................14

4. Tools for identifying the element names and IDs..............................164.1 Debug bar.............................................................................................................................. 164.2 Firebug................................................................................................................................... 16

5. Selenium Script Explanation............................................................17

6. Selenium Scripts for a site..............................................................196.1 Login...................................................................................................................................... 196.2 Multiple_Login1...................................................................................................................... 196.3 Login_Import_Export1............................................................................................................196.4 Simple_Acc_Registration.......................................................................................................196.5 Multiple_Acc_Registration......................................................................................................196.6 Multiple_Acc_Reg_login.........................................................................................................19

Page 3: Selenium RC Set Up in Eclipse

1.Selenium IntroductionSelenium 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 ProjectsSelenium 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 GridSelenium Grid allows easily to run multiple tests in parallel, on multiple machines, in anheterogeneous environment by cutting down the time required for test execution. Using this, user can run multiple instances of Selenium Remote Control in parallel.

Page 4: Selenium RC Set Up in Eclipse

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

Page 5: Selenium RC Set Up in Eclipse

2.Selenium Set up in EclipseThis section will explain how to set up selenium in Eclipse.

2.1 Required Software Eclipse (Version 3.5.2) –

http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.5.2-201002111343/eclipse-SDK-3.5.2-win32.zip

Jdk 1.5.0_11 or above http://java.sun.com/javase/downloads/index_jdk5.jsp

4 Jar files (junit-4.5, jxl, selenium-java-client-driver, selenium-server)

2.2 Procedure

1. Create an empty folder (Selenium_Scripts1) in F drive-no need to create in F drive you can create folder in any folder.

2. Create an empty folder lib in Selenium_Scripts1 folder.

3. Install jdk1.5.0_11, copy the jdk1.5.0_11 folder which is in c folder (Generally it will be installed in “C” Drive-- C:\Program Files\Java) and paste it in Selenium_Scripts1 folder.

4. Paste the 4 Jar files (junit-4.5, jxl, selenium-java-client-driver, and selenium-server) in lib folder.

5. Open eclipse (F: \eclipse\eslipse.exe)

You will get the below window select the path (F:\ Selenium_Scripts1) which you created a folder earlier in F drive.

Page 6: Selenium RC Set Up in Eclipse

After clicking Ok you will get below screen select “work bench”.

Page 7: Selenium RC Set Up in Eclipse

You will get the below screen—eclipse environment.

Create Java Project

1. File—New—Java Project

2. Give Project name (First)

3. Click Configure JREs in that screen. You will get a new window.

4. Click Add—Standard VMnext.

JRE Home—we need to specify path.

Page 8: Selenium RC Set Up in Eclipse

Click directory—browse the path where you created the folder (F:\Selenium_scripts1\jdk1.5.0_11\jre)

All jar files will be added. Click Finish and click OK

Click finish on the open window (New Java Project window)

You can see the new project Selenium_scripts1 in eclipse window.

New Java Project with all jar files.

Now Right click on JRE System Library[Java SE-1.6]

Select Build Path-configure Build Path.

A new window will be opened. Select Libraries tab and click Add External Jars Button.

Select path F:\demo\lib and select all 4 Jar files click OK.

You can see all Jar files under Libraries Tab.

Click Ok.

Page 9: Selenium RC Set Up in Eclipse

You can see the Referenced Libraries…

Everything is done.

Now need to create selenium server…

Go to RUNExternal ToolsExternal tools configuration…

There click Program---u will get new configuration window.

Give name selenium server (any name you can give).

Location ---click on Browse file systems. F:\Selenium_Scripts1\jdk1.5.0_11\bin\java.exe

Working Directory--- Browse file system --- F:\ Selenium_Scripts1\lib.

Arguments - -jar selenium-server.jar

Click Apply and Run….

Page 10: Selenium RC Set Up in Eclipse

Your selenium server will be up and running….

Now you can write your scripts and Enjoy Selenium Automation….

Page 11: Selenium RC Set Up in Eclipse

File – New –class

Give Name First and click the check box public static void main (String [] args) click Finish

Page 12: Selenium RC Set Up in Eclipse

It will open your editor with file name First

Page 13: Selenium RC Set Up in Eclipse

3.Selenium Commands

3.1 Element LocatorElement Locators tell Selenium which HTML element a command refers to.

The format of a locator is: locatorType=argument

Example: - (“link=click”)

Selenium supports the following strategies for locating elements:

id=id

Select the element with the specified @id attribute

name=name

Select the first element with the specified @name attribute.

username name=username

xpath=xpathExpression

Locate an element using an XPath expression.

xpath=//img[@alt='The image alt text'] xpath=//table[@id='table1']//tr[4]/td[2]

link=textPattern

Select the link (anchor) element which contains text matching the specified pattern.

link=The link text

Page 14: Selenium RC Set Up in Eclipse

3.2 Important Selenium Commands

Command Usage Description

start() selenium.start(); Launches the browser with a new Selenium session

stop() selenium.stop(); Ends the current Selenium testing session (normally killing the browser)

click() selenium.click("link=Home");

selenium.click("name=send");

Clicks on a link, button, checkbox or radio button. If the click action causes a new page to load (like a link usually does), call waitForPageToLoad.

doubleClick() Double clicks on a link, button, checkbox or radio button. If the double click action causes a new page to load (like a link usually does), call waitForPageToLoad.

type() Type(   string locator,   string value);

selenium.type("name=login[username]", ndasam);

Sets the value of an input field, as though you typed it in. Can also be used to set the value of combo boxes, check boxes, etc. In these cases, value should be the value of the option selected, not the visible text.

Page 15: Selenium RC Set Up in Eclipse

check() Check(   string locator);

selenium.check ("guest”);

Check a toggle-button (checkbox/radio)

uncheck() Uncheck(   string locator);

Uncheck a toggle-button (checkbox/radio)

select() Select(   string selectLocator,   string optionLocator);

selenium.select("payware_expiration_yr", "label=2010”);

Select an option from a drop-down using an option locator.

For more commands please refer the link

http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/java/com/thoughtworks/selenium/Selenium.html

Page 16: Selenium RC Set Up in Eclipse

4.Tools for identifying the element names and IDs

We have to use some tools to identify the element locators.

4.1 Debug barDebug bar is an Internet Explorer plug-in.

1. We can use this tool for identifying the element names and Ids.

2. View source code

You can download Debug bar by using the link http://www.debugbar.com/?langage=en

4.2 FirebugFirebug integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page...

1. Inspect HTML and modify style and layout in real-time

2. Accurately analyze network usage and performance

You can download fire bug using the link https://addons.mozilla.org/en-US/firefox/addon/1843/

Page 17: Selenium RC Set Up in Eclipse

5.Selenium Script ExplanationHere we can see the code for simple login and logout functionality with comments and the explanation of code.

import com.thoughtworks.selenium.DefaultSelenium; //Selenium package

//Class name[class name should equal to program name]

public class Login {

//creating a method

public static void Login_results() throws Exception

{

/*Defining the selenium method if you want to declare Default selenium outside the method you need to declare as public

public static DefaultSelenium selenium=new DefaultSelenium("localhost",4444,"*iehta","http://");

localhost—serverHost

4444 --- serverport

Iehta ----- browserstart command(we can use *firefox also)

http:// ---browser URL(Here we can give full URL of site) */

DefaultSelenium selenium=new DefaultSelenium("localhost", 4444, "*iehta", "http://");

//this command will start the selenium

selenium.start();

//to open the URL

selenium.open("www.example.com");

//Maximizes the window

selenium.windowMaximize();

//to read user name

selenium.type("name=login[username]", "[email protected]");

//to read password

selenium.type("name=login[password]", "xxxxx");

//click login button

selenium.click("send2");

//waits until the page loads

selenium.waitForPageToLoad("50000");

//click the link sign out

selenium.click("link=Sign Out");

Page 18: Selenium RC Set Up in Eclipse

// print message

System.out.println("Login and Log out success");

}

public static void main(String[] args) throws Exception{

Login_results();

}

}

Page 19: Selenium RC Set Up in Eclipse

6.Selenium Scripts for a site

Script Name Script Description Script path

6.1 Login Login and Log out

6.2 Multiple_Login1 Multiple Logins Reads data from Excel sheet

6.3 Login_Import_Export1 Read data from Excel sheet and write the result in another excel sheet

6.4 Simple_Acc_Registration

Single Account Creation

6.5 Multiple_Acc_Registration

Multiple Account Creation [Using Loop and Excel sheet]

6.6 Multiple_Acc_Reg_login

Multiple account Creation and Logins checkng[Using Loop and Excel sheet]