Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

ST Lab Manual PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 55

Software Testing Lab manual 2017-18

SOFTWARE TESTING
LAB MANUAL
RJS Polytechnic, Koramangala

According to DTE Syllabus 2015-16


Software Testing Lab

Vinayaka V.M.
vmvinayaka@gmail.com
SOFTWARE TESTING LAB MANUAL

SOFTWARE TESTING LAB MANNUAL


6th SEM COMPUTER SCIECNCE
(2017-18)

By
Mr. Vinayaka V.M. M.Tech.

Computer Science and Engineering Department


RJS Polytechnic, Koramangala, Bengaluru

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 1


SOFTWARE TESTING LAB MANUAL

EXERCISE 01

1. Understand the Automation Testing Approach (Theory Concept) Introduction:

Introduction:

What is Automation?
- Automation is making a process automatic, eliminating the need for human intervention.
- Is a self-controlling or self-moving process.
- Automation software offers automation wizard and commands of its own in addition to
providing task recording and re-play capabilities.
- Using these tools we can record the task
- Then if needed use the editor to edit the task, add new commands or using GUI
automation wizards

Benefits of Automation

Fast: Test automation runs faster than human users

Reliable: It performs precisely the same operations at each time elimination human errors

Repeatable: It performs the same operation with different combination of data in a less time

Programmable: We can use sophisticated tests that brings out hidden information

Reusable: We can develop reusable components which can run on different versions of
application under test

Regression testing: Easy to conduct regression test

Enabling 24*7 testing: test can be schedule and supports unattended recovery

Robust Verification: Support robust verification mechanism than any other testing tools

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 2


SOFTWARE TESTING LAB MANUAL

What Tests should be Automated?

• Tests executed for each software build

• tests which can be easily automated

• Business critical tests

• tests that are difficult to perform manually

Test artefacts (tools):


Requirements: the requirements that are being tested are stored into the repository. This
feature enables us to map the requirements to test cases and test scripts.

Test Plan: Design the tests and build the test plan on it using the test management tool. The
test plan will be maintained in a central repository. This will help to produce reusable tests
cases in future. The information is sharable and preserved.

Test case: Contains description of test case and test steps.

Test script: Automated test script associated with each test case will be stored in the quality
centre repository.

Test sets: this will be a set of selected test cases and associated test scripts. The tests sets are
executed from the quality centre onto remote machines. The status of each execution is stored
in the respective test case execution status. The status can be either pass/fail, it doesn.t
maintain exact details of execution.

Test logs: The test script execution logs are stored in global repository. It contains the status
of each test case.

Reusable components: The repetitive functions that are invoked in most of the functions are
stored, which reduces the coding redundancies.

Object repository: contains the declaration of the application objects. Data sheets: contains
the test data used for execution. it can be populated by the database or manually.

Automation Activity:
Record the application GUI Write Script Execute script Review the script Modify script if
any changes. Execute scripts on at least two machines Store the script in central repository
Execute the script from central repository Verify the execution status in central repository
Verify the test logs on common server Prepare the test reports

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 3


SOFTWARE TESTING 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 -
- JavaScript
-DHTML
-Frames
3. Selenium Components
– Selenium IDE
– Selenium Core
– Selenium RC
– Selenium Grid
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
Overview of Selenium IDE:
A.Test Case Pane
B.Toolbar
C.Menu Bar
D.Log/Reference/UI-Element/Rollup Pane

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 4


SOFTWARE TESTING LAB MANUAL

A. Test Case Pane:


• Your script is displayed in the test case pane.
• It has two tabs.
• one for displaying the command (source)
• and their parameters in a readable “table” format.

B. Toolbar:
The toolbar contains buttons for controlling the execution of your test cases.
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:
It has help information.

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:
• assert
• verify
• waitFor
Example: "assertText","verifyText" and "waitForText".

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 5


SOFTWARE TESTING LAB MANUAL

NOTE:
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.

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.

Running Test Cases


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 start point, select a command, right-click, and from
the context menu select Set/Clear Start Point.

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 6


SOFTWARE TESTING LAB MANUAL

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.

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 7


SOFTWARE TESTING LAB MANUAL

EXCERCISE 02

2. Using Selenium IDE, Write a test suite containing minimum 4 test cases.

Requirements

• Download Selenium IDE 1.5 or above addon for firefox from http://seleniumhq.org/download/
Or http://addons.mozilla.org/ from firefox browser.
• The webpage used in this example is a java Script program ‘Menu Driven Arithmetic Operations’
• A java Script for Arithmetic operation.

