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

UNIVERSAL COLLEGE

OF ENGINEERING AND TECHNOLOGY


VALLIOOR, TIRUNELVELI - 627117

CCS366

SOFTWARE TESTING AND AUTOMATION LAB


(LABORATORY MANUAL)

(R-2021)

VI SEMESTER

DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING

Prepared by: M.R.GEETHA Asst. Professor/CSE


VISION

To serve the young minds by providing Quality Professional education in Engineering and
Technology.

MISSION

To render the quality professional education through a Learner - Centric approach to empower the
students in professional ethics, social responsibilities and enabling the students to meet the challenges
in thefield of Engineering and Technology.

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

VISION

To become a centre of learning by focusing on the emerging trends in the fields of Computer Science
and Engineering.

MISSION

To impart quality technical education through an effective Learner -Centric approach with Modern Tool Usage,
to meet the challenges in the field of Computer Science and Engineering.
PROGRAM EDUCATIONAL OBJECTIVES (PEOs)

1. Fundamentals

To impart students with fundamental knowledge in Mathematics, Science and fundamentals


of Engineering that will would them to be successful professionals

2. Core Competence

To provide students with sound knowledge in engineering and experimental skills to identify
complex software problems in industry and to develop practical solution for them

3. Breadth

To provide relevant training and experience to bridge the gap between theory and practice
this enables to find solutions for real time problem in industry and organization and to design
products requiring interdisciplinary skills

4. Professionalism skills

To bestow students with adequate training and provide opportunities to work as team that will
build up their communication skills, individual leadership and supportive qualities and to
develop them to adapt and work in ever changing technologies

5. Lifelong Learning

To develop the ability of students to establish themselves as professionals in Computer


Science and Engineering and to create awareness about the need for lifelong learning and
pursuing advanced degrees.
PROGRAM SPECIFIC OUTCOME (PSOs)

PSO 1: To become technology-oriented by applying the programming knowledge to analyse,


design and develop creative solutions in the area of Programming, Software development,
Networking and things that human minds cannot interpret.

PSO 2: To build up programming, analytical and logical thinking abilities by using creative
graphic tools and deep learning.

PSO 3: To gain ability to communicate scientific information in a clear and concise manner
which will be reliable and interpretable for the forthcoming opportunities and limitation through
lifelong learning that is beyond our knowledge.

PROGRAM OUTCOMES (POs)

a) To demonstrate and apply knowledge of Mathematics, Science and


engineering fundamentals in Electronics and Communication Engineering
field.

b) To design a component, a system or a process to meet the specific needs within


the realistic constraints such as economics, environment, ethics, health, safety and
manufacturability.

c) To demonstrate the competency to use software tools for computation, simulation


and testing of electronics engineering circuits

d) To identify, formulate and solve Electronics and Communication engineering problems

e) To demonstrate an ability to visualize and work on laboratory and


multidisciplinary tasks

f) To function as a member or a leader in multidisciplinary activities

g) To communicate in verbal and written form with fellow engineers and society at large

h) To understand the impact of Computer Science and Engineering in the society and
demonstrate awareness of contemporary issues and commitment to give solutions
exhibiting social responsibility

i) To demonstrate professional & ethical responsibilities

j) To exhibit confidence in self-education and ability for lifelong learning

k) To participate and succeed in competitive exams


LABORATORY SAFETY RULES
Read all of the following rules carefully, and remember them while working in the laboratory.

1.No running is allowed in the labs.

2. No bare feet or open sandals are permitted.

3.Know the location of the fire extinguisher and the first aid box.

4. Avoid stepping on electrical wires or any other computer cables.

5.Do not open the system unit casing or monitor casing particularly when the powered is turned on.

Some internal components hold electric voltages of up to 30,000 volts which can be fatal.

6.Do not insert metal objects such as clips, pins and needles into the computer casings. They may

cause fire.

7.Do not remove anything from the computer laboratory without permission.

8.do not touch, connect or disconnect any plug or cable without your lecturer/laboratory technician’s

permission.

9.Do not misbehave in the computer laboratory.

10.Try not to touch any of the circuit boards and power sockets when a device is connected to them.
CCS366 SOFTWARE TESTING AND AUTOMATION LABORATORY

SYLLABUS

1. Develop the test plan for testing an e-commerce web/mobile application (www.amazon.in).

2. Design the test cases for testing the e-commerce application

3. Test the e-commerce application and report the defects in it.

4. Develop the test plan and design the test cases for an inventory control system.

5. Execute the test cases against a client server or desktop application and identify the defects.

6. Test the performance of the e-commerce application.

7. Automate the testing of e-commerce applications using Selenium.

8. Integrate TestNG with the above test automation.

9. Mini Project:

a) Build a data-driven framework using Selenium and TestNG

b) Build Page object Model using Selenium and TestNG c

c) Build BDD framework with Selenium, TestNG and Cucumber

COURSE OBJECTIVES
The student should be made to:

 Test the e-commerce application and report the defects in it


 Execute the test cases against a client server or desktop application and identify the defects
 Develop the test plan and design the test cases for an inventory control system.
 Design the test cases for testing the e-commerce application
LIST OF EXPERIMENTS

1. Develop the test plan for testing an e-commerce web/mobile application (www.amazon.in).
2. Design the test cases for testing the e-commerce application
3. Test the e-commerce application and report the defects in it.
4. Develop the test plan and design the test cases for an inventory control system.
5. Execute the test cases against a client server or desktop application and identify the defects.
6. Test the performance of the e-commerce application.
7. Automate the testing of e-commerce applications using Selenium.
8. Integrate TestNG with the above test automation.
9. Mini Project:
a) Build a data-driven framework using Selenium and TestNG
b) Build Page object Model using Selenium and TestNG c
c) Build BDD framework with Selenium, TestNG and Cucumber

COURSE OUTCOMES

At the end of the semester, students will be able to


CO1: Understand the basic concepts of software testing and the need for software testing
CO2: Design Test planning and Carry out advanced typed of testing
CO3: Design effective test cases that can uncover critical defects in the application
CO4: Carry out advanced typed of testing
CO5: Automate the software testing using selenium and TestNG
Ex.
Name of the Experiment Page No
No.
1. Develop the test plan for testing an e-commerce web/mobile application
(www.amazon.in).
2. Design the test cases for testing the e-commerce application
3. Test the e-commerce application and report the defects in it.
4. Develop the test plan and design the test cases for an inventory control system.
5. Execute the test cases against a client server or desktop application and identify the
defects.
6. Test the performance of the e-commerce application
7. Automate the testing of e-commerce applications using Selenium.
8. Integrate TestNG with the above test automation.
9. Mini Project:
a) Build a data-driven framework using Selenium and TestNG
b) Build Page object Model using Selenium and TestNG c
c) Build BDD framework with Selenium, TestNG and Cucumber
1.Develop the test plan for testing an e-commerce web/mobile application (www.amazon.in).

Table of Contents:
1. Test Plan Identifier.......................................................................................................................................
2. Introduction .................................................................................................................................................
3. Features to be tested .....................................................................................................................................
4. Test Cases ....................................................................................................................................................
5. Approach .....................................................................................................................................................
6. Pass/Fail Criteria ..........................................................................................................................................
7. Suspension criteria and resumption requirements .........................................................................................
8. Test deliverables ..........................................................................................................................................

Procedure:

1. Test Plan Identifier


Amazon online shopping website Project test plan V1.0

2. Introduction
The goal of this document is to develop a test plan for online shopping website Amazon. This document
defines all the procedures and activities required to prepare for testing of the functionalities of the system
which are specified in QA technical test document. The objective of the test plan are to define the activities to
perform the testing, define the test deliverables documents involved in testing.

3. Features to be tested
The following list of features to be tested in this test cycle.
 Product Search
 Recommendations
 Shopping Basket
 Product listings, navigation

4. Test Cases

TestCases_Amazon.
xlsx

5. Approach
This section describes the overall approach of the testing which ensures that the each feature and the
combination of the features are adequately tested. The major tasks that are used are
Manual Testing: Manual Testing will be done to ensure the correctness of various parts of the code using test
cases generated by the tester.
Automation Testing: Using selenium web drivertool, we automate these manual test case then execute to
reduce manual work at regression testing area.

