ACFrOgB6jK0WfhM1ZuvHOBqx3q4rXbpoguYLcnw2et1IeZny7c VoF-UQWO5j4UuuBBhriAx3dfK3BMnPfFSruz whcsED5nFKjbYdVmoDiqO3iDjzXOwMQR8ppLWINU3tN8ObCFFpzvZF467Plz
ACFrOgB6jK0WfhM1ZuvHOBqx3q4rXbpoguYLcnw2et1IeZny7c VoF-UQWO5j4UuuBBhriAx3dfK3BMnPfFSruz whcsED5nFKjbYdVmoDiqO3iDjzXOwMQR8ppLWINU3tN8ObCFFpzvZF467Plz
LIST OF EXPERIMENTS
4 Develop the test plan and design the test cases for an
inventory control system
AIM
To develop test plan document for testing e-commerce or banking web and mobile application.
1) INTRODUCTION
The Test Plan is designed to prescribe the scope, approach, resources, and schedule of all testing
activities of the project HDFC Bank.
The plan identifies the items to be tested, the features to be tested, the types of testing to be
performed, the personnel responsible for testing, the resources and schedule required to complete
testing, and the risks associated with the plan
1.1) Scope
1.1.1) In Scope
All the feature of website HDFC Bank which were defined in software requirement specs are
need to be tested
1.1.2) Out of Scope
These features are not be tested because they are not included in the software requirement specs
User Interfaces
Hardware Interfaces
Software Interfaces
Database logical
Communications Interfaces
Website Security and Performance
The test objectives are to verify the Functionality of website HDFC Bank, the project should
focus on testing the banking operation such as Account Management, Withdrawal, and Balance
etc. to guarantee all these operations can work normally in real business environment.
The project should use outsource members as the tester to save the project cost.
2 TESTMETHODOLOGY
2.1 Overview
Integration Testing (Individual software modules are combined and tested as a group)
System Testing: Conducted on a complete, integrated system to evaluate the system’s
Compliance with its specified requirements
/api-testing.html: Test all the API secrete for the software undertested
If the team members report that there are 40% of test cases failed, suspend testing until the
development team fixes all the failed cases.
3 TEST DELIVERABLES
– Test Data
Test Results/reports
Defect Report
Installation/ Test procedures guidelines
Release notes
It mentions the minimum hardware and software requirements that will be used to test the Application.
RESULT:
Test plan document for testing e-commerce or banking web and mobile application was created.
Exp.No.2
AIM
1.To develop test cases for testing e-commerce or any web and mobile application
TEST SCENARIO–LOGIN
Test Scenario–Purchase
Test Scenario–Search
RESULT:
Test cases for testing e-commerce or any web and mobile application was developed.
Exp.No.3
Aim:
To test the e-commerce application and report the defects in it.
1. Functionality Testing:
● Ensure all features such as product browsing, searching, adding items to the cart, checkout process, account
creation/login, and payment processing are working correctly.
● Test various scenarios like adding different types of products (physical/digital), applying discounts, using different
payment methods, etc.
2. Usability Testing:
● Evaluate the user interface for intuitiveness and ease of navigation.
● Check if the layout is responsive across different devices and screen sizes.
● Verify that the website is accessible to users with disabilities.
3. Performance Testing:
● Test the application's response time by simulating different levels of user traffic.
● Verify the loading speed of pages, especially product listings and checkout pages.
● Ensure that the application can handle peak loads without crashing or slowing down.
4. Security Testing:
● Check for vulnerabilities such as SQL injection, cross-site scripting (XSS), and authentication flaws.
● Verify that sensitive information like payment details is encrypted during transmission.
● Test for proper session management and access control mechanisms.
5. Compatibility Testing:
● Test the application on different web browsers (Chrome, Firefox, Safari, etc.) and versions.
● Verify compatibility with various operating systems (Windows, macOS, Linux) and devices (desktops, laptops, tablets,
smartphones).
● Ensure that the website renders correctly on different resolutions and screen sizes.
6. Integration Testing:
● Test integrations with external services such as payment gateways, shipping carriers, and third-party APIs.
● Verify that data is synchronized accurately between the e-commerce platform and any external systems.
7. Regression Testing:
● Re-test previously fixed defects to ensure they haven’t reappeared.
● Test new features or changes to existing features to ensure they haven’t introduced new issues.
SEARCH FUNCTIONALITY:
Test Case Module Test Scenario Test Case Pre- requisites Test Data Step Test Step Expected Result Actual Result Status Defect ID
ID Name No.
TC0 01 Product Verify the Verify that the Browser should Username- 1 Open Browser should be Browser is opened Pass N/A
Search product search search field be installed Username browser opened
functionality accepts alphabets, Internet Password-
2 Open url Ecommerce website Ecommerce Pass N/A
numbers or connection password
should be opened website is opened
symbols. should be
present User
should be 3 Enter User should be able to User is able to Pass N/A
logged in username input username and enter username
and password and password
password
4 Click on Home page should be Home page is Pass N/A
loginbutton displayed after login displayed after
login
5 Click on the Search field should Search field Pass N/A
search field. accepts alphabets, accepts alphabets,
numbers or numbers or
symbols. symbols.
TC0 02 Product Verify the Verify that after Browser should Username- 1 Open Browser should be Browser is opened Pass N/A
Search product search entering search be installed Username browser opened
functionality text and clicking Internet Password-
2 Open url Ecommerce website Ecommerce Pass N/A
on the search connection password
should be opened website is opened
icon, the search should be
should be present user
performed. should be 3 Enter User should be able to User is able to Pass N/A
logged in username input username and enter username
and password and password
password
4 Click on Home page should be Home page is Pass N/A
loginbutton displayed after login displayed after
and user name should login
be displayed on home
page
TC0 03 Product Verify the Verify that the Browser should Username- 1 Open Browser should be Browser is opened Pass N/A
Search product search search results be installed Username browser opened
functionality should be as per Internet Password-
2 Open url Ecommerce website Ecommerce Pass N/A
the search query. connection password
should be opened website is opened
should be
present User
should be 3 Enter user should be able to User is able to Pass N/A
logged in username input username and enter username
and password and password
password
4 Click on Home page should be Home page is Pass N/A
loginbutton displayed after login displayed after
and user name should login
be displayed on home
page
Test Module Test Scenario Test Case Pre- requisites Test Step Test Step Expected Result Actual Result Status Defect
Case ID Name Data No. ID
TC0 01 Product Verify the Verify that Browser should Userna 1 Open Browser should be Browser is Pass N/A
Details details on images of be installed me - browser opened opened
Product products Internet Userna
2 Open url Ecommerce website Ecommerce Pass N/A
Specification are connection me
should be opened website is opened
page displayed should be Passwo
correctly. present rd- 3 Enter User should be able to User is able to Pass N/A
passwo username input username and enter usernameand
rd and password password
password
4 Click on Home page should be Home page is Pass N/A
loginbutton displayed after login displayed after
login
5 Click on a The images of the The images of the Pass N/A
product product should be product are
displayed on displayed correctly. displayed
the home correctly.
page.
TC0 02 Product Verify the Verify that Browser should Userna 1 Open Browser should be Browser is Pass N/A
Details details on the price of be installed me - browser opened opened
Product the product Internet Userna 2 Open url Ecommerce website Ecommerce Pass N/A
Specification is displayed. connection me should be opened website is opened
page should be Passwo
present User rd- 3 Enter user should be able to User is able to Pass N/A
should be passwo username input username and enter usernameand
logged in rd and password password
password
CART PAGE
Test Case ID Module Test Test Case Pre- requisites Test Data Step Test Step Expected Result Actual Result Status Defect
Name Scenario No. ID
TC0 01 Cart Page Verify the Verify that Browser should Username- 1 Open browser Browser should be opened Browser is opened Pass N/A
details on when a user be installed Username
Cart Page clicks on add Internet Password- 2 Open url Ecommerce website Ecommerce website Pass N/A
to cart, the connection password should be opened is opened
product should be
should be present
added to cart. 3 Enter User should be able to User is able to enter Pass N/A
username and input username and username and
password password password
4 Click on login Home page should be Home page is Pass N/A
button displayed after login displayed after login
5 Click on any The product page should The product page is Pass N/A
product be displayed. displayed.
displayed on
home page
6 Click on add to The product should be The product is Pass N/A
cart for the added to cart. added to cart.
product.
TC0 02 Cart Page Verify the Verify that Browser should Username- 1 Open browser Browser should be opened Browser is opened Pass N/A
details on when a user be installed Username
Cart Page clicks on add Internet Password- 2 Open url Ecommerce website Ecommerce website Pass N/A
to cart, the connection password should be opened is opened
product should be
should be present
added to cart. 3 Enter User should be able to User is able to enter Pass N/A
username and input username and username and
password password password
4 Click on login Home page should be Home page is Pass N/A
button displayed after login displayed after login
5 Click on any The product page should The product page is Pass N/A
product be displayed. displayed.
displayed on
home page
6 Click on add to The product should be The product is Pass N/A
cart for the added to cart. added to cart.
product.
TC0 03 Cart Page Verify the Verify that Browser should Username- 1 Open browser Browser should be opened Browser is opened Pass N/A
details on when a user be installed Username
Cart Page clicks on add Internet Password- 2 Open url Ecommerce website Ecommerce website Pass N/A
to cart, the connection password should be opened is opened
product should be
should be present
added to cart. 3 Enter User should be able to User is able to enter Pass N/A
username and input username and username and
password password password
4 Click on login Home page should be Home page is Pass N/A
button displayed after login displayed after login
5 Click on any The product page should The product page is Pass N/A
product be displayed. displayed.
displayed on
home page
6 Click on add to The product should be The product is Pass N/A
cart for the added to cart. added to cart.
product.
Click on
The product The product
add to cart
6 should be added is added to Pass N/A
for the
to cart. cart.
product.
The
checkout
The checkout
Click on page is
page should be
7 the displayed Pass N/A
displayed with
Checkout with
delivery details.
button. delivery
details.
Browser
Open Browser is
1 should be Pass N/A
browser opened
opened
Ecommerce
Ecommerce
website
2 Open url website is Pass N/A
should be
opened
opened
Enter user should User is able
username be able to to enter
3 input username Pass N/A
and
password username and
and password
password
Browser
Verify that should be Home page
Home page
delivery installed should be
is displayed
Verify the details of Internet Username- displayed
Checkout, after login
details on items connectio Username after login
TC0 03 Payments Click on and user
Checkout,Pay should be n should Password- 4 and user Pass N/A
Page login name is
ments Page displayed be present password name should
button displayed
at User be displayed
on home
checkout. should be on home
page
logged in page
MY ORDER
Test Module Name Test Scenario Test Case Pre- requisites Test Data Step Test Step Expected Result Actual Result Status Defect
Case No. ID
ID
TC0 01 My Orders Verify the Verify that the Browser should be Username - 1 Open browser Browser should be opened Browser is opened Pass N/A
Page details on user should be installed Internet Username
Orders Page able to track connection should Password-
the order on be present password
2 Open url Ecommerce website Ecommerce website is Pass N/A
My orders page.
should be opened opened
3 Enter username User should be able to User is able to enter Pass N/A
and password input username and username and
password password
5 Click on My The orders by the user The product page is Pass N/A
orders button should be displayed. displayed.
TC0 02 My Orders Verify the Verify that the Browser should be Username - 1 Open browser Browser should be opened Browser is opened Pass N/A
Page details on user should be installed Internet Username
Orders Page able to track connection should Password-
the order on be present password
2 Open url Ecommerce website Ecommerce website is Pass N/A
My orders page.
should be opened opened
3 Enter username User should be able to User is able to enter Pass N/A
and password input username and username and
password password
5 Click on My The orders by the user The product page is Pass N/A
orders button should be displayed. displayed.
TC0 03 My Orders Verify the Verify that the Browser should be Username - 1 Open browser Browser should be opened Browser is opened Pass N/A
Page details on user should be installed Internet Username
Orders Page able to track connection should Password-
the order on be present password
2 Open url Ecommerce website Ecommerce website is Pass N/A
My orders page.
should be opened opened
3 Enter username User should be able to User is able to enter Pass N/A
and password input username and username and
password password
5 Click on My The orders by the user The product page is Pass N/A
orders button should be displayed. displayed.
CUSTOMER SERVICE
Test Module Test Scenario Test Case Pre- Test Data Step Test Step Expected Actual Status Defect ID
Case Name requisites No. Result Result
ID
TC0 01 Customer Verify the Verify that Browser Username - 1 Open Browser should Browser is Pass N/A
Service Page details on customer should be Username browser be opened opened
Customer service installed Password -
Service Page options Internet password 2 Open url Ecommerce Ecommerce Pass N/A
should be connection website should website is
present on should be be opened opened
the website. present 3 Enter user should be user is able to Pass N/A
username able to input enter
and username and username and
password password password
Conclusion
Thus, the e-commerce application is tested and the defects are reported successfully.
Exp.No.4
DEVELOP THE TEST PLAN AND DESIGN THE TEST CASES FOR AN
Date: INVENTORY CONTROL SYSTEM
Aim
To develop the test plan and design the test cases for an inventory control system.
1. Introduction
The Inventory Control System is designed to efficiently manage inventory, track stock levels,
and ensureaccurate stock information. This test plan outlines the testing approach, scope,
objectives, and methodologies to verify the functionality, performance, and usability of the
system.
2. Objectives
● Validate that the Inventory Control System meets the functional requirements.
● Verify the accuracy and consistency of inventory tracking.
● Assess system performance under varying loads.
● Ensure the system’s security mechanisms are effective
● Evaluate the system’s usability and user-friendliness.
3. Test Scope
The testing will cover the following aspects of the Inventory Control System:
4. Test Environment
Test data will include a range of products, quantities, prices, and suppliers. Both normal and
boundarytest cases will be created to cover various scenarios. Data will be structured to
validate different calculations and reports.
6. Test Cases
A comprehensive list of test cases will be created for functional, performance, security, and
usabilitytesting. Each test case will include:
● Test case ID
● Description of the scenario
● Preconditions
● Steps to execute the test
● Expected results
● Actual results Pass/fail status.
7. Types of Testing
8. Test Schedule
9. Defect Management
12.Resources
14.Approval
This test plan requires approval from relevant stakeholders before testing commences.
15.Appendix
● Glossary of terms
● References used in the test plan
TEST CASES FOR INVENTORY MANAGEMENT SYSTEM
Test
Sl.no Action Steps Input Data Experienced Actual result Status
Case
result
s
Enter It should accept Invoice no.
1 TC−1 Invoice no Input*1021* Pass
Invoice no invoice no. isaccepted
Enter Input*27/11/20 It should accept Bill date
2 TC−2 Bill date Pass
Bill 21* bill date is
date accepted
Item name should Item name is
Item Select item
3 TC−3 − be automatically automatically Pass
name name
reflected reflected
Available It should reflect Item stock is
Click on
4 TC−4 item − automatically item reflected Pass
text box
stock stock automatically
Enter item Item quantity Item quantity is
5 TC−5 Quantity Input*5000* Pass
quantity should be accepted accepted
Price should be
Click on Price is reflected
6 TC−6 Price − reflected Pass
text box automatically
automatically
Total should be
Click on Total is reflected
7 TC−7 Total − reflected Pass
text box automatically
automatically
Enter Receive bill date
Receive Input*29/1/202 Receive bill date
8 TC−8 receive bill should be Pass
bill date 1 is accepted
date accepting
It should be adding
Click on Item is added to
9 TC−9 Add item − item reflecting in Pass
add item the database
database
Sr.No Action Steps Input Expected Actual Status
Data Result Result
behidden
4 Check actions Open the Correct Login Login page is Pass
followed by application and password successful appeared
entering enter correct and page
username and username and username should
password password appear
Thus, the test plan and the test cases for an inventory control system are developed and
designedsuccessfully.
Exp.No.5
EXECUTE THE TEST CASES AGAINST A CLIENT SERVER OR
Date: DESKTOP APPLICATION AND IDENTIFY THE DEFECTS.
AIM:
To execute the test cases against a client server or desktop application and identify the
defects.
ALGORITHM:
3. Check Credentials:
● Verify if the entered username is "Form" and the password is "123".
4. Successful Login:
● If credentials match, display a success message and redirect to success.html.
5. Invalid Credentials:
● If credentials do not match, decrement the attempt variable by 1.
<html>
<head>
<!--IncludeJSFileHere -->
</head>
<body>
<div class="container">
<div class="main">
<label>UserName:</label>
<label>Password:</label>
</form>
</div>
</div>
</body>
</html>
//login.js
var attempt =3; //Variable to count number of attempts.
//BelowfunctionExecutesonclickofloginbutton.
function validate()
var
username=document.getElementById("username").v
alue;var
password=document.getElementById("password").v
alert("Login successfully");
window.location="success.html";//Redirecting To
else {
attempt;");
3attempts.if(attempt ==0) {
document.getElementById("username").disabled=true;
document.getElementById("password").disable
d =true;
document.getElementById("submit").disabled
}
}
//success.html
<html>
<head>
</head>
<body>
<h2>SuccessfulLogin!</h2>
</body>
</html>
RESULT:
Thus, the test cases against a client server or desktop application have been written and thedefects are identified
Successfully.
Exp.No.6
TEST THE PERFORMANCE OF THE E-COMMERCE APPLICATION
Date:
AIM:
E-Commerce applications are designed in such a way that customers can easily make
purchasesat any time of the day, irrespective of where they are located. If an e-Commerce
application malfunctions during peak hours, not only will it cause customer dissatisfaction,
but it will also lead to revenue loss for the business.
● Reduce Risks: Many times, making major and considerable changes to a site can cause
notablestrategic changes or even trigger significant losses. However, testing these changes in
a plannedmanner can help eliminate the chances of these uncertain revenue losses
● Increase Conversion Rates: By testing every aspect of an application and ensuring a
smoothvisitor experience through site optimization, the application conversion rate is
bound to increase.
● Improve User Engagement: Testing tells which page element or process affects a user’s
onsite journey and helps in rectifying the issues faster. The better the user experience, the
greater theonsite engagement.
Performance testing, when done effectively and consistently, can greatly boost
conversions while also enhancing the overall experience of site users. The following
reasons explain the significance of testing and optimization:
● Coupon codes or gift vouchers are provided to increase product sales and performance
tests ensure that coupon codes work well when applied to users in bulk. Multiple systems
like emailservers, social network sites, and enterprise content management systems are
involved in thebackend and the performance test ensures flawless functioning of various
features like product images/videos, and social media in such an integrated system.
● e-Commerce applications usually have more users than any other application and
validation ofusers is a must to filter out genuine customers. Performance test helps in
validating multiple sign-up and invoice email notifications in parallel.
● Augmented Reality (AR) is an advanced-level feature provided by modern e-Commerce
websitesso that customers can feel better without seeing products in person. With
augmented reality performance testing, we can make the feature more efficient and pleasing
to the eye.
● A recommendation system is a program that generates online recommendations using
severalalgorithms, artificial intelligence, and data analysis. A well-designed
recommendation systemhelps in better customer acquisition and retention. It is developed
for both new and existing customers with different behavior for different customer types.
Performance testing helps inmaking the recommendation system a faster system, to retain
online shoppers.
● Chatbots interact with online shoppers to improve the user experience, and any delay in
providing the required information may switch users to a competitor’s application.
Performancetests speed up chatbots to answer customer queries.
● Reviews are very important to increase the sale of a product. The majority of users prefer
visitingthe review listing page to get instant user feedback. Performance test helps in
optimizing customer review listing load time.
● e-Commerce applications attract the maximum number of customers during annual sales
events.Backend servers should be set with the optimal settings, keeping future users’ traffic
in mind. Performance tests help in identifying the servers’ optimum locations to manage a
higher numberof users.
● Slow DB server: Database size increases with the increase in product items of all ages, so
ensureto optimize DB queries.
● Faster Integrated Systems Communication: Multiple systems like email servers, social
media accounts, and payment channels are involved in the functioning of an e-Commerce
applicationto ensure that integrated systems work well under a heavy load.
● System Scaling: Brands cannot predict user load during peak hours; hence, the need of the
houris to be ready with tested scalable systems.
● Immoderate Scripts: Few E-Commerce applications are associated with third- party scripts
thatare running in the background like Google Analytics and Ads, and these widgets can
be a significant contributor to page load time.
● Slow Servers: Server resources and applications should be optimized to deliver content as
quicklyas possible after addressing any content-related performance issues.
● Massive Media: Oftentimes, images, videos, and other media are uploaded by non-
technical employees that aren’t familiar with the impact of loaded heavy files. It’s
important to ensurethese assets are optimized to maximize performance
Main Features to be Tested in E-Commerce Applications
Your e-Commerce website’s success depends on choosing the features to test to ensure that it
performsflawlessly. Some of the major features that require testing are as follows:
● Searching For a Product: e-Commerce sites provide various search filters to make the
search experience faster, which include price range, product type, country, and age. Hence,
ensure thatsearching for a product among billions of records does not halt the system and
return the expected records.
● Virtual Reality: Modern E-Commerce sites provide advanced-level features to visualize
products. Online shoppers can now see how they would look wearing an item virtually
Hence, we need toensure the smooth movement of virtual images for a better experience.
● Testing Payment Gateway Integration: Failed transactions are one of the main reasons why
most customers exit an application without completing the purchase. So, it’s important to
ensure theproper functioning of payment gateways.
● Product Details Page: A fast product listing is important because every consumer
will beattracted to the product by how it’s presented and how it’s visible to them.
Mentioned below are some of the best practices for testing e-Commerce applications:
● Test all CDNs (content delivery networks) by repeating time-bound hot transactions
multipletimes.
● Performance testing of big data plays an important role to ensure faster decompression
andcompression cycles to speed up the application’s speed.
● Online shopping has opened doors worldwide for businesses. Vendors shifted their servers
to the cloud for better user coverage. Hence, tests from various geo-locations need to be
performed to identify latency issues and to ensure that the geographical location of a user
doesnot affect the speed of the application.
● Test individual servers before integration system testing to find bottlenecks like email
servers,social accounts, DB servers, and enterprise content management systems.
● Volume testing plays a crucial role in seeing how storage systems function with or
without aheavy load, hence including it in the test scope is a good practice.
Role of QA Source
Testing experts at QA Source have years of experience in running performance tests on a
wide range ofdomains including e-Commerce, media streaming, legal, human resources,
eLearning, healthcare, enterprise content management, financial, and many more. QA
Source assists teams in setting up theperformance test lab and identifying the best-fit
performance test scenarios to ensure the best user experience. Following are our high-level
performance testing services to meet the performance test requirement:
● Performance test plan
● Test data setup
● Simulation of test cases
● Generate performance test suite results
● Identify bottlenecks and follow up with the Dev team to fix them
● Generate daily status reports
RESULT:
Performance testing of e-Commerce applications is a crucial part of any Business’s
success. It helps eCommerce applications generate better user experience, safeguard user data
security, and ensuremobile responsiveness, security, and a quick load time. It is vital to
conduct quick and effective application performance testing from time to time to ensure that
the application is offering an exceptional customer experience to maximize revenue for
businesses.
Exp.No.7
AUTONMATE TESTING OF E-COMMERCE APPLICATION USING
Date: SELENIUM
AIM:
ALGORITHM:
1. Import the necessary libraries such as time and web driver from Selenium.
2. Create an instance of the WebDriver, specifying the browser (e.g., Chrome).
3. Use the WebDriver to navigate to the registration page URL.
4. Find the username input field on the registration form using a suitable method.
5. Use JavaScript to set the value of the username field to the desired username.
6. Find the password input field on the form using an appropriate method.
7. Utilize JavaScript to set the value of the password field to the desired password.
8. Locate the submit button and click it to submit the form.
9. If the form submission opens a new window or tab (e.g., a success page), switch to it.
10. Verify that the submission was successful (e.g., by checking for a success message).
Program
//1.html
<html>
<head>
<!--IncludeJSFileHere -->
</head>
<body>
<div class="container">
<div class="main">
<label>Password:</label>
</form>
</div>
</div>
</body>
</html>
//success.html
<html>
<head>
</head>
<body>
<h2>SuccessfulLogin!</h2>
</body>
</html>
Selenium code for User Registration
import time
from selenium import WebDriver browser =
WebDriver. Chrome() browser.
Get('http://127.0.0.1:5500/1.html') #time.sleep(5)
uname = browser.find_element("id", 'username')
browser.execute_script("arguments[0].value = 'Form';",
uname)#time.sleep(5)upass = browser.find_element("id",
'password') browser.execute_script("arguments[0].value = '123';",
upass)#time.sleep(5) browser.find_element("id",
'submit').click()#time.sleep(5)
newURl =
browser.window_handles[0]
browser.get(newURl)
RESULT:
Thus, the execution of the ecommerce application using the selenium is
successfully executed.
Exp.No.8
INTERGRATING TESTNG WITH THE TEST AUTOMATION
Date:
AIM:
ALGORITHM:
TestNG is a powerful testing framework, an enhanced version of JUnit which was in use for a long time
before TestNG came into existence. NG stands for 'Next Generation'.
Step 3 − The dialog box 'Add Repository' opens. Enter the name as 'TestNG' and click 'OK'
Step 4 − Click 'Select All' and 'TestNG' would be selected as shown in the figure
Step 5 − Click 'Next' to continue.
Step 6 − Review the items that are selected and click 'Next'.
Step 10 − The Installer prompts to restart Eclipse for the changes to take effect. Click 'Yes'.
TestNG-Eclipse Setup
Step 1 − Launch Eclipse and create a 'New Java Project' as shown below.
Result:
EXNO : 9 DEVELOP A MINI PROJECT
DATE : BUILD A DATA-DRIVEN FRAMEWORK USING SELENIUM and TestNG
BUILD PAGE OBJECT MODEL USING SELENIUM AND TestNG
BUILD BDD FRAMEWORK WITH SELENIUM,TestNG AND CUCUMBER
AIM:
The Page Object model is an object design pattern in Selenium, where web pages are represented a classes,
the various elements on the page are defined as variables in the class and all possible user interaction can
then be implemented as methods in the class.
Cucumber:
Cucumber is one such open-source tool, which supports Behavior Driven Development(BDD). In simple
words, Cucumber can be defined as a testing framework, driven by plain English. It serves as documentation,
automated tests, and development aid – all in one.Dependency List
1 <properties>
2<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3<cucumber.version>7.14.0</cucumber.version>
4<selenium.version>4.14.0</selenium.version>
5<webdrivermanager.version>5.5.3</webdrivermanager.version>
6<testng.version>7.8.0</testng.version>
7<apache.common.version>2.4</apache.common.version>
8<maven.compiler.plugin.version>3.11.0</maven.compiler.plugin.version>
9<maven.surefire.plugin.version>3.1.2</maven.surefire.plugin.version>
10<maven.compiler.source.version>11</maven.compiler.source.version>
11<maven.compiler.target.version>11</maven.compiler.target.version>
12</properties>
13
14<dependencies>
15
16<dependency>
17<groupId>io.cucumber</groupId>
18<artifactId>cucumber-java</artifactId>
19<version>${cucumber.version}</version>
20</dependency> 21
22<dependency>
23<groupId>io.cucumber</groupId>
24<artifactId>cucumber-testng</artifactId>
25<version>${cucumber.version}</version>
26<scope>test</scope>
27</dependency> 28
29<!-- Selenium -->
30<dependency>
31<groupId>org.seleniumhq.selenium</groupId>
32<artifactId>selenium-java</artifactId>
33<version>${selenium.version}</version>
34</dependency> 35
36<!-- Web Driver Manager -->
3<dependency>
38<groupId>io.github.bonigarcia</groupId>
39<artifactId>webdrivermanager</artifactId>
40<version>${webdrivermanager.version}</version>
41</dependency> 42
43<!-- TestNG -->
44<dependency>
45<groupId>org.testng</groupId>
46<artifactId>testng</artifactId>
47<version>${testng.version}</version>
48<scope>test</scope>
49</dependency> 50
51<!-- Apache Common -->
52<dependency>
53<groupId>org.apache.directory.studio</groupId>
54<artifactId>org.apache.commons.io</artifactId>
55<version>${apache.common.version}</version>
56</dependency> 57
58</dependencies
73<artifactId>maven-compiler-plugin</artifactId>
74<version>${maven.compiler.plugin.version}</version>
75<configuration>
76<source>${maven.compiler.source.version}</source>
77<target>${maven.compiler.target.version}</target>
78</configuration>
79</plugin>
80<plugin>
81<groupId>org.apache.maven.plugins</groupId>
82<artifactId>maven-surefire-plugin</artifactId>
83<version>${maven.surefire.plugin.version}</version>
84<configuration>
85<suiteXmlFiles>
86<suiteXmlFile>testng.xml</suiteXmlFile>
87</suiteXmlFiles>
88</configuration>
89</plugin>
90</plugins>
</build>
</project>
Step 8 – Create a feature file in the src/test/resources
Create a folder with name features. Now, create the feature file in this folder. The feature file should be saved with the
extension .feature. This feature file contains the test scenarios created to test the application. The Test Scenarios are written
in Gherkins language in the format of Given, When,
Then, And, But.
Below is an example of Test Scenarios in the feature file. I have failed one test scenario intentionally –
@MissingUsername.
1.Feature: Login to HRM Application
2
3Background:
4Given User is on HRMLogin page "https://opensource-demo.orangehrmlive.com/"
5
6@ValidCredentials
7Scenario: Login with valid credentials
8
9When User enters username as "Admin" and password as "admin123"
10Then User should be able to login successfully and new page open
11
12@InvalidCredentials
13Scenario Outline: Login with invalid credentials
14
15When User enters username as "<username>" and password as "<password>"
16Then User should be able to see error message "<errorMessage>" 17
18Examples:
19| username | password | errorMessage|
20| Admin| admin12$$ | Invalid credentials|
21| admin$$| admin123 | Invalid credentials|
22| abc123| xyz$$| Invalid credentials| 23
24
25@MissingUsername
26Scenario Outline: Login with blank username 27
28When User enters username as " " and password as "admin123"
29Then User should be able to see a message "Required1" below Username
Step 9 – Create the classes for locators, actions, and utilities in src/main/java
Create folders – actions, locators, and utils in src/main/java.
Now, we need to create the Step Definition of the Feature File – LoginPageDefinitions.java.
Create a Java Class for each page where define WebElements as variables using Annotation @FindBy. Create another Java
class that contains methods for actions performed on WebElements. Here, I’m going to create 2 classes for locators –
LoginPageLocators and HomePageLocators as well as 2 classes
for actions – LoginPageActions and HomePageActions
The Locator class contains WebElements which are identified by @FindBy annotation as shown below:-
1@FindBy(name = "txtUsername")
2WebElement userName;
Action class contains methods for the action to be performed on the web elements identified in the locator class.
The initElements is a static method of PageFactory class that is used to initialize all the web elements located by @FindBy
annotation. Only after the WebElements are initialized, they can be used in the methods to perform actions.
1publicLogin(WebDriver driver) {
2this.driver = driver;
3// This initElements method will create all WebElements
4PageFactory.initElements(driver, this);
5}
Below is the sample code of the LoginPageLocators.
1import org.openqa.selenium.WebElement;
2import org.openqa.selenium.support.FindBy;
3
4public class LoginPageLocators { 5
6@FindBy(name = "username")
7public WebElement userName; 8
9@FindBy(name = "password")
10public WebElement password; 1
12@FindBy(xpath = "//*[@id='app']/div[1]/div/div[1]/div/div[2]/div[2]/form/div[1]/div/span")
13public WebElement missingUsernameErrorMessage; 14
15@FindBy(xpath = "//*[@id='app']/div[1]/div/div[1]/div/div[2]/div[2]/form/div[3]/button")
16public WebElement login; 17
1@FindBy(xpath = "//*[@id='app']/div[1]/div/div[1]/div/div[2]/div[2]/div/div[1]/div[1]/p")
19public WebElement errorMessage;
20
21}
Below is the sample code for the HomePageLocators.
1import org.openqa.selenium.WebElement;
2import org.openqa.selenium.support.FindBy;
3
4public class HomePageLocators {
5
6@FindBy(xpath = "//span[@class='oxd-topbar-header-breadcrumb']/h6")
7public WebElement homePageUserName;
8
9}
Create the action classes for each web page. These action classes contain all the methods needed by the step definitions. In
this case, I have created 2 action classes – LoginPageActions, HomePageActions LoginPageActions
1import org.example.locators.LoginPageLocators;
2import org.example.utils.HelperClass;
3import org.openqa.selenium.support.PageFactory;
4
5public class LoginPageActions {
6
7 LoginPageLocators loginPageLocators = null; 8
9public LoginPageActions() {
10
11
12
13
14}
15
this.loginPageLocators = new LoginPageLocators(); PageFactory.initElements(HelperClass.getDriver(),loginPageLocators);
16// Get the error message when username is blank
17public String getMissingUsernameText() {
18return loginPageLocators.missingUsernameErrorMessage.getText()
19}
20
21// Get the Error Message
22public String getErrorMessage() {
23return loginPageLocators.errorMessage.getText();
24}
25
26public void login(String strUserName, String strPassword)
27
28// Fill user name
29loginPageLocators.userName.sendKeys(strUserName);
30
31// Fill password
32loginPageLocators.password.sendKeys(strPassword);
33
34// Click Login button
35loginPageLocators.login.click();
36
37}
HomePageActions
1import org.example.locators.HomePageLocators;
2import org.example.utils.HelperClass;
3import org.openqa.selenium.support.PageFactory;
4
5public class HomePageActions {
6
7HomePageLocators homePageLocators = null;
8
9public HomePageActions() {
10
11this.homePageLocators = new HomePageLocators();
12PageFactory.initElements(HelperClass.getDriver(),homePageLocators);
13}
14
15// Get the User name from Home Page
16public String getHomePageText() {
17return homePageLocators.homePageUserName.getText();
18}
19
20}
Create a Helper class where we are initializing the web driver, initializing the web driver wait, defining
the timeouts, and creating a private constructor of the class, it will declare the web driver, sowhenever we create
an object of this class, a new web browser is invoked.
1 package com.example.utils;
2
3 import java.time.Duration;
4 import org.openqa.selenium.WebDriver;
5 import org.openqa.selenium.chrome.ChromeDriver;
6 import io.github.bonigarcia.wdm.WebDriverManager;
7 import org.openqa.selenium.chrome.ChromeOptions;
8
9 public class HelperClass {
10
11 private static HelperClass helperClass;
12
13 private static WebDriver driver;
14 public final static int TIMEOUT = 5;
15
16 private HelperClass() {
17
18 WebDriverManager.chromedriver().setup();
19 ChromeOptions options = new ChromeOptions();
20 options.addArguments("--start-maximized");
21 driver = new ChromeDriver(options);
22 driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(TIMEOUT));
23 }
24
25 public static void openPage(String url) {
26 driver.get(url);27
}
28
29 public static WebDriver getDriver() {
30 return driver;31
}
32
33 public static void setUpDriver() {
34
35 if (helperClass==null) {
36
37 helperClass = new HelperClass();
38 }
39 }
40
41 public static void tearDown()
42
43 if(driver!=null) {
driver.close();
driver.quit();
}
helperClass = null
}}
Step 10 – Create a StepDefinition class in src/test/java
Create a Java Class called Definition where we will create the Test Code related to the Given, When
, Then of Feature file in src/test/java.
Now, we need to create the Step Definition of the Feature File – LoginPageDefinitions.java.
1import io.cucumber.java.en.Given;
2 import io.cucumber.java.en.Then;
3 import io.cucumber.java.en.When;
4 import org.example.actions.HomePageActions;
5 import org.example.actions.LoginPageActions;
6 import org.example.utils.HelperClass;
7 import org.testng.Assert; 8
9 public class LoginPageDefinitions { 10
11 LoginPageActions objLogin = new LoginPageActions();
12 HomePageActions objHomePage = new HomePageActions(); 13
14 @Given("User is on HRMLogin page {string}")
15 public void loginTest(String url) { 16
17 HelperClass.openPage(url); 18
19 }
20
21 @When("User enters username as {string} and password as {string}")
22 public void goToHomePage(String userName, String passWord) { 23
24 // login to application
25 objLogin.login(userName, passWord); 26
27 // go the next page 28
29 }
30
31 @Then("User should be able to login successfully and new page open")
32 public void verifyLogin() { 33
34 // Verify home page
35 Assert.assertTrue(objHomePage.getHomePageText().contains("Dashboard")); 36
37 }
38
39 @Then("User should be able to see error message {string}")
40 public void verifyErrorMessage(String expectedErrorMessage) { 41
42 // Verify error message
43 Assert.assertEquals(objLogin.getErrorMessage(),expectedErrorMessage); 44
45 }
46
47
48
49
50
51
52
53 }
@Then("User should be able to see a message {string} below Username") public void
verifyMissingUsernameMessage(String message) {
Assert.assertEquals(objLogin.getMissingUsernameText(),message);
}
2 import com.example.utils.HelperClass;
3 import io.cucumber.java.After;
4 import io.cucumber.java.Before;
5 import io.cucumber.java.Scenario;
7
8 public class Hooks {
9
10 @Before
11 public static void setUp() {
12
13 HelperClass.setUpDriver();
14 }
15
16 @After
17 public static void tearDown(Scenario scenario) {
18
19 //validate if scenario has failed
20 if(scenario.isFailed()) {
21 final byte[] screenshot = ((TakesScreenshot) HelperClass.getDriver())
22 .getScreenshotAs(OutputType.BYTES);
23 scenario.attach(screenshot, "image/png", scenario.getName());24
}
25
26 HelperClass.tearDown();
27 }
}
Step 12 – Create a TestNG Cucumber Runner class in the src/test/java
Cucumber needs a TestRunner class to run the feature files. It is suggested to create a folder with
the name of the runner in the src/test/java directory and create the Cucumber TestRunner class in
this folder. Below is the code of the Cucumber TestRunner class.
Below is the code for
CucumberRunnerTests
class.
1 import
io.cucumber.testng.Abst
ractTestNGCucumberTe
sts;
32 import
io.cucumber.testng.Cuc
umberOptions;
4 @,
gCluuec=um"obregr.Oe
xpatmiopnlse(.tdaegfsin
=it"i"o,nfse"a,tures =
"src/test/resources/featu
res/LoginPage.feature"
5 plugin = {}) 6
7 public class
CucumberRunnerTests
extends
AbstractTestNGCucum
berTests {
8 }
Note:- The name of the
Runner class should end
with Test otherwise we
can’t run the tests using
Command Line.
Step 13 – Run the tests
from TestNG
You can execute the test
script by right-clicking
on TestRunner class ->
Run As TestNG.
(Eclipse)
In the case of the IntelliJ project, rightclick on the runner class and select Run
‘CucumberRunnerTests’.
The output of the above program is
Index.html
TestNG also produces an “index.html” report. The below image shows the index.html report.
RESULT: