Software Testing Lab Manual
Software Testing Lab Manual
2011-12
SOFTWARE TESTING
LABORATORY MANUAL
VI Semester Computer Science & Engineering
2011-12
BY
Mr.RAHUL A.PALAKAR
LECTURER
COMPUTER SCIENCE DEPARTMENT
B.T.PATIL & SONS POLYTECHNIC
Stavanidhi-Nipani. Dist: BELGAUM
Email : [email protected]
Page 1
2011-12
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
Fast
Reliable
Repeatable
Programmable
Reusable
Makes Regression testing easy
Enables 24*78 Testing
Robust verification.
Page 2
2011-12
Create
Verify &Enhance
Setup
Test
Createfor
Basic
Automation
Test
Enhance Basic
Document
Record
userManual
actions
test Steps
Confirm successful
Check
data is valid
playback
Add
Integrate
Integrate Tests
Test
Synchronization
Insert check points
Pass Data
Build integrated
test sets
Page 3
2011-12
INTRODUCTION TO SELENIUM
1. History of Selenium
In 2004 invented by Jason R. Huggins and team.
JavaScript
DHTML
Frames
3. Selenium Components
Selenium IDE
Selenium Core
Selenium RC
B.T.Patil & Sons Polytechnic, Stavanidhi-Nipani, Dist: Belgaum.
Page 4
2011-12
Selenium Grid
3.1 Selenium IDE
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:
A.Test Case Pane
B. Toolbar
C. Menu Bar
D.Log/Reference/UI-Element/Rollup Pane
B. Toolbar: The toolbar contains buttons for controlling the execution of your
Page 5
2011-12
C. Menu Bar:
File Menu: The File menu allows you to create, open and save test case
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
Page 6
2011-12
Page 7
2011-12
Page 8
2011-12
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.
When downloading from Firefox, youll be presented with the following window.
Page 9
2011-12
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.
Page 10
2011-12
Page 11
2011-12
EXPT NO:-2 Using Selenium IDE, Write a test suite containing minimum 4 test
cases.
TCS #1: Manual Steps:
TCS #2:
Page 12
2011-12
EXPT NO:-3 Conduct a test suite for nay two web sites.
TCS #1: Manual Steps:
TC#2:
1: Open Firefox Web Browser
2: In the address bar, Type http://www.yahoo.com
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:/search.yahoo.com"
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.
Page 13
2011-12
Page 14
2011-12
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.
Youll 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.
Page 15
2011-12
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
Page 16
2011-12
2. Download Selenium Client driver for Java (from Selenium Client Drivers
section)
3. Create Selenium folder in C: drive and copy the Selenium-server.jar 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)
Page 17
2011-12
Page 18
2011-12
3. Extract the selenium-remote-control-1.0.3.zip 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-server1.0.3\selenium-server.jar file to the build path.
4. Create a new package and a class in the newly created package.
5. Copy the below code:
import com.thoughtworks.selenium.SeleneseTestCase;
public class SeleniumTest1 extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://www.hexbytes.com/", "*firefox");
}
B.T.Patil & Sons Polytechnic, Stavanidhi-Nipani, Dist: Belgaum.
Page 19
2011-12
Page 20
2011-12
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;
public class exp5 extends SeleneseTestCase {
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome",
"http://demo.opensourcecms.com/");
selenium.start();
}
@Test
public void testExp5() throws Exception {
selenium.open("/wordpress/wp-login.php");
selenium.type("id=user_login", "admin");
selenium.type("id=user_pass", "demo123");
selenium.click("id=wp-submit");
selenium.waitForPageToLoad("30000");
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}
Page 21
2011-12
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:
Annotations.
Run your tests in arbitrarily big thread pools with various policies available
(all methods in their own thread, one thread per test class, etc...).
Page 22
2011-12
You can launch TestNG from the command line, using a Eclipse plugin or
even programatically. We are going to use the Eclipse plugin. Follow the
steps described on the official TestNG documentation over here
If you installed TestNG correctly, you will see this menu when you right
click on the XML file:
Click on Run as TestNG Suite and your test will start running. You will
then see this nice results tree:
Page 23
2011-12
Page 24
2011-12
EXPT NO :-6 Write and test a program to update 10 student records into table
into Excel file .
import java.io.FileInputStream;
import java.io.FileOutputStream;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.testng.annotations.*;
public class newj {
@BeforeClass
public void setUp() throws Exception {}
@Test
public void testImportexport1() throws Exception {
FileInputStream fi = new FileInputStream("D:\\exp6.xls");
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
String a[][] = new String[s.getRows()][s.getColumns()];
FileOutputStream fo = new FileOutputStream("D://exp6Result.xls");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("result1", 0);
for (int i = 0; i < s.getRows(); i++)
for (int j = 0; j < s.getColumns(); j++)
{
a[i][j] = s.getCell(j, i).getContents();
Label l2 = new Label(j, i, a[i][j]);
ws.addCell(l2);
Label l1 = new Label(6, 0, "Result");
ws.addCell(l1);
}
for (int i = 1; i < s.getRows(); i++) {
B.T.Patil & Sons Polytechnic, Stavanidhi-Nipani, Dist: Belgaum.
Page 25
2011-12
Page 26
2011-12
INPUT
OUTPUT
Page 27
2011-12
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 java.io.FileInputStream;
import java.io.FileOutputStream;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.testng.annotations.*;
public class exp7 {
@BeforeClass
public void setUp() throws Exception {
}
@Test
public void testImportexport1() throws Exception {
FileInputStream fi = new FileInputStream("D:\\exp6.xls");
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
String a[][] = new String[s.getRows()][s.getColumns()];
FileOutputStream fo = new FileOutputStream("D://exp7Result.xls");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("result", 0);
int c=0;
for (int i = 0; i < s.getRows(); i++) {
for (int j = 0; j < s.getColumns(); j++)
{
if(i >= 1)
{
String b= new String();
b=s.getCell(3,i).getContents();
int x= Integer.parseInt(b);
B.T.Patil & Sons Polytechnic, Stavanidhi-Nipani, Dist: Belgaum.
Page 28
2011-12
Page 29
2011-12
OUTPUT
Page 30
2011-12
EXPT NO :-8 Write and test a program to provide total number of objects present
/ available on the page .
package testscripts;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;
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","http://");
seleniumserver.start();
selenium.start();
}
@Test
public void testDefaultTNG() throws Exception {
selenium.open("http://www.google.co.in/");
selenium.windowMaximize();
String lc[]=selenium.getAllLinks();
System.out.println("TOTAL NO OF LINKS="+lc.length);
String bc[]=selenium.getAllButtons();
System.out.println("TOTAL NO OF BUTTONS="+bc.length);
String fc[]=selenium.getAllFields();
System.out.println("TOTAL NO OF INPUT FIELDS="+fc.length);
}
Page 31
2011-12
@AfterClass
public void tearDown() throws Exception {
selenium.stop();
seleniumserver.stop();
}
}
OUTPUT
TOTAL NO OF LINKS=41
TOTAL NO OF BUTTONS=1
TOTAL NO OF INPUT FIELDS=3
Page 32
2011-12
EXPT NO :-9 Write and test a program to get the number of list items in a list /
combo box.
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;
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", "http://");
seleniumserver.start();
selenium.start();
}
@Test
public void testDropdowngoogle()throws Exception {
selenium.open("http://www.schools9.com/kdiploma11022011.htm");
selenium.waitForPageToLoad("3000");
String[] option = selenium.getSelectOptions("name=course");
File file = new File("C:/Dropdownvalues.xls");//excel
File file1 = new File("C:/Dropdownvalues.txt");//notepad
BufferedWriter out = new BufferedWriter(new FileWriter(file));//excel
BufferedWriter out1 = new BufferedWriter(new FileWriter(file1));//notepad
out.write("Options in drop down\n");//Excel
out1.write("Options in drop down\n");//notepad
for (int i = 0; i < option.length; i++) {
System.out.println("Option: " + i + " is" + option[i]);
out.write(""+option[i]);
B.T.Patil & Sons Polytechnic, Stavanidhi-Nipani, Dist: Belgaum.
Page 33
2011-12
out.newLine();
out1.write(""+option[i]);
out1.newLine();
}
out.close();//excel
out1.close();//notepad
}
@AfterClass
public void tearDown()throws Exception {
selenium.stop();
seleniumserver.stop();
}
}
OUTPUT
Page 34
2011-12
EXPT NO :-10 Write and test a program to count number of check boxes on the
page checked and unchecked count.
package testscripts;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;
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","http://");
seleniumserver.start();
selenium.start();
}
@Test
public void testDefaultTNG() throws Exception {
selenium.open("http://browsershots.org/");
selenium.windowMaximize();
//Count of check boxes
Number c =selenium.getXpathCount("//input[@type['checkbox']]");
System.out.println("Count of check boxes " +c);
//Number of check boxes checked
Number d = selenium.getXpathCount("//input[@type='checkbox' and
@checked]");
System.out.println("Count of Checked check boxes " +d);
//Number of check boxes unchecked
Number e = selenium.getXpathCount("//input[@type='checkbox' and
not(@checked)]");
System.out.println("Count of Checked check boxes " +e);
}
B.T.Patil & Sons Polytechnic, Stavanidhi-Nipani, Dist: Belgaum.
Page 35
2011-12
@AfterClass
public void tearDown() throws Exception {
selenium.stop();
seleniumserver.stop();
}
}
OUTPUT
Count of check boxes 127
Count of Checked check boxes 91
Count of Checked check boxes 36
Page 36