Software Testing Practical File
Software Testing Practical File
OF
(KCS751A)
(2022-2023)
List of Experiments
2 Using Selenium IDE, write a test suite containing minimum 4 test cases.
6 Write and test a program to update 10 student records into table into Excel file
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 ).
8 Writeandtestaprogram to providetotalnumberofobjectspresent
/ available on thepage .
9 Write and test a program to get the number of list items in a list / combo box.
10 Write and test a program to count number of check boxes on the page checked and
unchecked count.
EXPT NO :-1
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
Robust verification.
Automation Test Workflow
1. History of Selenium
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 -
JavaScript
DHTML
Frames
3. Selenium Components
– Selenium IDE
– Selenium Core
– Selenium RC
– Selenium Grid
3.1 Selenium IDE
• 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:
B. Toolbar
C. Menu Bar
D. Log/Reference/UI-Element/Rollup Pane
B. Toolbar: The toolbar contains buttons for controlling the execution of your test cases,
including a step feature for
C. Menu Bar:
File Menu: The File menu allows you to create, open and save test case and test suite
files.
Edit Menu: The Edit menu allows copy, paste, delete, undo and select all operations for
editing the commands in your test case.
Options Menu: The Options menu allows the changing of settings. You 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:
The command set is often called selenese. Selenium commands come in three “flavors”:
Actions, Accessory and Assertions.
Actions are commands that generally manipulate the state of the application.
2. Selecting items
b. Accessors: Accessors examine the state of the application and store the results in
variables, e.g. "storeTitle".
• assert
• verify
• waitFor
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.
verifyText - verifies expected text and it’s corresponding HTML tag are present on the page.
waitForElementPresent -pauses execution until an expected UI element, as defined by its HTML tag,
is present on the page.
Run a Test Case Click the Run button to run the currently displayed test case. 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.
Using Firefox, first, download the IDE from the SeleniumHQ downloads page Firefox will protect
you from installing addons from unfamiliar locations, so you 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.
EXPT NO:-2 Using Selenium IDE, Write a test suite containing minimum 4 test cases.
1. Create more Tc’s save each Test Case with <.html> extension.
2. Open Firefox
Manual Steps:
TC#2:
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"
1. Create more Tc’s save each Test Case with <.html> extension.
2. Open Firefox
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.
EXPT NO :-4 Install Selenium server and demonstrate it using a script in Java/PHP
Download Eclipse
1. Go to URL – http://www.eclipse.org/downloads/
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 Eclipse.exe and
then click on “desktop create shortcut”) as demonstrated in the below pictures.
Now we need to create a workspace folder –> C:Eclipse- WorkspaceSeleniumTests
1. Double click on “Eclipse shortcut on Desktop”
2. This opens the Eclipse
3. Close Eclipse welcome screen
4. Click File menu –> Switch Worspace –> other
5. 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
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
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
Before you start with your script, the following are the steps that should be performed.
Method1: Extending the Selenese Test Case
7. Click 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.
@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();
}
}
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...).
• Test that your code is multithread safe.
• Flexible test configuration.
• Support for data-driven testing (with @DataProvider).
• Support for parameters.
• Powerful execution model (no more TestSuite).
• Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc...).
• Embeds BeanShell for further flexibility.
• Default JDK functions for runtime and logging (no dependencies).
• Dependent methods for application server testing.
TestNG is designed to cover all categories of tests: unit, functional, end-to-end, integration,
etc...
• Click on “Run as TestNG Suite” and your test will start running. You will then see this
nice results tree:
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.
Jxl.jar 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)
Add import statements to the .java file as below to read from an Excel spreadsheet import jxl.Cell;
jxl.Workbook;
import jxl.read.biff.BiffException;
EXPT NO :-6 Write and test a program to update 10 student records into table into Excel
file .
@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++)
{
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 ).
@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);
if( x < 60)
{
c++;
break;
}
}
}
}
wwb.write();
wwb.close();
}
}
INPUT
OUTPUT
EXPT NO :-8 Write and test a program to provide total number of objects present
/ available on thepage .
package testscripts;
import com.thoughtworks.selenium.*; import
org.openqa.selenium.server.*; import
org.testng.annotations.*;
@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);
}
}
OUTPUT
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]);
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
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.*;
@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);
}
@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