6. Pass/Fail Criteria
The pass or fail of a test depends on whether the system meets with all the functional requirements. Test cases
executed on the Online Amazon store will pass if they meet the specific requirements.
7. Suspension criteria and resumption requirements
Suspension criteria: If the system contains one or more critical defects,the entire system should be
suspended. The testing may also be suspended if the hardware and software components required are
not available on time. The failed test cases should be recorded along with the description for failure.
Resumption requirements: When a new version of the system is transmitted to the test group after a
suspension of testing has occurred, all previous tests will be rerun to ensure program changes have not
inadvertently affected other portions of the program.

8. Test deliverables
The following documents are the available test deliverables
 Test plan
 Test case specifications
 Test input and output data
 Test logs

2. Design the test cases for testing the e-commerce application.

Pre-requisites Test Step Test Step Expected Result Actual Status Comments Defect
Data No. Result ID
Browser should Userna 1 Open Browser should be opened
be installed me- browser
Internet Userna 2 Open url Ecommerce website should be 123
connection me opened
should be Passwor 3 Enter user should be able to input
present d- username username and password
passwor and
d password
4 Click on Home page should be
login button displayed after login
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on Home page should be
login button displayed after login and user
name should be displayed on
home page
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on Home page should be
login button displayed after login and user
name should be displayed on
home page
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on User should be logged in and
login button Search functionality is present
on home page.
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on User should be logged in and
login button home page should be same on
different browsers.
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on User should be logged in and
login button alignment of products on
home page should be proper.
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on Home page should be
login button displayed after login and user
name should be displayed on
home page
5 Click on any User should be redirected to
product product specification page.
displayed on
home page
Browser should 1 Open Browser should be opened
be installed browser
Internet
connection 2 Open url Ecommerce website should be
should be opened
present
3 Enter user should be able to input
User should be
username username and password
logged in
and
password
4 Click on Home page should be
login button displayed after login and user
name should be displayed on
home page
5 Click on any User should be redirected to
product product specification page.
displayed on
home page
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on Home page should be
login button displayed after login and user
name should be displayed on
home page
5 Click on user User profile should be
name displayed.
displayed on
home page.
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on Used should be logged in and
login button home page should be
displayed, products should be
categorised.
3. Test the e-commerce application and report the defects in it.

Pre-requisites Test Step Test Step Expected Result Actual Status Comments Defect
Data No. Result ID
Browser should Userna 1 Open Browser should be opened
be installed me- browser
Internet Userna 2 Open url Ecommerce website should be 123
connection me opened
should be Passwor 3 Enter user should be able to input
present d- username username and password
passwor and
d password
4 Click on Home page should be
login button displayed after login
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on Home page should be
login button displayed after login and user
name should be displayed on
home page
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on Home page should be
login button displayed after login and user
name should be displayed on
home page
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on User should be logged in and
login button Search functionality is present
on home page.
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on User should be logged in and
login button home page should be same on
different browsers.
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on User should be logged in and
login button alignment of products on
home page should be proper.
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on Home page should be
login button displayed after login and user
name should be displayed on
home page
5 Click on any User should be redirected to
product product specification page.
displayed on
home page
Browser should 1 Open Browser should be opened
be installed browser
Internet
connection 2 Open url Ecommerce website should be
should be opened
present
3 Enter user should be able to input
User should be username username and password
logged in and
password
4 Click on Home page should be
login button displayed after login and user
name should be displayed on
home page
5 Click on any User should be redirected to
product product specification page.
displayed on
home page

Browser should 1 Open Browser should be opened


be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on Home page should be
login button displayed after login and user
name should be displayed on
home page
5 Click on user User profile should be
name displayed.
displayed on
home page.
Browser should 1 Open Browser should be opened
be installed browser
Internet 2 Open url Ecommerce website should be
connection opened
should be 3 Enter user should be able to input
present username username and password
User should be and
logged in password
4 Click on Used should be logged in and
login button home page should be
displayed, products should be
categorised.

4. Develop the test plan and design the test cases for an inventory control system.

Test Cases of Store Management System Project (Testing)

The test case generation of Inventory Management System Project is today’s topic of discussion in this post.
Login
Here, you can mention the Name of the test
Test Engineer:
engineer
Test Case ID: 1
Related
UC/FR/NFR
UC/FR/NFR
Date: 02-01-2014
The purpose of this test insure that the user can
Purpose:
log in with his id to use this app.
Pre-Req: The user enters his correct name and password
for a successful login page.
Test Data: sname, sid, spassword
The steps are below.
1. visit Login Page
2. enter UserId
3. enter password
Steps:
4. click login
5. recovery password
6. change password
7. keep login
Status: Pass
Main form
Here, you can mention the Name of the test
Test Engineer:
engineer
Test Case ID: 2
Related
UC/FR/NFR
UC/FR/NFR
Date: 03-01-2014
The purpose of this test is to make sure that the
Purpose: design of the front page of the app is consistent
and readable.
The main activity of the app should be up and
Pre-Req:
running.
Test Data: none (test is just visual test)
Following steps will take place in the test
1. Latest orders
2. Top customers
Steps: 3. Recent products
4. Recent customers
5. Graph by amount and order
6. Graph by day/month/year
Status: Pass
Employ Records
Here, you can mention the Name of the test
Test Engineer:
engineer
Test Case ID: 3
Related
UC/FR/NFR
UC/FR/NFR
Date: 03-01-2014
The purpose of this test for registered employ by
Purpose: his name, password, email, and mobile number
for use this app and work on the app.
Employ sure that login with his name and id to
Pre-Req:
use this app.
Test Data: none (test is just visual test)
Step formatting rules below.
1. enter employ name
Steps: 2. enter employ password
3. enter employ email
4. enter employ a mobile number
Status: Pass
Category Record
Here, you can mention the Name of the test
Test Engineer:
engineer
Test Case ID: 4
Related
UC/FR/NFR
UC/FR/NFR
Date: 04-01-2014
The purpose of this testing to insert, update,
Purpose:
delete and view category.
Pre-Req: The user enter category by its correct name.

Test Data: Txtcatogaryname


Step formatting rules below.
1. open the category form
2. insert the category name of items
3. update the category name of items
Steps:
4. delete the category name of items
5. insert the category name of items
6. view the category names
7. Export the category records to MS Excel.
Status: Pass
Customer Record
Here, you can mention the Name of the test
Test Engineer:
engineer
Test Case ID: 5
Related
UC/FR/NFR
UC/FR/NFR
Date: 05-01-2014
The purpose of this testing to registered the new
Purpose: customer by his name, address, id number and
phone number for sales items.
The user can easily search customer by name
Pre-Req:
with all data.
Scustmrname, scsutmradress, scustmrmblnumer,
Test Data:
scustmremail
Step formatting rules below.
1. automatically generate customer-id
2. enter the customer name
3. enter customer address
Steps: 4. enter customer id number
5. enter customer city
6. enter customer mobile number
7. enter customer email
Status: Pass
Items Record And Configuration
Here, you can mention the Name of the test
Test Engineer:
engineer
Test Case ID: 6
Related
UC/FR/NFR
UC/FR/NFR
Date: 05-01-2014
The purpose of this testing to enter item code,
Purpose: name and price and also can modify name and
price of items.
Pre-Req: Employ can search items by name and code.
Test Data: none (test is just visual test)
Step formatting rules below.
1. insert items code
Steps: 2. insert items name with price
3. update items name or price
4. delete items name
Status: Pass
Sales and Report
Here, you can mention the Name of the test
Test Engineer:
engineer
Test Case ID: 7
Related
UC/FR/NFR
UC/FR/NFR
Date: 05-01-2014
The purpose of this testing to sales items with
Purpose:
discount and print invoice of sales.
The user can check records for recent or old sales
Pre-Req:
by report or data.
none (test is just visual test)
Test Data:

Step formatting rules below.


1. sales items with quantity
2. discount to customer
Steps:
3. payment due
4. print crystal report of sales
5. print excel report of sales
Status: Pass
Stock
Here, you can mention the Name of the test
Test Engineer:
engineer
Test Case ID: 8
Related
UC/FR/NFR
UC/FR/NFR
Date: 05-09-2014
The purpose of this test for check quantities of
Purpose:
items in which user can modify items day by day.
The user can see the quantities are below in the
Pre-Req:
range or above in the range.
Test Data: None
Step formatting rules below.
1. set the quantities of items
2. update the quantities of items
3. delete the quantities of items
Steps:
4. if quantities less than 200 than message
show with yellow color
5. if quantities equal to zero than message
show with red color
Status: Pass

5. Execute the test cases against a client server or desktop application and identify the defects.

CalcTest.txt
package cse.test;
import cse.com.*;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class CalcTest {

@Test
void test1() {
assertEquals(15,Calculator.addition(10, 5));
}
@Test
void test2() {
assertEquals(2,Calculator.division(10, 5));
}
@Test
void test3() {
assertEquals(50,Calculator.multiplication(10, 5));
}
@Test
void test4() {
assertEquals(5,Calculator.subtraction(10, 5));
}

Calculator.txt
package cse.com;

import java.util.Scanner;

public class Calculator {


private int solution;
private int x;
private int y;
private char operators;

public Calculator() { solution = 0;


Scanner operators = new Scanner(System.in);
Scanner operands = new Scanner(System.in);
}
public static int addition(int x, int y) { return x + y;
}
public static int subtraction(int x, int y) { return x * y;
}
public static int multiplication(int x, int y)
{
return x * y;
}
public static int division(int x, int y)
{
return x / y;
}
}

6. Test the performance of the e-commerce application.

VERSION HISTORY
[Provide information on how the development and distribution of the Test Plan, up to the
final point of approval, was controlled and tracked. Use the table below to provide the
version number, the author implementing the version, the date of the version, the name of
the person approving the version, the date that particular version was approved, and a
brief description of the reason for creating the revised version.]
Versio Implemented Revision Approve Approval Reason
n By Date d Date
# By
1.0 <Author <mm/dd/yy <name> <mm/dd/yy Test Plan draft
name> > >

1 INTRODUCTION
PURPOSE OF THE TEST PLAN DOCUMENT
[Provide the purpose of the Test Plan Document. This document should be tailored to fit a
particular project’s needs.]
The Test Plan document documents and tracks the necessary information required to
effectively define the approach to be used in the testing of the project’s product. The Test
Plan document is created during the Planning Phase of the project. Its intended audience is
the project manager, project team, and testing team. Some portions of this document may
on occasion be shared with the client/user and other stakeholder whose input/approval into
the testing process is needed.
2 COMPATIBILITY TESTING
TEST RISKS / ISSUES
[Describe the risks associated with product testing or provide a reference to a document
location where it is stored. Also outline appropriate mitigation strategies and contingency
plans.]
ITEMS TO BE TESTED / NOT TESTED
[Describe the items/features/functions to be tested that are within the scope of this test
plan. Include a description of how they will be tested, when, by whom, and to what quality
standards. Also include a description of those items agreed not to be tested.]
Item to Test Test Description Test Date Responsibility

TEST APPROACH(S)
[Describe the overall testing approach to be used to test the project’s product. Provide an
outline of any planned tests.]

TEST REGULATORY / MANDATE CRITERIA


[Describe any regulations or mandates that the system must be tested against.]
TEST PASS / FAIL CRITERIA
[Describe the criteria used to determine if a test item has passed or failed its test.]
TEST ENTRY / EXIT CRITERIA
[Describe the entry and exit criteria used to start testing and determine when to stop
testing.]
TEST DELIVERABLES
[Describe the deliverables that will result from the testing process (documents, reports,
charts, etc.).]
TEST SUSPENSION / RESUMPTION CRITERIA
[Describe the suspension criteria that may be used to suspend all or portions of testing.
Also describe the resumption criteria that may be used to resume testing.]
TEST ENVIRONMENTAL / STAFFING / TRAINING NEEDS
[Describe any specific requirements needed for the testing to be performed
(hardware/software, staffing, skills training, etc).)]
3 CONFORMANCE TESTING
TEST RISKS / ISSUES
[Describe the risks associated with product testing or provide a reference to a document
location where it is stored. Also outline appropriate mitigation strategies and contingency
plans.]

ITEMS TO BE TESTED / NOT TESTED


[Describe the items/features/functions to be tested that are within the scope of this test
plan. Include a description of how they will be tested, when, by whom, and to what quality
standards. Also include a description of those items agreed not to be tested.]
Item to Test Test Description Test Date Responsibility