• Firefox version 10.0

Procedure:-

• Type the html code in notepad and save as arithmetic.html


• Open Firefox browser select toolsweb developerselenium IDE
• Click on Start recording minimize the selenium window
• Run the Arithmetic program by giving values
• Execution will be recorded in the Selinium IDE
• In Selenium IDE, test cases and test suites will be generated.

Java script to develop a web page for Arithmetic Operations. Save this file on desktop and
save as arithmetic.html

<html>
<head>
<title> Arithmatic Operation </title>
<script type="text/javascript">
var n1,n2,r;
function add()
{
n1=document.myform.n1.value;
n2=document.myform.n2.value;
n1=parseFloat(n1);
n2=parseFloat(n2);
r=n1+n2;
document.myform.result.value=r;
}

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 8


SOFTWARE TESTING LAB MANUAL

function sub()
{
n1=document.myform.n1.value;
n2=document.myform.n2.value;
n1=parseFloat(n1);
n2=parseFloat(n2);
r=n1-n2;
document.myform.result.value=r;
}
function mul()
{
n1=document.myform.n1.value;
n2=document.myform.n2.value;
n1=parseFloat(n1);
n2=parseFloat(n2);
r=n1*n2;
document.myform.result.value=r;
}
function divide()
{
n1=document.myform.n1.value;
n2=document.myform.n2.value;
n1=parseFloat(n1);
n2=parseFloat(n2);
r=n1/n2;
document.myform.result.value=r;
}
</script>
</head>
<body>
<form name="myform">
<h1 align="center"> Arithmatic Operations</h1> <hr color="red"> <center>
<u>Enter a number in each text box </u>
<br><br>
Number 1:<input type="text" name="n1" value="">
<br><br>
Number 2:<input type="text" name="n2" value="">
<br><br>
<input type="button" value="Add" onClick="add()">

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 9


SOFTWARE TESTING LAB MANUAL

<input type="button" value="Subtract" onClick="sub()">


<input type="button" value="Multiply" onClick="mul()" >
<input type="button" value="Divide" onClick="divide()">
<br><br>
<font color="red">Result is: <input type="text" name="result" value="">
</center>
</font>
</form>
</body>
</html>

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 10


SOFTWARE TESTING LAB MANUAL

OUTPUT:

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 11


SOFTWARE TESTING LAB MANUAL

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 12


SOFTWARE TESTING LAB MANUAL

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 13


SOFTWARE TESTING LAB MANUAL

EXERCISE 03

3.Understanding Test Automation. Using Selenium write a simple test script to validate
each field of the registration page ( Eg: Face book Registration Page)

Requirements:
• Download Selenium IDE 1.5 or above from http://seleniumhq.org/download/ from
Firefox browser.
• A html Script for Registration form.
• Firefox version 10.0.
Procedure:-
Type this code in notepad and save on desktop

<html>
<body>
<form tag="Create Logon">
<div align="center">
Username *: <input type="username" name="username" /><br />
Password *: <input type="password" name="pwd" /><br />
Surname *: <input type="surname" name="surname" /><br />
Other Names *: <input type="other names" name="names" /><br />
Date of Birth *: <input type="date of birth" name="dob" /><br />
Email *: <input type="email" name="email" /><br />
Telephone: <input type="telephone" name="tel" /><br />
Address *: <input type="address" name="add" /><br />
Post Code *: <input type="postcode" name="ptc" /><br />
<input type="submit" value="Submit" />
</div>
</form>
<p>Note: Please make sure your details are correct before submitting form and that all fields marked with *
are completed!.</p>
</body>
</html>

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 14


SOFTWARE TESTING LAB MANUAL

Test program to be typed in selenium IDE: Select source tab in selenium and type

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 15


SOFTWARE TESTING LAB MANUAL

Test program to be typed in selenium IDE:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://change-this-to-the-site-you-are-testing/" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead>

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 16


SOFTWARE TESTING LAB MANUAL

