STV LAB MANUAL
Software Testing Lab Manual (8CS4-22)
EXPT NO :-1
Understand The Automation Testing Approach (Theory Concept)
Automation
Automation is making a process automatic eliminating the need for human
intervention. It is a self-controlling or self-moving process. Automation Software
offers automation wizards and commands of its own in addition to providing a task
recording and re-play capabilities. Using these programs you can record an IT or
business task.
Benefits of Automation
1. Fast
2. Reliable
3. Repeatable
4. Programmable
5. Reusable
6. Makes Regression testing easy
7. Enables 24*78 Testing
8. Robust verification.
Software Testing Lab Manual ( STV Lab)
Automation Test Workflow
Setup for Test
Automation
Document Manual
test Steps
Check data is valid
Create Basic
Test
Record user actions
Confirm successful
1
STV LAB MANUAL
playback
Enhance Basic
Test
Add
Synchronization
Insert check points
Data drive the test
Integrate Tests
Pass Data
Build integrated
test sets
Prepare Create Verify &Enhance Integrate
2
STV LAB MANUAL
INTRODUCTION TO SELENIUM
1. History of Selenium
• In 2004 invented by Jason R. Huggins and team.
• Original name is JavaScript Functional Tester [JSFT]
• Open source browser based integration test framework built originally by
Thoughtworks.
• 100% JavaScript and HTML
• Web testing tool
• That supports testing Web 2.0 applications
• Supports for Cross-Browser Testing(ON Multiple Browsers)
• And multiple Operating Systems
• Cross browser – IE 6/7, Firefox .8+, Opera, Safari 2.0+
2. What is Selenium?
• Acceptance Testing tool for web-apps
• Tests run directly in browser
• Selenium can be deployed on Windows, Linux, and Macintosh.
• Implemented entirely using browser technologies -
3. Selenium Components
– Selenium IDE
– Selenium Core
– Selenium RC
– Selenium Grid
3.1 Selenium IDE
3
STV LAB MANUAL
• The Selenium-IDE (Integrated Development Environment) is the tool you
use to develop your Selenium test cases.
• It is Firefox plug-in
• Firefox extension which allows record/play testing paradigm
• Automates commands, but asserts must be entered by hand
• Creates the simplest possible Locator
• Based on Selenese
3.1.1 Overview of Selenium IDE:
[Link] Case Pane
B. Toolbar
[Link] Bar
[Link]/Reference/UI-Element/Rollup Pane
A. Test Case Pane:
B. Toolbar: The toolbar contains buttons for controlling the execution of your
test cases, including a step feature for
. Page 5
Software Testing Lab Manual ( STV Lab)
C. Menu Bar:
and test suite files.
operations for editing the commands in your test case.
4
STV LAB MANUAL
can set the timeout value for certain commands, add user-defined user
extensions to the base set of Selenium commands, and specify the format
(language) used when saving your test cases.
D. Help Menu:
Introducing Selenium Commands
The command set is often called selenese. Selenium commands come in three
“flavors”:
Actions, Accessory and Assertions.
a. Actions: user actions on application / Command the browser to do
something.
Actions are commands that generally manipulate the state of the
application.
1. Click link- click / Clickandwait
2. Selecting items
b. Accessors: Accessors examine the state of the application and store the
results in variables, e.g. "storeTitle".
c. Assertions: For validating the application we are using Assertions
1. For verifying the web pages
2. For verifying the text
3. For verifying alerts
Assertions can be used in 3 modes:
Example: "assertText","verifyText" and "waitForText".
NOTE:
5
STV LAB MANUAL
1. When an "assert" fails, the test is aborted.
2. When a "verify" fails, the test will continue execution
3. "waitFor" commands wait for some condition to become true
Commonly Used Selenium Commands
These are probably the most commonly used commands for building test.
open - opens a page using a URL.
click/clickAndWait - performs a click operation, and optionally waits for a new
page to load.
verifyTitle/assertTitle - verifies an expected page title.
verifyTextPresent- verifies expected text is somewhere on the page.
verifyElementPresent -verifies an expected UI element, as defined by its HTML
tag, is present on the page.
verifyText - verifies expected text and it’s corresponding HTML tag are present on
the page.
verifyTable - verifies a table’s expected contents.
waitForPageToLoad -pauses execution until an expected new page loads. Called
automatically when clickAndWait is used.
waitForElementPresent -pauses execution until an expected UI element, as defined
by its HTML tag, is present on the page.
3.1.2 Recording and Run settings
When Selenium-IDE is first opened, the record button is ON by default.
During recording, Selenium-IDE will automatically insert commands into your
test case based on your actions.
a. Remember Base URL MODE - Using Base URL to Run Test Cases in Different Domains
b. Record Absolute recording mode – Run Test Cases in Particular Domain.
3.1.3 Running Test Cases
Run a Test Case Click the Run button to run the currently displayed test case.
6
STV LAB MANUAL
Run a Test Suite Click the Run All button to run all the test cases in the currently
loaded test suite.
Stop and Start The Pause button can be used to stop the test case while it is
running. The icon of this button then changes to indicate the Resume button. To
continue click Resume.
Stop in the Middle You can set a breakpoint in the test case to cause it to stop on a
particular command. This is useful for debugging your test case. To set a
breakpoint, select a command, right-click, and from the context menu select
Toggle Breakpoint.
Start from the Middle You can tell the IDE to begin running from a specific
command in the middle of the test case. This also is used for debugging. To set a
startpoint, select a command, right-click, and from the context menu select
Set/Clear Start Point.
Run Any Single Command Double-click any single command to run it by itself.
This is useful when writing a single command. It lets you immediately test a
command you are constructing, when you are not sure if it is correct. You can
double-click it to see if it runs correctly. This is also available from the context
menu.
Test Suite:
A test suite is a collection of tests. Often one will run all the tests in a test suite as
one continuous batch-job.
When using Selenium-IDE, test suites also can be defined using a simple HTML
file. The syntax again is simple. An HTML table defines a list of tests where each
row defines the filesystem path to each test.
Installing the IDE
Using Firefox, first, download the IDE from the SeleniumHQ downloads page
Firefox will protect you from installing addons from unfamiliar locations, so you
7
STV LAB MANUAL
will need to click ‘Allow’ to proceed with the installation, as shown in the
following screenshot.
When downloading from Firefox, you’ll be presented with the following window.
Select Install Now. The Firefox Add-ons window pops up, first showing a progress
bar, and when the download is complete, displays the following.
Restart Firefox. After Firefox reboots you will find the Selenium-IDE listed under
the Firefox Tools menu.
Opening the IDE
To run the Selenium-IDE, simply select it from the Firefox Tools menu. It opens as
follows with an empty script-editing window and a menu for loading, or creating
new test cases.
8
STV LAB MANUAL
EXPT NO:-2 Using Selenium IDE, Write a test suite containing minimum 4 test
cases.
TC’S #1: Manual Steps:
• Open (Example : Type [Link])
• Type “energy efficient” in the Google Search Input Box
• Click outside on an empty spot
• Click Search Button
• Verify the Text Present as “energy efficient”
• Assert the Title as “energy efficient - Google Search”
• Save the test case with .HTML Extension.
TC’S #2:
• Open (Example : Type [Link])
• Type “Selenium RC” in the Google Search Input Box
• Click outside on an empty spot
• Click Search Button
• Verify the Text Present as “Selenium RC”
• Assert the Title as “Selenium RC - Google Search”
• Save the test case with .HTML Extension.
Steps for creating test suite:
1. Create more Tc’s save each Test Case with <.html> extension.
2. Open Firefox
3. Open Tools à Selenium IDE
4. File à Open à new Test Suite
5. File à Open à Add Test cases
6. Add more test cases
7. Save Suite with <.Html> extensions.
9
STV LAB MANUAL
8. Run the test suite
EXPT NO:-3 Conduct a test suite for nay two web sites.
TC’S #1: Manual Steps:
• Open (Example : Type [Link])
• Type “energy efficient” in the Google Search Input Box
• Click outside on an empty spot
• Click Search Button
• Verify the Text Present as “energy efficient”
• Assert the Title as “energy efficient - Google Search”
• Save the test case with .HTML Extension.
TC#2:
1: Open Firefox Web Browser
2: In the address bar, Type [Link]
3: In the search input button, Type "energy efficient"
4: Click on the "Web Search" submit button
5: Wait for Search Results to come on "http:/[Link]"
6: Verify "energy efficient" text is present anywhere in the search results:
(Select and
highlight anywhere in the search results page, "energy efficient" text is
present.)
7: Verify the browsers title has the value "energy efficient - Yahoo! Search
Results"
8. Save the test case with .HTML Extension.
Steps for creating test suite:
1. Create more Tc’s save each Test Case with <.html> extension.
2. Open Firefox
3. Open Tools à Selenium IDE
10
STV LAB MANUAL
4. File à Open à new Test Suite
5. File à Open à Add Test cases
6. Add more test cases
7. Save Suite with <.Html> extensions.
8. Run the test suite
Selenium-RC
1. Introduction
Selenium-RC is the solution for tests that need more than simple browser actions
and linear execution.
Selenium-RC uses the full power of programming languages to create more
complex tests like reading and writing files, querying a database, emailing test
results.
You’ll want to use Selenium-RC whenever your test requires logic not supported
by Selenium-IDE.
What logic could this be? For example, Selenium-IDE does not directly support:
• condition statements
• iteration
• logging and reporting of test results
• error handling, particularly unexpected errors
• database testing
• test case grouping
• re-execution of failed tests
• test case dependency
• screenshot capture of test failures
Although these tasks are not supported by Selenium directly, all of them can be
achieved by using programming techniques with a language-specific Selenium-RC
client library.
11
STV LAB MANUAL
EXPT NO :-4 Install Selenium server and demonstrate it using a script in
Java/PHP
Installation of Selenium RC and Eclipse
Download Eclipse
1. Go to URL – [Link]
2. Select Eclipse IDE for Java Developers (Click on Windows 32 bit platform)
3. Click on OK button and save to a local drive (i.e. C: or D:, etc)
4. Unzip the downloaded zip file and rename that to Eclipse
5. Create one more folder “Eclipse-Workspace” (i.e. C:Eclipse-Workspace)in
the same drive where Eclipse is unzipped and renamed.
6. Create Eclipse desktop shortcut (go to C:Eclipse folder –> right click
[Link] and then click on “desktop create shortcut”) as demonstrated in
the below pictures.
1. Now we need to create a workspace folder –> C:Eclipse-
WorkspaceSeleniumTests
2. Double click on “Eclipse shortcut on Desktop”
3. This opens the Eclipse
4. Close Eclipse welcome screen
5. Click File menu –> Switch Worspace –> other
6. Now Select the C:Eclipse-WorkspaceSeleniumTests folder (These steps are
demonstrated in the following figure)
We have finished setting up the eclipse. Now, we need to download Selenium RC
server / client driver and configure that to Eclipse
1. Download Selenium server: [Link]
2. Download Selenium Client driver for Java (from Selenium Client Drivers
section)
12
STV LAB MANUAL
3. Create “Selenium” folder in C: drive and copy the [Link] as
well as unzip the Selenium Client driver (C:Selenium)
Downloading and unzipping the files into a folder is done. We need to configure
the appropriate Selenium Client driver Jar file to the Eclipse.
1. Go to Eclipse –> Click File –> New –> Project (from various options need to
select just “project”)
2. In Select Wizard –> Click Java –> “Java Project” (demonstrated in the below
figure)
3. Give the project name (e.g. SugarCRMTests)
4. Click Finish – Click Yes
5. Now we are done with creation of project and need to configure the
Selenium Client driver to this Project
6. Right Click “SugarCRMTests” project
7. Click “Java Build Path”
8. Click Libraries tab
9. Click “Add External JARs” button
10. Select “Selenium Client Drivers” unzipped in C:Selenium folder (Selenium
Server JAR file should not be added)
11. Click OK
[Link] libraries –> contains both the Selenium Client driver jar files as
shown in the below picture.
First script-Selenium RC-JUnit-Java
Selenium RC allows to write the automated tests in any language. Selenium Scripts
can be written in various ways:
1. Extending the Selenese Test Case
2. Extending the TestCase-Junit and defining an object to the DefaultSelenium
Class
13
STV LAB MANUAL
Before you start with your script, the following are the steps that should be
performed.
Method1: Extending the Selenese Test Case
1. Install any IDE (Eclipse, IntelliJ, IDEA), create a project.
2. Download the selenium RC file from Selenium website.
3. Extract the [Link] file and add the seleniumremote-
control-1.0.3\selenium-java-client-driver-1.0.1\selenium-javaclientdriver.
jar and selenium-remote-control-1.0.3\selenium-server-
1.0.3\[Link] file to the build path.
4. Create a new package and a class in the newly created package.
5. Copy the below code:
import [Link];
public class SeleniumTest1 extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("[Link] "*firefox");
public void testNew() throws Exception{
[Link]("/");
[Link]("searchbox", "selenium rc");
[Link]("css=input[type='submit'][value='Search']");
[Link]("30000");
assertTrue([Link]("selenium rc"));
[Link] the selenium Server.
[Link] on the RunAs button and run the script as JUnit Test. If you don’t
find the option Install the JUnit plug-in and run the script.
14
STV LAB MANUAL
Method2: Extending the DefaultSelenium Class.
Some times we need the selenium scripts to contact the server running on a
different port and different machine. You can configure the selenium scripts to
handle such situations easily by extending your selenium script from
TestCase(Junit) and defining the selenium instance as an object to DefaultSelenium
class.
package test;
import [Link].*;
import [Link];
public class DefaultSelenium1 extends TestCase{
private DefaultSelenium selenium;
public void testing(){
selenium=new
DefaultSelenium("localhost",4444,"*iexplore","[Link]
[Link]();
[Link]("/");
[Link]("searchbox", "selenium rc");
[Link]("css=input[type='submit'][value='Search']");
[Link]("30000");
[Link]([Link]("selenium rc"));
15
STV LAB MANUAL
EXPT NO:-5 Write and test a program to login a specific web page.
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
public class exp5 extends SeleneseTestCase {
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome",
"[Link]
[Link]();
@Test
public void testExp5() throws Exception {
[Link]("/wordpress/[Link]");
[Link]("id=user_login", "admin");
[Link]("id=user_pass", "demo123");
[Link]("id=wp-submit");
[Link]("30000");
@After
public void tearDown() throws Exception {
[Link]();
16
STV LAB MANUAL
TestNG
TestNG is a testing framework inspired from JUnit and NUnit but introducing
some new functionalities that make it more powerful and easier to use, such as:
(all methods in their own thread, one thread per test class, etc...).
-driven testing (with @DataProvider).
-ins (Eclipse, IDEA, Maven, etc...).
TestNG is designed to cover all categories of tests: unit, functional, end-to-end,
integration, etc...
Installing TestNG in eclipse
nd below, enter [Link]
Launching your tests in Eclipse
17
STV LAB MANUAL
even programatically. We are going to use the Eclipse plugin. Follow the
steps described on the official TestNG documentation over here
click on the XML file:
then see this nice results tree:
Selenium Tests with Microsoft Excel
Parameterizing a test from external sources such as Microsoft Excel is always
recommended in order to handle large amount of test data. To read data from
Excel, we need APIs which support opening file, reading data, and writing data
into Excel. We should know various classes and methods which support above
mentioned operations. In this post, let us try to figure out which is the API that
supports all the activities we need to do during execution of a test.
[Link] is an open source Java API which supports read Excel spreadsheets and to
write into Excel spreadsheets. Below are some of the operations that we can
handle with this API.
1. Read data from Excel spreadsheet
2. Read and write formulas into spreadsheets
3. Generate spreadsheets
4. Supports formatting of font, number, and date
5. Supports coloring of cells
To access the methods and classes provided by this API inside Eclipse we need to
add this JAR file to the Java Build Path. (I have explained steps to add external Jar
files to Java Build Path in previous posts)
18
STV LAB MANUAL
Download the [Link] from “[Link]
Add the JAR file to Java Build Path
Add import statements to the .java file as below to read from an Excel spreadsheet
import [Link];
import [Link];
import [Link];
import [Link];
19
STV LAB MANUAL
EXPT NO :-6 Write and test a program to update 10 student records into table
into Excel file .
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
public class newj {
@BeforeClass
public void setUp() throws Exception {}
@Test
public void testImportexport1() throws Exception {
FileInputStream fi = new FileInputStream("D:\\[Link]");
Workbook w = [Link](fi);
Sheet s = [Link](0);
String a[][] = new String[[Link]()][[Link]()];
FileOutputStream fo = new FileOutputStream("D://[Link]");
WritableWorkbook wwb = [Link](fo);
WritableSheet ws = [Link]("result1", 0);
for (int i = 0; i < [Link](); i++)
for (int j = 0; j < [Link](); j++)
a[i][j] = [Link](j, i).getContents();
20
STV LAB MANUAL
Label l2 = new Label(j, i, a[i][j]);
[Link](l2);
Label l1 = new Label(6, 0, "Result");
[Link](l1);
for (int i = 1; i < [Link](); i++) {
for (int j = 2; j < [Link](); j++)
a[i][j] = [Link](j, i).getContents();
int x=[Link](a[i][j]);
if(x > 35)
Label l1 = new Label(6, i, "pass");
[Link](l1);
else
Label l1 = new Label(6, i, "fail");
[Link](l1);
break;
[Link]();
[Link]();
21
STV LAB MANUAL
INPUT
OUTPUT
EXPT NO :-7 Write and test a program to select the number of students who have
scored more than 60 in any one subject ( or all subjects ).
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
public class exp7 {
@BeforeClass
public void setUp() throws Exception {
@Test
public void testImportexport1() throws Exception {
FileInputStream fi = new FileInputStream("D:\\[Link]");
Workbook w = [Link](fi);
Sheet s = [Link](0);
String a[][] = new String[[Link]()][[Link]()];
FileOutputStream fo = new FileOutputStream("D://[Link]");
WritableWorkbook wwb = [Link](fo);
WritableSheet ws = [Link]("result", 0);
int c=0;
for (int i = 0; i < [Link](); i++) {
22
STV LAB MANUAL
for (int j = 0; j < [Link](); j++)
if(i >= 1)
String b= new String();
b=[Link](3,i).getContents();
int x= [Link](b);
. Page 28
Software Testing Lab Manual ( STV Lab)
if( x < 60)
c++;
break;
a[i][j] = [Link](j, i).getContents();
Label l2 = new Label(j, i-c, a[i][j]);
[Link](l2);
[Link]();
[Link]();
INPUT
OUTPUT
23
STV LAB MANUAL
EXPT NO :-8 Write and test a program to provide total number of objects present
/ available on the page .
package testscripts;
import [Link].*;
import [Link].*;
import [Link].*;
public class exp8 {
public Selenium selenium;
public SeleniumServer seleniumserver;
@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox","[Link]
[Link]();
[Link]();
@Test
public void testDefaultTNG() throws Exception {
[Link]("[Link]
[Link]();
String lc[]=[Link]();
[Link]("TOTAL NO OF LINKS="+[Link]);
String bc[]=[Link]();
[Link]("TOTAL NO OF BUTTONS="+[Link]);
String fc[]=[Link]();
24
STV LAB MANUAL
[Link]("TOTAL NO OF INPUT FIELDS="+[Link]);
@AfterClass
public void tearDown() throws Exception {
[Link]();
[Link]();
OUTPUT
TOTAL NO OF LINKS=41
TOTAL NO OF BUTTONS=1
TOTAL NO OF INPUT FIELDS=3
25
STV LAB MANUAL
EXPT NO :-9 Write and test a program to get the number of list items in a list /
combo box.
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
public class Dropdowngoogle {
public Selenium selenium;
public SeleniumServer seleniumserver;
@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "[Link]
[Link]();
[Link]();
@Test
public void testDropdowngoogle()throws Exception {
[Link]("[Link]
[Link]("3000");
String[] option = [Link]("name=course");
File file = new File("C:/[Link]");//excel
File file1 = new File("C:/[Link]");//notepad
26
STV LAB MANUAL
BufferedWriter out = new BufferedWriter(new FileWriter(file));//excel
BufferedWriter out1 = new BufferedWriter(new FileWriter(file1));//notepad
[Link]("Options in drop down\n");//Excel
[Link]("Options in drop down\n");//notepad
for (int i = 0; i < [Link]; i++) {
[Link]("Option: " + i + " is" + option[i]);
[Link](""+option[i]);
[Link]();
[Link](""+option[i]);
[Link]();
[Link]();//excel
[Link]();//notepad
@AfterClass
public void tearDown()throws Exception {
[Link]();
[Link]();
OUTPUT
27
STV LAB MANUAL
EXPT NO :-10 Write and test a program to count number of check boxes on the
page checked and unchecked count.
package testscripts;
import [Link].*;
import [Link].*;
import [Link].*;
public class exp8 {
public Selenium selenium;
public SeleniumServer seleniumserver;
@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox","[Link]
[Link]();
[Link]();
@Test
public void testDefaultTNG() throws Exception {
[Link]("[Link]
[Link]();
//Count of check boxes
Number c =[Link]("//input[@type['checkbox']]");
[Link]("Count of check boxes " +c);
//Number of check boxes checked
Number d = [Link]("//input[@type='checkbox' and
28
STV LAB MANUAL
@checked]");
[Link]("Count of Checked check boxes " +d);
//Number of check boxes unchecked
Number e = [Link]("//input[@type='checkbox' and
not(@checked)]");
[Link]("Count of Checked check boxes " +e);
@AfterClass
public void tearDown() throws Exception {
[Link]();
[Link]();
OUTPUT
Count of check boxes 127
Count of Checked check boxes 91
Count of Checked check boxes 36
29