TEST APPROACH(S)
[Describe the overall testing approach to be used to test the project’s product. Provide an
outline of any planned tests.]
TEST REGULATORY / MANDATE CRITERIA
[Describe any regulations or mandates that the system must be tested against.]
TEST PASS / FAIL CRITERIA
[Describe the criteria used to determine if a test item has passed or failed its test.]
TEST ENTRY / EXIT CRITERIA
[Describe the entry and exit criteria used to start testing and determine when to stop
testing.]
TEST DELIVERABLES
[Describe the deliverables that will result from the testing process (documents, reports,
charts, etc.).]
TEST SUSPENSION / RESUMPTION CRITERIA
[Describe the suspension criteria that may be used to suspend all or portions of testing.
Also describe the resumption criteria that may be used to resume testing.]
TEST ENVIRONMENTAL / STAFFING / TRAINING NEEDS
[Describe any specific requirements needed for the testing to be performed
(hardware/software, staffing, skills training, etc).)]

7. Automate the testing of e-commerce applications using Selenium.

Selenium is a robust set of tools that supports rapid development of test automation for
web-based applications. Selenium provides a rich set of testing functions specifically
geared to the needs of testing of a web application. These operations are highly flexible,
allowing many options for locating UI elements and comparing expected test results
against actual application behavior.
One of Selenium‘s key features is the support for executing one‘s tests on multiple
browser platforms.
Selenium Components
Selenium is composed of three major tools. Each one has a specific role in aiding
the development of web application test automation.
Selenium-RC provides an API (Application Programming Interface) and library for each
of its supported languages: HTML, Java, C#, Perl, PHP, Python, and Ruby. This ability
to use Selenium-RC with a high-level programming language to develop test cases also
allows the automated testing to be integrated with a project‘s automated build
environment.
Selenium-Grid

Selenium-Grid allows the Selenium-RC solution to scale for large test suites or test suites
that must be run in multiple environments. With Selenium-Grid, multiple instances of
Selenium-RC are running on various operating system and browser configurations; Each
of these when launching register with a hub. When tests are sent to the hub they are then
redirected to an available Selenium-RC, which will launch the browser and run the test.
This allows for running tests in parallel, with the entire test suite theoretically taking only
as long to run as the longest individual test.
* Tests developed on Firefox via Selenium-IDE can be executed on any other supported
browser via a simple Selenium-RC command line.
** Selenium-RC server can start any executable, but depending on browser security
settings there may be technical limitations that would limit certain features.

Flexibility and Extensibility

Selenium is highly flexible. There are multiple ways in which one can add functionality
to Selenium‘s framework to customize test automation for one‘s specific testing needs.
This is, perhaps, Selenium‘s strongest characteristic when compared with proprietary test
automation tools and other open source solutions. Selenium-RC support for multiple
programming and scripting languages allows the test writer to build any logic they need
into their automated testing and to use a preferred programming or scripting language of
one‘s choice.
Selenium-IDE allows for the addition of user-defined ―user-extensions‖ for creating
additional commands customized to the user‘s needs. Also, it is possible to re-configure
how the Selenium-IDE generates its Selenium-RC code. This allows users to customize
the generated code to fit in with their own test frameworks. Finally, Selenium is an Open
Source project where code can be modified and enhancements can be submitted for
contribution.
.Test Suites

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. An example tells it all.

<html>
<head>
<title>Test Suite Function Tests – Priority 1</title>
</head> <body>
<table>
<tr><td><b>Suite Of Tests</b></td></tr>
<tr><td><a href=‖./Login.html‖>Login</a></td></tr>
<tr><td><a href=‖./SearchValues.html‖>Test Searching for
Values</a></td></tr> <tr><td><a href=‖./SaveValues.html‖>Test
Save</a></td></tr>
</table>
</body> </html>
A file similar to this would allow running the tests all at once, one after another, from the
Selenium-IDE.

Test suites can also be maintained when using Selenium-RC. This is done via
programming and can be done a number of ways. Commonly Junit is used to maintain a
test suite if one is using Selenium-RC with Java. Additionally, if C# is the chosen
language, Nunit could be employed. If using an interpreted language like Python with
Selenium-RC than some simple programming would be involved in setting up a test
suite. Since the whole reason for using Sel-RC is to make use of programming logic for
your testing this usually isn‘t a problem.
Few typical Selenium commands.

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.

8. Integrate TestNG with the above test automation.

Dependency List
1. Selenium- 4.12.1
2. Java 8 or above
3. TestNG – 7.8.0
4. Maven – 3.8.1
5. WebdriverManager – 5.5.3
Implementation Steps
Step 1- Download and Install Java
Selenium needs Java to be installed on the system to run the tests. Click here to learn How to install Java.
Step 2 – Download and setup Eclipse IDE on the system
The Eclipse IDE (integrated development environment) provides strong support for Java developers, which is
needed to write Java code. Click here to learn How to install Eclipse.
Step 3 – Setup Maven
To build a test framework, we need to add a number of dependencies to the project. It is a very tedious and
cumbersome process to add each dependency manually. So, to overcome this problem, we use a build
management tool. Maven is a build management tool that is used to define project structure, dependencies,
build, and test management. Click here to learn How to install Maven.
Step 4 – Create a new Maven Project
Click here to learn How to create a Maven project
Below is the Maven project structure. Here,

Group Id – com.example
Artifact Id – Selenium_TestNGDemo
Version – 0.0.1-SNAPSHOT
Package – com. example. Selenium_TestNGDemo

Step 5 – Add Selenium and TestNG dependencies to the project


As this is a Maven project, we can add the dependencies in POM.xml as shown below.

1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema


2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd
3 <modelVersion>4.0.0</modelVersion>
4
5 <groupId>com.example</groupId>
6 <artifactId>Log4j2_Demo</artifactId>
7 <version>1.0-SNAPSHOT</version>
8 <packaging>jar</packaging>
9
10 <name>Log4j2_Demo</name>
11 <url>http://maven.apache.org</url>
12
13 <properties>
14 <selenium.version>4.12.1</selenium.version>
15 <testng.version>7.8.0</testng.version>
16 <webdrivermanager.version>5.5.3</webdrivermanager.version>
17 <maven.surefire.failsafe.version>3.1.2</maven.surefire.failsafe.version>
18 <maven.compiler.version>3.11.0</maven.compiler.version>
19 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20 <maven.compiler.source>11</maven.compiler.source>
21 <maven.compiler.target>11</maven.compiler.target>
22 </properties>
23
24 <dependencies>
25
26 <!-- TestNG Dependency -->
27 <dependency>
28 <groupId>org.testng</groupId>
29 <artifactId>testng</artifactId>
30 <version>${testng.version}</version>
31 <scope>test</scope>
32 </dependency>
33
34 <!-- WebDriverManager Dependency -->
35 <dependency>
36 <groupId>io.github.bonigarcia</groupId>
37 <artifactId>webdrivermanager</artifactId>
38 <version>${webdrivermanager.version}</version>
39 </dependency>
40
41 <!-- Selenium Dependency -->
42 <dependency>
43 <groupId>org.seleniumhq.selenium</groupId>
44 <artifactId>selenium-java</artifactId>
45 <version>${selenium.version}</version>
46 </dependency>
47
48 </dependencies>
49
50 <build>
51
52 <plugins>
53 <plugin>
54 <groupId>org.apache.maven.plugins</groupId>
55 <artifactId>maven-surefire-plugin</artifactId>
56 <version>${maven.surefire.failsafe.version}</version>
57 <configuration>
58 <skipTests>false</skipTests>
59 <skip>false</skip>
60 <testFailureIgnore>true</testFailureIgnore>
61 </configuration>
62 </plugin>
63
64 <plugin>
65 <groupId>org.apache.maven.plugins</groupId>
66 <artifactId>maven-compiler-plugin</artifactId>
67 <version>${maven.compiler.version}</version>
68 <configuration>
69 <source>${maven.compiler.source}</source>
70 <target>${maven.compiler.target}</target>
71 <fork>true</fork>
72 </configuration>
73 </plugin>
74 </plugins>
75
76 </build>
77
78 </project>
After the addition of dependencies in pom.xml, the Maven Dependencies folder will be updated automatically
with all the JAR file related to the dependencies.

Step 6 – Create a Test file under src/test/java


@BeforeMethod – This annotated method will be run before each test method i.e say there are three test
methods (i.e test cases), then @BeforeMethod annotated method will be called thrice before each test method.
@AfterMethod – methods under this annotation will be executed after each Test method.
@Test – The annotated method is part of a test case.
Description – You can describe your test case under the description, stating what it does.
1 description = "This test validates title of login functionality"
Priority – You can prioritize the order of your test methods by defining a priority. Based on the defined
priority, the test shall execute in that order.
1priority = 0
1 import io.github.bonigarcia.wdm.WebDriverManager;
2 import org.openqa.selenium.By;
3 import org.openqa.selenium.WebDriver;
4 import org.openqa.selenium.chrome.ChromeDriver;
5 import org.openqa.selenium.chrome.ChromeOptions;
6 import org.testng.Assert;
7 import org.testng.annotations.AfterMethod;
8 import org.testng.annotations.BeforeMethod;
9 import org.testng.annotations.Test;
10 import java.util.concurrent.TimeUnit;
11
12 public class TestNG_Demo {
13 WebDriver driver;
14
15 By userName = By.name("username");
16 By passWord = By.name("password");
17
18 By loginBtn =
19 By.xpath("//*[@id='app']/div[1]/div/div[1]/div/div[2]/div[2]/form/div[3]/button");
20
21 By loginTitle = By.xpath("//*[@id='app']/div[1]/div/div[1]/div/div[2]/h5");
22
23 By dashboardPage =
24 By.xpath("//*[@id='app']/div[1]/div[1]/header/div[1]/div[1]/span/h6");
25
26
27 @BeforeMethod
28 public void setUp() {
29
30 System.out.println("Open a Chrome Web Browser");
31 WebDriverManager.chromedriver().setup();
32 ChromeOptions options=new ChromeOptions();
33 options.addArguments("--start-maximized");
34 driver=new ChromeDriver(options);
35 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
36 driver.get("https://opensource-demo.orangehrmlive.com/");
37 System.out.println("Open the application");
38 }
39
40 @Test(description = "This test validates title of login functionality", priority =
41 0)
42 public void verifyLoginPageTitle() {
43
44 System.out.println("Verify the Login page title");
45 String expectedTitle = driver.findElement(loginTitle).getText();
46
47 System.out.println("Actual Title :" + expectedTitle);
48 Assert.assertTrue(expectedTitle.equalsIgnoreCase("Login"));
49 }
50
51 @Test(description = "This test validates successful login to Home page",
52 priority = 1)
53 public void verifyloginPage() {
54
55 System.out.println("Enter Username");
56 driver.findElement(userName).sendKeys("Admin");
57
58 System.out.println("Enter Password");
59 driver.findElement(passWord).sendKeys("admin123");
60
61 driver.findElement(loginBtn).submit();
62
63 System.out.println("New page - Dashboard is opened");
64 String newPageText = driver.findElement(dashboardPage).getText();
65
66 System.out.println("Heading of new page :" + newPageText);
67 Assert.assertTrue(newPageText.contains("Dashboard"));
68
69 }
70
71 @AfterMethod
72 public void teardown() {
73
74 System.out.println("Close the webpage");
driver.quit();
}

}
Step 7 – Test Execution through TestNG
Go to the Runner class and right-click Run As TestNG Test. The tests will run as TestNG tests.

Step 8 – Run the tests from TestNG.xml


Create a TestNG.xml as shown below and run the tests as TestNG.

1 <?xml version = "1.0"encoding = "UTF-8"?>


2 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
3 <suite name = "Suite1">
4 <test name = "TestNG Demo">
5 <classes>
6 <class name = "com.example.Selenium_TestNGDemo.TestNG_Demo"/>
7 </classes>
8 </test>
9 </suite>
Step 9 – TestNG Report Generation
TestNG generates various types of reports under test-output folder like emailable-report.html, index.html,
testng-results.xml.

We are interested in the “emailable-report.html” report. Open “emailable-report.html“, as this is an HTML report, and
open it with the browser. The below image shows emailable-report.html.

TestNG also produces an “index.html” report, and it resides under the test-output folder. The below image shows
the index.html report. This is the latest theme of the report.

You might also like