<tbody>
<tr>
<td>open</td>
<td>file:///C:/Users/RJSPL112/Desktop/reg.html</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>name=username</td>
<td>Vinayaka</td>
</tr>
<tr>
<td>type</td>
<td>name=pwd</td>
<td>vinaaa</td>
</tr>
<tr>
<td>type</td>
<td>name=surname</td>
<td>vm</td>
</tr>
<tr>
<td>type</td>
<td>name=names</td>
<td>vinay</td>
</tr>
<tr>
<td>type</td>
<td>name=dob</td>
<td>24-08-1985</td>
</tr>
<tr>
<td>type</td>
<td>name=email</td>
<td>vinayakavm@gmail.com</td>
</tr>
<tr>
<td>type</td>
<td>name=tel</td>
<td>9191919191</td>
</tr>
<tr>
<td>type</td>
<td>name=add</td>
<td>villa 4th cross venkatapura</td>
</tr>
<tr>
<td>type</td>
<td>name=ptc</td>
<td>560034</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>css=input[type=&quot;submit&quot;]</td>

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 17


SOFTWARE TESTING LAB MANUAL

<td></td>
</tr>

</tbody>
</table>
</body>
</html>

EXERCISE 04
4. Install Selenium server and demonstrate it using a script in Java/PHP.
Requirements:
• Download the following :

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 18


SOFTWARE TESTING LAB MANUAL

selenium-server-standalone-2.32.0 selenium-java-client-driver from


http://seleniumhq.org/download/ save these 2 jar files under
C:\Program Files (x86)\java\jdk1.6.0\bin
(You can use jdk6 and above versions of java)
• Download ‘Eclipse IDE for java developers’ from http://www.eclipse.org/downloads/.
This is not an installable file. So just copy the file under C: drive. whenever you need to
write test code in eclipse just double click on the eclipse application inside the eclipse
folder.
• Firefox version 10 is required.

Procedure:-
• Type the html code in the notepad and save that as GCD.html
• Open eclipse application  give the folder name where you want to store your files. the
default will be ‘ workspace ‘
• Then go to filenewjava project.
• You will get Create java project window , Name the project to st  click finish. Double
click on the new project st on the package explorer  you will get src folder and JRE
System Library
• Right click on the src foldergo to newclick on the class  you will get new java class
window name the class as Gcd  click finish. After writing this code if u get red lines
under the selenium then include the selenium-server-standalone-2.32.0.jar and selenium-
java-clientdriver.jar files
• The steps are :
• Right click on the st folder  click on properties  click on Java Build path  then
select the libraries tab  click on Add External JARs  browse for selenium-
serverstandalone-2.32.0.jar  click open  again click on Add External JARs 
browse for selenium-java-clientdriver.jar  click open  click ok.
• To run the above program
First open the command prompt, go to the C:\Program Files (x86)\java\jdk1.6.0_25\bin
folder ->run/write the command java –jar selenium-server-standalone-2.32.0.jar 4444
• Click on run button in eclipse the output will be displayed the console.

Java script to develop a web page which calculates the GCD of 2 numbers. Save this file on desktop and
save as GCD.html

<html>
<head>

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 19


SOFTWARE TESTING LAB MANUAL

<script type="text/javascript">
function gcd()
{
var x,y;
x=parseInt(document.myform.n1.value);
y=parseInt(document.myform.n2.value);
while(x!=y)
{
if(x>y)
x=x-y;
else
y=y-x;
}
document.myform.result.value=x;
}
</script>
</head>
<body>
<h1 align="center"> Program to calculate gcd of two numbers </h1> <hr color="red">
<center> Enter two numbers : <form name="myform">
Number 1 : <input type="text" name="n1" value=""> <br> <br>
Number 2 : <input type="text" name="n2" value=""> <br> <br>
<input type="button" value="Get GCD" onClick="gcd()"> <br> <br>
GCD is : <input type="text" name="result" value="">
</form>
</body>
</html>
Java test script for testing the GCD webpage. (write this code in eclipse environment).

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@SuppressWarnings("deprecation")
Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 20
SOFTWARE TESTING LAB MANUAL

public class GcdTest extends SeleneseTestCase {


@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium ("localhost", 4444, "*firefox",
"file:///C:/Users/RJSP/Desktop/GCD.html");
selenium.start();
}

@Test
public void testGcd() throws Exception {
selenium.setSpeed("2000");
selenium.open("file:///C:/Users/RJSP/Desktop/GCD.html");
selenium.windowMaximize();
selenium.type("name=n1", "5");
selenium.type("name=n2", "6");
selenium.click("css=input[type=\"button\"]");
String result = selenium.getValue("name=result");
System.out.println("the gcd is : " +result);
}

@After
public void tearDown() throws Exception {
selenium.stop();
}
}

Write the Above code in eclipse by following the below steps

• Open eclipse application-> give the folder name where you want to store your files. the default will be
‘ workspace ‘

• Then go to file new java project.

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 21


SOFTWARE TESTING LAB MANUAL

• You will get Create java project window , Name the project to st click finish.

• Double click on the new project st on the package explorer

• you will get src folder and JRE System Library

• right click on the src folder go to new click on the class

• you will get new java class window, name the class as GcdTest

• click finish.

Note: Make sure that the path of your GCD.html file must be correct , in this example it is
file:///C:/Users/RJSP/Desktop/GCD.html
After writing this code if you get red lines under the selenium then include the selenium-server-standalone-2.32.0.jar
and selenium-java-clientdriver.jar files.
The steps are : Right click on the st folder click on propertiesclick on Java Build path then select the libraries
tab  click on Add External JARs  browse for
selenium-server-standalone-2.32.0 click open again click on Add External JARs  browse for
selenium-java-clientdriver  click open  click ok.
To run the above program

• First open the command prompt

• go to the jdk1.6.0_26\bin folder

• run/write the command


java –jar selenium-server-standalone-2.32.0.jar 4444

Then click on run button in eclipse

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 22


SOFTWARE TESTING LAB MANUAL

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 23


SOFTWARE TESTING LAB MANUAL

EXERCISE 05
5. Conduct a test suite for any two web sites.

Requirements:

• Download Selenium IDE 1.5 or above from http://seleniumhq.org/download/ from


Firefox browser.
• Firefox version 10.0
• Internet connection is required.

Procedure:-
• Open firefox browser-> select tools->web developer->selenium IDE.
• Click on Start recording ->minimize the selenium window.
• Visit any website save testcase
• Create new testcase visit another website save testcase.
• Click on play entire test suite button in the selenium IDE.

TC’S #1: Manual Steps:


• Open (Example : Type www.google.com)
• 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 http://www.sretravels.com
3: Close advertisementselect source and destination cities
4: Click on the date  select today’s date  click on search button
5: Wait for Search Results to come
6: Stop recording.
7. Save the test case as sretravels.

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 24


SOFTWARE TESTING LAB MANUAL

Steps for creating test suite:


1. Create more Test Cases save each Test Case.
2. Open Firefox
3. Open Tools Selenium IDE
4. File Open new Test Suite
5. File Open Add Test cases
6. Add test cases you just created (at least two)
7. click FileSave Suite.
8. Run the test suite

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 25


SOFTWARE TESTING LAB MANUAL

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 26


SOFTWARE TESTING LAB MANUAL

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 27


SOFTWARE TESTING LAB MANUAL

EXERCISE 06

6. Write and test a program to login a specific web page.


Requirements:
• Write this java test code in eclipse.
• Before running this code makes sure your selenium RC server is running
• First open the command prompt, go to the C:\Program Files (x86)\java\jdk1.6.0_25\bin folder ->run/write
the command java –jar selenium-server-standalone-2.32.0.jar 4444

Procedure:-
• Open eclipse application  give the folder name where you want to store your files. the
default will be ‘ workspace ‘
• Then go to filenewjava project.
• You will get Create java project window , Name the project to st  click finish.
• Double click on the new project st on the package explorer  you will get src folder
and JRE System Library
• Right click on the src foldergo to newclick on the class you will get new java
class window name the class as Login click finish.

• Type in the java code in that Login.java file


• After writing this code if you get red lines under the selenium then include the selenium
server and selenium java driver jar file. The steps are :
• Right click on the st folder click on properties click on Java Build path then select
the tab librariesclick on Add External JARs browse for
selenium-serverstandalone-2.32.0click openagain click on Add External JARs
browse for selenium-java-clientdriverclick open click ok.
• To run the above program
First open the command prompt
Go to the C:\Program Files (x86)\java\jdk1.6.0_26\bin folder  run/write the command
java –jar selenium-server-standalone-2.32.0.jar 4444
• Click on run the output will be displayed the console

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 28


SOFTWARE TESTING LAB MANUAL

import com.thoughtworks.selenium.*;
@SuppressWarnings("deprecation")
public class login extends SeleneseTestCase
{
public void setUp() throws Exception
{
setUp("http://php.thedemosite.co.uk/","*firefox");
}
public void testloginlogout()
{
selenium.setSpeed("2000");
selenium.open("/login.php");
selenium.windowMaximize();
selenium.type("//input[@name='username']", "mytest");
selenium.type("//input[@name='password']", "mytest");
selenium.click("//input[@type='button']");
selenium.waitForPageToLoad("50000"); }
}

OUTPUT:

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 29


SOFTWARE TESTING LAB MANUAL

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 30


SOFTWARE TESTING LAB MANUAL

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 31


SOFTWARE TESTING LAB MANUAL

EXERCISE 06
06.Write test cases to validate a mobile number using one-time pin identification
(OTP)

Requirements :

• Download Selenium IDE 1.5 or above from http://seleniumhq.org/download/ from


Firefox browser.
• Firefox version 10.0
• Internet connection required.

Test Cases for OTP:

1) OTP should be generated within time period.

2) Limitations of number of OTP generation for single authentication.

3) It is received only on registered Mobile Number / E-mail Address.

4) Network delay for expiry of One-Time Password.

5) Verify that once expired, it should not be used for any authentication.

6) Verify that once used, it should not be allowed to use again.

7) Verify that resend OTP functionality is working properly.

8) Verify that once user resent the OTP, the old one should be of no use.

9) How many times user can provide invalid OTP?

10) Provide an invalid Phone Number or E-Mail address and submit the OTP. Check the validation.

To verify mobile number using OTP in google account:


1. Visit Google's 2-Step Verification page and click on Get Started.
2. Enter your Google email and password (or just your password, if you're already logged in to Google).
3. Click the Start setup button.
4. Add a phone number that Google can send the six-digit verification code to. (For semi-obvious
reasons, this shouldn't be your Google Voice number: If you use that phone number, you might end up
locked out of your account.)

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 32


SOFTWARE TESTING LAB MANUAL

9191919191

5. Verify your phone number by entering in the six-digit code Google sent you.

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 33


SOFTWARE TESTING LAB MANUAL

6. Choose not to add your current computer as a trusted device.

7. Confirm that you wish to turn on two-step verification.

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 34


SOFTWARE TESTING LAB MANUAL

8. Now open firefox 10.0  start selenium ide … by default recording will be on.
9. Open gmail.com  input phone number in the text box present for entering email id / phone number.
10. Click next
11. Enter password
12. Click next
13. Now system will ask to enter an OTP which is sent to your mobile number.
14. See the message you got to your mobile and enter the OTP in the text box.
15. Uncheck the check box button for remember this computer.
16. Click next
17. Now click on signout
18. Stop recording.
19. Now play the test case.
20. You should get a failure because OTP can be used only one time.

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 35


SOFTWARE TESTING LAB MANUAL

EXERCISE 08

8. Write and Test a program to find out list of employees having salary greater than
₹ 50,000 and age between 30 to 40 years.

Requirements:

• Write this java test code in eclipse. Since we are not using any Selenium object here no
need of selenium RC Server to run at the command prompt for this program.
• Since we are dealing with the excel, we need to add the external jar file jxl-2.6 in to the
java project.
• Download jxl-2.6.jar and past it in C:\Program Files (x86)\java\jdk1.6.0_25\bin and
Follow the same steps as we used to add selenium server and selenium java driver to our
java project.

Procedure:-
• Create the Microsoft excel document containing the name of employees and their salary
details in the Microsoft excel and save that file as Emp.xls
• Open eclipse application give the folder name where you want to store your files. The
default workspace will be ‘ workspace ‘
• Then go to filenewjava project.
• You will get Create java project window, Name the project to st  click finish. Double
click on the new project st on the package explorer  you will get src folder and JRE
System Library
• Right click on the src foldergo to newclick on the class you will get new java
class window name the class as Emp  click finish.

• Type in the java code in that Emp.java file


• After writing this code if u get red lines under the selenium then include the selenium
server and selenium java driver jar file. The steps are:
• Right click on the st folder click on properties click on Java Build path then select
the tab librariesclick on Add External JARs browse for jxl-2.6.jar
• Click open  Click ok.
• Click on run in eclipse, the output will be displayed the console.

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 36


SOFTWARE TESTING LAB MANUAL

import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class Emp
{
private String inputFile;
public void setInputFile(String inputFile)
{
this.inputFile = inputFile;
}
public void read() throws IOException
{
File inputWorkbook = new File(inputFile);
Workbook w;
boolean flag=false;
boolean flag2=false;
int count=0;
try
{
w = Workbook.getWorkbook(inputWorkbook);
Sheet sheet = w.getSheet(0);
for (int j = 0; j < sheet.getRows(); j++)
{
for (int i = 0; i < sheet.getColumns(); i++)
{
Cell cell = sheet.getCell(i, j);
if (cell.getType() == CellType.NUMBER)
{
if(Integer.parseInt(cell.getContents())>50000)
{
flag = true;

}
}

if (cell.getType() == CellType.NUMBER)
{
if(Integer.parseInt(cell.getContents())>30 && Integer.parseInt(cell.getContents())< 40)
{
flag2 = true;
if(flag == true && flag2==true)

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 37


SOFTWARE TESTING LAB MANUAL

{
count++;

}
break;
}
}
}
}
System.out.println("Total number of employees having salary greater than ₹ 50,000 and age between 30 to
40 years: " +count);
}
catch (BiffException e)
{
e.printStackTrace();
}
}
public static void main(String[ ] args) throws IOException
{
Emp test = new Emp();
test.setInputFile("C:/Users/RJSP/Desktop/Emp.xls");
test.read();
}
}

INPUT FILE : Located in “C:/Users/RJSP/Desktop/Emp.xls”

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 38


SOFTWARE TESTING LAB MANUAL

OUTPUT:

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 39


SOFTWARE TESTING LAB MANUAL

EXERCISE 09
9. Write and test a program to update 10 student records into table into Excel file.

• Write this java test code in eclipse. Since we are not using any Selenium object here no
need of selenium RC Server to run at the command prompt for this program.
• This program will create an Excel file Student.xls under the desktop.
• Since we are dealing with the excel, we need to add the external jar file jxl-2.6 in to the
java project.
• Download jxl-2.6 and Follow the same steps as we used to add selenium server and
selenium java driver to our java project.

Procedure:-
• Create the blank excel document in the Microsoft excel and save that file as Student.xls
• Open eclipse application give the folder name where you want to store your files. The
default will be ‘ workspace ‘
• Then go to filenewjava project.
• You will get Create java project window , Name the project to st  click finish. Double
click on the new project st on the package explorer  you will get src folder and JRE
System Library
• Right click on the src foldergo to newclick on the class you will get new java
class window name the class as Student click finish.

• Type in the java code in that Student.java file


• After writing this code if u get red lines under the selenium then include the selenium
server and selenium java driver jar file. The steps are:
• Right click on the st folder click on properties click on Java Build path then select
the tab librariesclick on Add External JARs browse for jxl-2.6.jar file Click
open Click ok.
• Click on run button in eclipse, the output will be displayed the console.

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 40


SOFTWARE TESTING LAB MANUAL

import java.io.File;
import java.io.IOException;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class Stdrec
{
private String inputFile;
public void setOutputFile(String inputFile)
{
this.inputFile = inputFile;
}
public void write() throws IOException, WriteException
{
File file = new File(inputFile);
WritableWorkbook workbook = Workbook.createWorkbook(file);
workbook.createSheet("Report", 0);
WritableSheet excelSheet = workbook.getSheet(0);
createLabel(excelSheet);
createContent(excelSheet);
workbook.write();
workbook.close();
}

private void createLabel(WritableSheet sheet) throws WriteException


{
addCaption(sheet, 0, 0, "Name");
addCaption(sheet, 1, 0, "Subject 1");
addCaption(sheet, 2, 0, "Subject 2");
addCaption(sheet, 3, 0, "Subject 3");
}
private void createContent (WritableSheet sheet) throws WriteException, RowsExceededException
{
// Write a few number
for (int i = 1; i <10; i++)
{
// First column
addLabel(sheet, 0, i, "Student " + i);
// Second column
addNumber(sheet, 1, i, ((i*i)+10));
addNumber(sheet, 2, i, ((i*i)+6));

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 41


SOFTWARE TESTING LAB MANUAL

addNumber(sheet, 3, i, ((i*i)+8));
}
}
private void addCaption(WritableSheet sheet, int column, int row, String s) throws
RowsExceededException, WriteException
{
Label label;
label = new Label(column, row, s);
sheet.addCell(label);
}
private void addNumber(WritableSheet sheet, int column, int row,Integer integer) throws
WriteException, RowsExceededException
{
Number number;
number = new Number(column, row, integer);
sheet.addCell(number);
}
private void addLabel(WritableSheet sheet, int column, int row, String s) throws WriteException,
RowsExceededException
{
Label label;
label = new Label(column, row, s);
sheet.addCell(label);
}
public static void main(String[ ] args) throws WriteException, IOException {
Stdrec test = new Stdrec();
test.setOutputFile("C:/Users/RJSP/Desktop/Student.xls");
test.write();
System.out.println("Please check the result file under C:/Users/RJSP/Desktop/Student.xls");
}
}

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 42


SOFTWARE TESTING LAB MANUAL

OUTPUT:

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 43


SOFTWARE TESTING LAB MANUAL

EXERCISE 10
10.Write and test a program to select the number of students who have scored more
than 60 in any one subject (or all subjects).

Requirements :

• Write this java test code in eclipse. Since we are not using any Selenium object here no
need of selenium RC Server to run at the command prompt for this program.
• Since we are dealing with the excel, we need to add the external jar file jxl-2.6 in to the
java project.
• Download jxl-2.6 and Follow the same steps as we used to add selenium server and
selenium java driver to our java project.

Procedure:

• Create the excel document containing the details about the students and their marks in
the Microsoft excel and save that file as Student.xls
• Open eclipse application give the folder name where you want to store your files. the
default will be ‘ workspace ‘
• Then go to filenewjava project.
• You will get Create java project window , Name the project to st  click finish. Double
click on the new project st on the package explorer  you will get src folder and JRE
System Library
• Right click on the src foldergo to newclick on the class you will get new java
class window name the class as Student click finish.

• Type in the java code in that Student.java file


• After writing this code if u get red lines under the selenium then include the selenium
server and selenium java driver jar file. The steps are:
• Right click on the st folder  click on properties  click on Java Build path then
select the tab librariesclick on Add External JARs browse for
jxl-2.6.jar file Click open  Click ok.
• Click on run the run button in eclipse, output will be displayed the console.

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 44


SOFTWARE TESTING LAB MANUAL

import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class student_excel_read
{
private String inputFile;
public void setInputFile(String inputFile)
{
this.inputFile = inputFile;
}
public void read() throws IOException
{
File inputWorkbook = new File(inputFile);
Workbook w;
boolean flag=false;
int count=0;
try
{
w = Workbook.getWorkbook(inputWorkbook);
Sheet sheet = w.getSheet(0);
for (int j = 0; j < sheet.getRows(); j++)
{
for (int i = 0; i < sheet.getColumns(); i++)
{
Cell cell = sheet.getCell(i, j);
if (cell.getType() == CellType.NUMBER)
{
if(Integer.parseInt(cell.getContents())>60)
{
flag = true;
if(flag == true)
{
count++;
flag=false;
} break;
}
}
}
}
System.out.println("Total number of students who scored more than 60 in one or
more subjects is: " +count);
}

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 45


SOFTWARE TESTING LAB MANUAL

catch (BiffException e)
{
e.printStackTrace();
}
}
public static void main(String[ ] args) throws IOException
{ student_excel_read test = new student_excel_read();
test.setInputFile("C:/Users/vmvin/Desktop/Student.xls");
test.read();
}
}

INPUT:

OUTPUT :

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 46


SOFTWARE TESTING LAB MANUAL

EXERCISE 11

11. Write and test a program to provide total number of objects present / available on
the page.

Requirements:

• Write this java test code in eclipse. before running this code makes sure your selenium
RC server is running
• Firefox version 10.0 required.
• Internet access required.

Procedure:-
• Write the Above code in eclipse by following the below steps
• Open eclipse application give the folder name where you want to store your files
the default will be ‘workspace ‘Then go to filenewjava project.
• You will get Create java project window Name the project to st click finish.
• Double click on the new project st on the package explorer you will get src folder and
JRE System Library
• Right click on the src foldergo to newclick on the class  you will get new java
class window name the class as Obj  click finish.
• After writing this code if u get red lines under the selenium then include the selenium
server and selenium java driver jar file. The steps are:
• Right click on the st folderclick on properties click on Java Build paththen select
the tab libraries click on Add External JARsbrowse for
selenium-serverstandalone-2.32.0Click open again click on Add External JARs
browse for selenium-java-clientdriver
• click open-> click ok->To run the above program
• First open the command prompt-> go to the C:\Program Files (x86)\java\jdk1.6.0_26\bin
folder run/write the command java –jar selenium-server-standalone-2.32.0.jar 4444
• The number of objects available on the web page will be displayed as output in the
console when you click run button in eclipse.

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 47


SOFTWARE TESTING LAB MANUAL

import com.thoughtworks.selenium.*;
@SuppressWarnings("deprecation")
public class objectcount extends SeleneseTestCase
{
public void setUp() throws Exception {
setUp("http://www.wikipedia.org/","*firefox");
}
public void testloginlogout()
{
selenium.setSpeed("1000");
selenium.open("www.wikipedia.org/Gmail");
selenium.waitForPageToLoad("30000");
selenium.windowMaximize();
int num = selenium.getXpathCount("//p").intValue();
System.out.println("The number of option elements present are " +num);
}
}

OUTPUT:

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 48


SOFTWARE TESTING LAB MANUAL

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 49


SOFTWARE TESTING LAB MANUAL

EXERCISE 11
11. Write and test a program to get the number of list items in a list / combo box.

Requirements:

• Write this java test code in eclipse. before running this code makes sure your selenium
RC server is running)
• Write Combocount.html as shown below and save under desktop.

Procedure:-
• Type the html code in notepad and save that as combo.html
• Open eclipse application give the folder name where you want to store your files. The
default will be ‘ workspace ‘
• Then go to filenewjava project.
• You will get Create java project window , Name the project to st  click finish. Double
click on the new project st on the package explorer  you will get src folder and JRE
System Library
• right click on the src foldergo to newclick on the class you will get new java class
window name the class as Comboitemcount click finish.

• Type in the java code in that Comboitemcount.java file


• After writing this code if u get red lines under the selenium then include the selenium
server and selenium java driver jar file. The steps are:
• Right click on the st folder click on properties click on Java Build path then select
the tab librariesclick on Add External JARs browse for
selenium-serverstandalone-2.32.0click openagain click on Add External JARs
browse for selenium-java-clientdriverclick open click ok.
• To run the above program
• First open the command prompt go to the jdk1.6.0_26\bin folder run/write the
command java –jar selenium-server-standalone-2.32.0.jar 4444
• Click on run in eclipse, the output will be displayed the console.

<html>
<body>
<select>
<option>Volvo</option>
<option>Express</option>
<option>Mercedes</option>
<option>Lamborghini</option>
Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 50
SOFTWARE TESTING LAB MANUAL

</select>
</body>
</html>

• Write the below code in eclipse

import com.thoughtworks.selenium.*;
public class Comboitemcount extends SeleneseTestCase
{
public void setUp() throws Exception
{
selenium = new DefaultSelenium("localhost", 4444,
"*chrome","file:///C:/combocount.html");
selenium.start();
}
public void testloginlogout()
{
selenium.setSpeed("1000");
selenium.open("file:///C:/combo.html");
selenium.waitForPageToLoad("30000");
selenium.windowMaximize();
String[] selectelements = new String[1000];
selectelements= selenium.getSelectOptions("//select");
System.out.println("The number of options present in the given select box is "
+selectelements.length); }
}

OUTPUT:

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 51


SOFTWARE TESTING LAB MANUAL

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 52


SOFTWARE TESTING LAB MANUAL

EXERCISE 13
13. Write and test a program to count number of items present on a desktop.

Requirements:

• Write this java test code in eclipse. Since we are not using any Selenium object here no
need of selenium RC Server to run at the command prompt for this program.
• Write a visual basic script with the following code and save as count.vbs under the
desktop.
Procedure:-
• Type the visual basics code in the notepad and save that as count.vbs
• Write the Above code in eclipse by following the below steps
• Open eclipse application give the folder name where you want to store your files-the
default will be ‘workspace ‘Then go to filenewjava project.
• You will get Create java project window Name the project to st click finish.
• Double click on the new project st on the package explorer you will get src folder and
JRE System Library
• Right click on the src foldergo to newclick on the class  you will get new java
class window name the class as desktop_item_count click finish.
• Click on run button in eclipse, the output will be displayed in an alert box.

• Type the below code in notepad and save as count.vbs

Set fso = createobject("Scripting.FileSystemObject")


DesktopPath = CreateObject("WScript.Shell").SpecialFolders("Desktop")
'Files count
msgbox "The number of files on the desktop is : "&fso.GetFolder(DesktopPath).Files.Count
'Folders count msgbox "The number of folders on the desktop is : "&fso.GetFolder(DesktopPath)
.SubFolders.Count

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 53


SOFTWARE TESTING LAB MANUAL

• Write the below code in eclipse

import java.io.*;
public class desktop_item_count
{
public static void main(String[ ] args)
{
try
{
Runtime.getRuntime().exec("wscript C:/Users/vmvin/count.vbs");
}
catch (IOException e)
{
System.exit(0);
}
}
}

Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 54

You might also like