Selenium RC Set Up in Eclipse

Share Embed Donate


Short Description

Download Selenium RC Set Up in Eclipse...

Description

Selenium Documentation

th

July 13 , 2010

Table of Contents

1. Selenium Introduction....................... ........................... ........................... ........................... ........... 3 1.1 Selenium Projects ........................ ........................... .......................... ............................ ........ 3 1.2 Selenium IDE (IDE) .............................................................................................................. 3 1.3 Selenium Core (CORE) ............................................... ......................... ............................ .... 3 1.4 Selenium Remote Control (RC)....................... .......................... ............................ ................ 3 1.5 Selenium Grid .......................... ........................... ......................... ............................. ............ 3 1.6 Selenium Supported Browsers ........................ .......................... ............................ ................ 4 1.7 Supported Operating Systems ....................... ........................... ............................ ................ 4 1.8 Supported Programming languages ......................... ......................... ............................. ....... 4 2.

Selenium Set up in Eclipse ........... ........................... ........................... ........................... ................ 5 2.1 Required Software ........................ .......................... .......................... ............................ ........ 5 2.2 Procedure....................... ........................... .......................... ............................ ..................... 5

3. Selenium Commands ........................................... ........................... ........................... .................. 13 3.1 Element Locator ................................................................................................................. 13 3.2 Important Selenium Commands ........................... ......................... ............................ .......... 14 4.

Tools for identifying the element names and IDs .......................... ........................... .................. 16 4.1 Debug bar .......................................................................................................................... 16 4.2 Firebug ............................................................................................................................... 16

5. Selenium Script Explanation .......................... ........................... ........................... ....................... 17 6. Selenium Scripts for a site .......................... ........................... ........................... .......................... . 19 6.1 Login .................................................................................................................................. 19 6.2 Multiple_Login1 .................................................................................................................. 19 6.3 Login_Import_Export1......................................................................................................... 19 6.4 Simple_Acc_Registration ....................... .......................... .......................... ......................... 19 6.5 Multiple_Acc_Registration................................................................................................... 19 6.6 Multiple_Acc_Reg_login ..................................................................................................... 19

2

1. 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.

3

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

4

2.

Selenium Set up in Eclipse

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

Required Software

2.1 y

Eclipse

y

Jdk

y

2.2

(Version 3.5.2) ± http://www.e clipse.org/downloads/download.php?file=/e clipse/downloads/drops/ R-3.5.2-201002111343/e clipse-SDK-3.5.2-win32.zip 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)

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.

5

 After clicking Ok you will get below screen select ³work bench´.

6

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 VM next. JRE Home²we need to specify path.

7

Click directory²browse the path (F:\Selenium_scripts1\jdk1.5.0_11\jre)

where

you

created

the

folder 

 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.

8

You can see the Referenced Libraries«

Everything is done.

Now need to create selenium server« Go to RUNExternal Tools External 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«.

9

Your selenium server will be up and running«.

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

10

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

11

It will open your editor with file name First

12

3. Selenium Commands

3.1

Element Locator

Element 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. y y

username name=username

xpath= xpathE  xpr ession Locate an element using an XPath expression. y y

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

link=te x tPatter n Select the link (anchor) element which contains text matching the specified y

 patter n.

link=The link text

13

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");

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.

selenium.click("name=send");

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.

doubleClick()

type()

Type( string string );

l oc at or , v alue

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

check()

Check(

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.

Check a toggle-

14

string

l oc at or 

);

button (checkbox/radio)

selenium. check ("guest´);

uncheck()

Uncheck( string l oc at or  );

Uncheck a togglebutton (checkbox/radio)

select()

Select( string string );

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

sel ec tLoc at or , o pt ionLoc at or 

selenium.sele ct("payware_expiration_yr", "label=2010´);

For more commands please refer the link http://release.seleniumhq.org/selenium-remotecontrol/0.9.2/doc/java/com/thoughtworks/selenium/Selenium.html

15

4.

Tools for identifying the element names and IDs

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

4.1

Debug bar

Debug 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

Firebug

Firebug 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/

16

5. Selenium Script Explanation Here we can see the code f or 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 publi c static DefaultSelenium

sel eni um=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");

17

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

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

}

18

6. Selenium Scripts for a site

Script Name

Script Description

6.1

Login and Log out

Login

S cript path

Login

6.2

Multiple_Login1

Multiple Logins Reads data from Excel sheet Multiple_login1

6.3

Login_Import_Export1

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

Login_Import_Export 

1

6.4

Simple_Acc_Registration

Single Account Creation Simple_Acc_Registra

tion

6.5

6.6

Multiple_Acc_Registration

Multiple_Acc_Reg_login

Multiple Account Creation [Using Loop and Excel sheet]

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

Multiple_Acc_Registr ation

Multiple_Acc_Reg_ Lo gin

19

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF