Table
of Contents
1. Selenium
Introduction
1.1 Selenium Projects
1.2 Selenium IDE (IDE)
1.3 Selenium Core (CORE)
1.4 Selenium Remote Control (RC)
1.5 Selenium Grid
1.6 Selenium Supported Browsers
1.7 Supported Operating Systems
1.8 Supported Programming languages
2. Selenium
Set up in Eclipse
2.1 Required Software
2.2 Procedure
3. Selenium
Commands
3.1 Element Locator
3.2 Important Selenium Commands
4. Tools for
identifying the element names and IDs
4.1 Debug bar
4.2 Firebug
5. Selenium
Script Explanation
6. Selenium
Scripts for a site
6.1 Login
6.2 Multiple_Login1
6.3 Login_Import_Export1
6.4 Simple_Acc_Registration
6.5 Multiple_Acc_Registration
6.6 Multiple_Acc_Reg_login
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.
1.6
Selenium Supported Browsers
Selenium
tools can run in following browsers.* Internet Explorer
* FireFox
* Opera
*Chrome
* Safari
* Seamonkey
1.7
Supported Operating Systems
* Windows
* Linux
* Solaris
* OS X
1.8
Supported Programming languages
Below
languages are supported by Selenium RC.
*
C# (DotNet)
* Java
* Perl
* Ruby
* Python
* PHP
* Java
* Perl
* Ruby
* Python
* PHP
2. Selenium Set up in Eclipse
This section will explain how to
set up selenium in Eclipse.
2.1 Required Software
·
Eclipse (Version 3.7) –
http://www.eclipse.org/downloads/
eclipse-jee-indigo-win32-x86_64.zip
·
Jdk 1.5.0_11 or above
http://java.sun.com/javase/downloads/index_jdk5.jsp
·
selenium-server-standalone-2.16.0.jar
2.2 Procedure
1. Install Eclipse, JDK in the machine
2.
Create an empty folder (AutomatedTestScripts)
in C drive
3.
Open eclipse (c: \eclipse\eclipse.exe)
After
clicking Ok you will get below screen select “work bench”.
You
will get the below screen—eclipse environment.
Create Java Project
1.
File—New—Java Project
2. Give Project name (VFUKNewCo)
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.
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.
Now
Right click on JRE System Library[Java SE-1.7]
Select
Build Path-àconfigure
Build Path.
A
new window will be opened. Select Libraries tab and click Add External Jars
Button.
Select
the required Jar files mentioned below:
o
selenium-server-standalone-2.16.0.jar
o
logging-selenium-1.2.jar
o
iText-2.1.5.jar
Click
OK.
You
can see all Jar files under Referenced Libraries Tab.
Click
Ok.
You
can see the Referenced Libraries…
Now
need to start selenium server…
Go
to RUNà
type cmd àopen
command prompt…
Change
the directory to where the standalone jar is located:
Start
the server with the command: java –jar
selenium-server-standalone-2.7.0.jar
Press
Enter, server will start as shown below:
Note:
Don’t click on this cmd prompt window.
Your
selenium server will be up and running….
Now
you can write your scripts and Enjoy Selenium Automation….
Right click on src – New – class
Give
Package with the name as com.vfuk.tests and Name as Example and click Finish
It
will open your editor with file name First
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.
·
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
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()
|
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.
|
check()
|
Check(
string locator );
selenium.check
("guest”);
|
Check a toggle-button (checkbox/radio)
|
uncheck()
|
Uncheck(
string locator ); |
Uncheck a toggle-button (checkbox/radio)
|
select()
|
selenium.select("payware_expiration_yr",
"label=2010”);
|
Select an option from a drop-down using an option locator.
|
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/
5. Selenium Script Explanation
Here 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]",
"dnr5dnr@gmail.com");
//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");
// print message
System.out.println("Login
and Log out success");
}
public static
void main(String[] args) throws Exception{
Login_results();
}
}
A very interesting topic that you have discussed here, definitely, your tips help me out to reach my passion. I would love to see more updates. Thank you, admin.
ReplyDeleteBest Selenium Training Institute in Chennai
Selenium training institute in Chennai