0% found this document useful (0 votes)
8 views28 pages

STA - UNIT V march 13

The document discusses automated software testing, detailing its evolution through various generations, from manual testing with scripted automation to AI/ML-driven automation. It outlines the purposes, types of tests suitable for automation, the stages of the automation testing life cycle, and various automated testing tools and frameworks. Additionally, it highlights the advantages and disadvantages of automation testing in the software development lifecycle.

Uploaded by

rg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views28 pages

STA - UNIT V march 13

The document discusses automated software testing, detailing its evolution through various generations, from manual testing with scripted automation to AI/ML-driven automation. It outlines the purposes, types of tests suitable for automation, the stages of the automation testing life cycle, and various automated testing tools and frameworks. Additionally, it highlights the advantages and disadvantages of automation testing in the software development lifecycle.

Uploaded by

rg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

CCS366- SOFTWARE TESTING AND

UNIT V
TEST AUTOMATION AND TOOLS
Automated Software Testing, Automate Testing of Web Applications, Selenium:
Introducing Web Driver and Web Elements, Locating Web Elements, Actions on Web
Elements, Different Web Drivers, Understanding Web Driver Events, TestNG:
Understanding TestNG.xml, Adding Classes, Packages, Methods to Test, Test Reports.

5.1 AUTOMATED SOFTWARE TESTING


Automated software testing is the method of automatically reviewing and
validating software products, such as web and mobile applications. This process ensures
that they meet all predefined quality standards for code style, functionality, and user
experience. Test automation replaces manual human activity with systems. Even though
tests, like regression or functional testing, can be done manually, automating the process will
reduce the time taken to perform the tests. Moreover, it takes less time to perform
exploratory tests and more time to maintain test scripts, thus, increasing the overall test
coverage.

5.1.1 : Evolution of Automated Testing (Generations of Automation)


Automation in software testing has evolved significantly over the years, and different
generations of automation reflect the advancement of tools, methodologies, and practices.

1st Generation: Manual Testing + Scripted Automation


● Era: 1950s - 1980s
● Overview: The first generation of automation was focused on transitioning manual
testing into the digital realm using basic scripts.
● Characteristics:
o Manual Testing Dominates: Testing was mostly manual, and scripts were
created for repetitive tasks.
o Tools Used: Early automation tools were primarily focused on record-and-
playback methods (e.g., WinRunner, QTP).
o Focus: The goal was to automate repetitive test execution and reduce human
error.
o Challenges: Tools were rudimentary and offered limited flexibility. Automation
was largely used for regression testing rather than complex test cases.
2nd Generation: Functional Test Automation
● Era: 1990s - Early 2000s
● Overview: The second generation expanded on the first by incorporating functional
automation that was more integrated into development and testing processes.
● Characteristics:
o More Advanced Tools: Tools like Selenium (launched in 2004) and JUnit
emerged. These tools supported better integration with continuous integration
(CI) systems.
o Test Coverage Expansion: Focused on increasing test coverage, especially for
functional and regression testing.
o Scripting Languages: More advanced scripting languages (e.g., Java, Python)
began to be used, making the automation more adaptable.
o Better Integration: Testing tools integrated better with the development
environment, improving collaboration between developers and testers.
o Challenges: Test maintenance became harder with the growth of code bases. The
scripts were often fragile and required frequent updates.
3rd Generation: Continuous Integration & Continuous Testing
● Era: 2000s - 2010s
CCS366- SOFTWARE TESTING AND
● Overview: Automation evolved alongside agile methodologies and DevOps practices.
Continuous testing (CT) became an important part of the software development lifecycle.
● Characteristics:
o CI/CD Integration: Automation tools were integrated into CI/CD pipelines,
making tests run automatically every time code changes are committed.
o Test Automation Frameworks: Frameworks like JUnit, TestNG, and Appium
became more sophisticated, enabling more complex test strategies.
o Parallel Execution: Parallel testing techniques and distributed testing became
more prevalent.
o Shift-left Testing: Testing was performed earlier in the software lifecycle,
allowing bugs to be caught early.
o Challenges: Increased focus on automated regression testing, leading to high
maintenance of test scripts. Achieving stable automation across large systems
was still a challenge.
4th Generation: AI/ML-Driven Automation
● Era: 2015 - Present
● Overview: The latest generation of automation testing is heavily influenced by artificial
intelligence (AI) and machine learning (ML) algorithms.
● Characteristics:
o AI and ML in Test Creation: Tools are using AI/ML to create, optimize, and
maintain test scripts, reducing the need for manual test creation.
o Self-Healing Automation: AI-powered tools can automatically adjust and fix
tests when application elements change (e.g., name, attributes).
o Predictive Analysis: ML models predict areas of code that are likely to break
based on past behavior, helping focus testing efforts.
o Natural Language Processing (NLP): Tools like Testim.io and mabl are
utilizing NLP to allow testers to write tests in plain language.
o Autonomous Testing: Some tools are moving toward fully autonomous testing,
requiring minimal human input.
o Challenges: Complexity increases as testers need a deep understanding of AI/ML
techniques. Tools still require quality data and fine-tuning.

5th Generation: Autonomous Test Generation & Execution


Each generation of test automation has focused on reducing human intervention, increasing
efficiency, and improving the ability to detect issues early. The future promises even more
intelligent and adaptive systems, where testing is largely automated and self-healing.

5.1.2 : Purpose of Automation Testing:


Automation testing serves several important purposes in the software development lifecycle.
Let's explore some key reasons why organizations embrace automation testing:
1. Increased Test Coverage: Automation testing enables a broader scope of test coverage.
Organizations can leverage a test automation platform and use it to design test scripts to
cover various scenarios and test cases, ensuring thorough validation of software
functionality. With automated tests, organizations can achieve higher levels of test coverage,
resulting in improved software reliability.
2. Consistency and Reusability: Automation testing ensures consistent test execution by
removing the element of human error. Using test automation platform to automate testing,
you can reuse test scripts across multiple test cycles and different software versions. This
reusability not only saves time but also promotes consistency in testing, enabling accurate
comparison of results over time.
3. Early Detection of Defects: Automation testing enables early detection issues. By running
automated tests at different stages, such as during integration or regression testing, potential
bugs can be identified and addressed promptly. Early defect detection helps in reducing the
CCS366- SOFTWARE TESTING AND
costs.

5.1.3 : Kinds of Tests that should be Automated:


While testing an application/software, testers cannot automate all processes involved in the
testing cycle. Some tests need human supervision and involvement to get better results.
Using test automation platforms to automate testing is not an alternative to manual testing but
helps and supports the entire testing team by reducing the workload.

In order to determine whether a test is suitable for automation, testers can check if it fits the
following criteria:
• The tests should be highly repetitive and take a long period of time to perform if it is
done manually
• The testing path must be predictable, as it has been verified earlier through manual testing
• The tests that involve the testing of frequently used features that introduce high-risk
conditions
• The tests that require multiple datasets and run on several different hardware or
software platforms and configurations
• Tests that are not possible for human manual testing, e.g., thousands of concurrent users
trying to log in at the same time
If a test meets all these criteria mentioned above, you can consider test automation platforms

5.1.4 : Stages (Phases) of Automation Testing Life Cycle (ATLC)


Automation testing life cycle is a multi-stage process that consists of the tasks necessary to
identify and introduce an automation test tool, write and run test cases, develop test designs, and
build and manage test data and environment. Six phases are important.
1. Deciding The Scope of Test Automation
The first stage of automation testing life cycle aims to discover the feasibility of automation. It is
essential to perform a feasibility analysis on the manual test cases that helps automation
engineers to design the test scripts.
We address the following in the first stage -
● Which components of the applications can be automated?
● Which tests can be automated and how to automate them?
● Factors like cost, team size and capabilities must also be considered.
Feasibility checks like Test Case Automation feasibility and AUT Automation feasibility should
be performed before starting the test automation.

Deciding the Scope of Test Automation

Choosing the Right Automation Tool

Plan, Design, and Strategy

Set-up Test Environment

Test Script & Execution

Test Analysis & Reporting


CCS366- SOFTWARE TESTING AND

2. Choosing The Right Automation Tool


While choosing an automation tool, the technologies being used in the project, the familiarity of
the tool with the team, intuitiveness, and flexibility must be considered. For example, if you are
looking for an automated browser compatibility testing tool then the variety of browsers offered
is a critical deciding parameter.
We must do a comparative study of automation tools before making a decision. Some of the
frequently used automation tools nowadays are Selenium, Appium, Katalon Studio, Cucumber,
SoapUI, Worksoft, Test Studio, Lambda Test, Test Complete and Testimony.
3. Plan, Design, and Strategy
Selecting a test automation framework is the first and foremost thing to do in the Test Strategy
phase of Automation Testing Life Cycle.
The team of test engineers design a test architecture to describe the test program structure and
the way test procedures are managed.
We consider the following things when planning this phase :
● Gather all manual test cases from the test management tool to identify which test
cases need to be automated.
● Identify which framework to be used after understanding the pros and cons of the
testing tools.
● Build a test suite for Automation test cases in the selected tool for test management.
● Ensure to mention the background, risk, and dependency between the tool and
application in the test plan.
● Seek approval on the test strategy from clients or stakeholders.

4. Set-Up Test Environment


Key areas for the Test Environment setup :
● Check for the required software, licenses and hardware.
● Maintain a checklist of automation tools and their configurations.
● Test data – Test environment setup are populated with similar to production data.
● Front-End Running Environment – Availablity of front-end running environment to
perform load testing for analyzing the capabilities of handling web traffic.
● Checklist of all the Systems, modules and applications to be put under test.
● Availablity of the staging environment.
● Test across various operating systems, browsers and browser versions.
● Test your web applications on low and high network to realize the difference
between rendering time.
● Document all the Configuration/Installation/User manuals in a central repository.
● Planning the scheduled use of the test environment.

5. Test Script & Execution


Once we introduce the test environment, the next step is to develop and execute the test scripts.
● Create scripts based on project requirements.
● Use a currency approach throughout the process.
● Scripts must be reusable, simple, and structured so that anyone can understand
them.
● Perform proper code reviews and reporting to get better insights and maintain
quality throughout the process.
● We must incorporate the following during test executions -
● Test cases should cover all functional aspects.
● They should cover all platforms and environments.
● They must be processed in batches to save time and effort.
● Always document bug reports, preventing any functional errors.
Evaluating and documenting test results for further reference is done in this stage of the ATLC.
CCS366- SOFTWARE TESTING AND
6. Test Analysis & Reporting
In this phase, we gather the test automation results and share them with the team, stakeholders
and client. Test results must be easy to understand for everyone involved. Proper filters must be
used in the report.
For maintenance, test cases are updated and automated regularly as per the functional or UI
changes or new testing criterias.
Conclusion
The 6 stages of automation testing life cycle are crucial for ensuring the effective
implementation of automated testing.

5.1.5 : Various Types of Automated Software Testing:


1. Unit Testing:
The testing of each unit of the software application is known as unit testing. As it is the first
level of testing, you can use test automation platforms to automate it. This type of testing is
used to validate unit components with their performance. Primarily, unit testing is performed
during the development phase.
2. Smoke Testing:
Smoke testing is usually done on a build software received from the development team. The
focus of the smoke tests is to check whether the build software is stable or not. If the
software passes this test, then testers can proceed with further testing.
3. Integration Testing:
Integration testing is the testing process that is performed after unit testing. This test ensures
that units or individual components of the software are tested in a group and work well as a
whole. This test is used to detect defects at the time of interaction between integrated
components or units.
4. Regression Testing
Regression testing is both functional and non-functional type of testing. It verifies the code
changes that do not impact the software's existing functionality. This testing ensures that the
software works fine with new functionality, bug fixes, or code changes in the existing
feature. With HeadSpin’s test automation platform, testing teams can perform regression
automation testing for their apps/websites. HeadSpin's Regression Intelligence is a powerful
comparison tool for analyzing degradation across new app builds, OS releases, feature
additions, locations, and more. Using the test automation platform, testers can also compare
build over build, location over location, network over network, and device over device
performance of their apps/websites.
5. API Testing
The application programming interface (API) is the connection between all the other systems
that software needs to function. This testing verifies all APIs. API testing is mainly used to
test the programming interfaces' functionality, reliability, performance, and security.
While executing API testing with the HeadSpin Platform, the API usage monitoring feature
will help testers keep track of how their APIs are being used by applications or track the
impact of 3rd party APIs on application performance.
6. Security Testing
Security testing is also functional and non-functional in nature. It detects the weaknesses and
threats in the software. This testing can block the attacks from hackers and ensure the
security of the software.
7. Performance Testing
Performance testing records the system performance of the software in terms of
responsiveness and stability under a specific workload. The main parameters checked under
this testing
include the software's speed, robustness, and reliability.
8. Acceptance Testing
Acceptance testing is used to check how end users will respond to the final software product.
Usually, this is the last type of testing used before a software/application is released.
CCS366- SOFTWARE TESTING AND

5.1.6 : Automated Software Testing Tools


Automated testing tools have become indispensable in achieving this goal efficiently. These
tools speed up the testing process and enhance its accuracy. Some automated software testing
tools are listed below :
✔ Selenium - Selenium supports multiple languages and browsers, focusing on web
application testing.
✔ TestComplete - TestComplete supports desktop, mobile, and web applications.
✔ JUnit - JUnit facilitates unit testing with simplicity and ease of use.
✔ Cypress - Cypress is a modern web testing tool designed to work exclusively with
web applications.
✔ Robot Framework - Robot Framework is designed for acceptance testing
✔ Cucumber - Cucumber allows for the specification of application behavior in plain
language. This makes tests easy to read and understand.

5.1.7 : Different Types of Test Automation Frameworks:


In the test automation process, testing frameworks play a crucial role. These frameworks
include guidelines for testers/developers in coding standards, repository management, and
handling of test data. The main focus of these frameworks is to reduce maintenance costs and
testing efforts and achieve a high return on investment for the testing teams.
The different types of automated software testing are given below:
1. Linear Automation Framework
The linear test automation framework guides testers to create functions without writing
codes, and the steps in this framework are given in sequential order. While testing with this
framework, testers record every step and play the script back automatically to repeat the test.
2. Modular-based Testing Framework
In the modular-based testing framework, testers need to divide the application/software under
test into separate units or sections. These separate units or sections are tested in isolation.
Individual test scripts are created for each part, and after testing, all parts are combined to
build larger tests that represent various test cases.
3. Data-driven Framework
In the data-driven framework, the test data are separated from script logic, and testers can
store all the data externally. With this framework, whenever testers need to test
application/software multiple times with different data sets, they can use the data stored in
external data sources..
4. Keyword-driven Framework
Keywords are also stored in the external data table. These keywords represent the various
actions that are being performed to test the GUI of an application.
5. Hybrid Testing Framework
The hybrid framework is a combination of the already mentioned frameworks. This type of
framework is used to use some frameworks' advantages and mitigate others' weaknesses.

5.1. 8 Advantages of Automation Testing


● Simplifies Test Case Execution
● Improves Reliability of Tests.
● Increases amount of test coverage
● Minimizing Human Interaction
● Saves Time and Money
● Earlier detection of defects

5.1. 9 Disadvantages of Automation Testing


● High initial cost
● 100% test automation is not possible
● Not possible to automate all testing types
CCS366- SOFTWARE TESTING AND
● Programming knowledge is required
● Complex process
5.1. 10 :Test Automation Pyramid
The Test Automation Pyramid is a concept that helps guide the organization and strategy of
automated tests in software development. The pyramid consists of three main levels,
representing different types of tests that should be automated at various stages of development.:

1. Unit Tests (Bottom Layer)


● Focus: Tests small, isolated pieces of code (functions, methods, classes).
● Purpose: To ensure that individual units of code work correctly in isolation.
● Speed: Fast execution because they run on a small scope of code.
● Example: Testing if a function returns the expected result for a given input.
● Characteristics:
o Cheap to write and run.
o Should cover most of the codebase.
o Focuses on the internal logic of the application.

2. Service/Integration Tests (Middle Layer)


● Focus: Tests the interaction between different components, services, or systems (e.g.,
database, external APIs).
● Purpose: To ensure that different parts of the application work together as expected.
● Speed: Slower than unit tests because they involve multiple components or external
systems.
● Example: Testing if a web service correctly integrates with a database.
● Characteristics:
o Focus on testing system interactions.
o May involve some level of external dependencies, which could make tests more
complex and slower.

3. End-to-End (E2E) Tests (Top Layer)


● Focus: Tests the full system from start to finish, simulating real-world user interactions.
● Purpose: To verify that the application as a whole behaves correctly from the user's
perspective.
● Speed: Slow execution, as they simulate user interactions with the entire system.
● Example: Testing if a user can successfully log in and complete a purchase on an e-
commerce website.
● Characteristics:
o Focuses on overall system behavior and user experience.
o Expensive to write and maintain.
o Often run less frequently (e.g., on specific builds or milestones).

By following the pyramid approach, test automation becomes a structured and balanced part of
your software development lifecycle, helping you catch issues early without slowing down the
release process.
CCS366- SOFTWARE TESTING AND

5.2 AUTOMATE TESTING OF WEB APPLICATIONS

Web Application Testing :


✔ Web Application Testing ensures that a web app works as expected across browsers,
devices, and platforms.
✔ Testing a web application is a highly crucial and essential part of software
development. It is a software practice that can be automated with the combination of
different tools related to it.
✔ It eventually reduces the need for human intervention and leads to incredible speed,
reliability, and efficiency in it.
✔ It can be implemented and accomplished using various types of software automation
testing tools and types of it for that particular purpose and eventually increase the
performance and enhance the user interface of it.

5.2.1 Types of Web App Testing that can be automated:

✔ Functional Testing
A single end-user can make the whole system crash in minutes, even after unit, integration,
and performance tests have passed. This usually happens because the user does something
the developers did not expect. The purpose of functional testing is therefore to ensure that the
functionality of the software works as intended for an end-user. It tests this through the UI of
the application. Examples of functional tests in a web application UI include testing:
● The login to your web application is successful across browsers and devices
● The web application is interacting as intended with external databases and syncing
successfully
● Invoices are being sent and received with the correct information and securely
● Buttons, text fields, menus, etc., are working as per the requirements

✔ Usability Testing (UI/UX Testing)


Usability testing focuses on design aspects rather than functional aspects, assessing the user
experience, and how user-friendly the web application is.
Key aspects include:
● User Interface Evaluation: Analyzing the layout, design, and navigability.
● User Experience Testing: Assessing the ease of learning and using the application.
● Accessibility Testing: Ensuring the application is accessible to all users, including
those with disabilities.

✔ Regression Testing
Regression testing is critical whenever updates or changes are made to the application. It
ensures that new code doesn't negatively impact existing functionality. This type of testing:
● Verifies Existing Functionality: Ensures that previous functions still operate as intended
after modifications.
● Identifies Unintended Consequences: Catches any new bugs introduced by recent changes.
✔ End-to-End Testing
End-to-end testing examines the complete functionality of the web application from start to
finish, emulating real user scenarios. It aims to ensure that all components of the application
work together seamlessly. This involves:
● Workflow Testing: Ensuring all the integrated parts of the application interact
correctly.
● Data Integrity Testing: Confirming that data maintains its integrity throughout all
CCS366- SOFTWARE TESTING AND
transactions.

✔ Cross-Browser Testing
With the variety of browsers available, browser-based testing ensures that the web application
performs consistently across different browsers and their versions. This testing type:
● Ensures Compatibility: Verifies that the application functions correctly on various
browsers.
● Identifies Browser-Specific Issues: Highlights any layout or functional issues
unique to certain browsers.
● Related reading: How to automate web testing across browsers and devices
✔ Performance Testing
Performance testing evaluates the web application’s stability and responsiveness under various
conditions. This includes:
● Load Testing: Assessing the application's ability to handle high volumes of users.
● Stress Testing: Determining the application's breaking point and how it recovers
from failure.
● Speed Testing: Measuring response times and the speed of page loading under
normal conditions.

5.2.2 Steps involved in automating Web application testing


⮚ Planning - Identify the test cases that need to be automated and select the right tools.
⮚ Development – Writing code to execute the test cases
⮚ Execution – Execute the test cases
⮚ Reporting – Report on the results of the automated tests

5.2.3 Web app test automation best practices


(How to select a right automation tool for Web app testing)
Before you start automating your web application tests, make sure you draft a test automation
strategy to keep you on track. Things to keep in mind before you start automation are:
● What are the specific requirements of your web application?
● What types of tests do you need to automate?
● Which test automation tool best suits your requirements and goals, as well as the
resources on your team?
● How much maintenance will automation require?
As a first rule of thumb, start small, and once you’re comfortable, start scaling your
automation efforts. No one wants to end up with hundreds of automated test cases that are
impossible to maintain. Rather, think of automation like a bell curve - automate too little, and
the ROI on your potential tool costs and onboarding will be too high. Automate too much,
and the time you spend on changing or maintaining your tests starts to exceed the time saved.
Ideally, find the sweet spot in the middle where return is the highest.
Successful web application testing requires effective test automation processes, clear
communication within the team, an efficient strategy, and an automation tool that doesn’t
impair testers, but enables them.
The following are some considerations to help to choose the appropriate automation
tool:
⮚ Application type and Technology
⮚ Test requirements
⮚ Programming language
⮚ Learning Curve
⮚ Integration and Extensibility
⮚ Cost and licensing
CCS366- SOFTWARE TESTING AND
⮚ Maintenance and support
⮚ Team Collaboration

5.2.4 Why to automate Web application testing / Benefits of Web Application testing
There are so many reasons to automate web application testing including
✔ Increased Speed
✔ Reduced Cost
✔ Improved Quality
✔ Increased Confidence

5.2.5 Challenges (Disadvantages) of Web Application testing


✔ Initial investment is more
✔ High Maintenance
✔ Complex Process
✔ Lack of Expertise

5.2.6 Web Application Automated test tools:


Some of the tools for web application automated testing are given below:
a. Katalon Studio
Katalon Studio is an automation testing solution that provides users with a comprehensive set
of features for testing web, mobile, and API applications
Advantages:
● It is convenient and accessible to different types of testers
● It is flexible and easy to use with its quick, powerful features(robust).
Disadvantages:
✔ It only supports java .
✔ It is not an open-source tool.

Cucumber: Cucumber is a free, open-source testing framework that helps users write
automated tests in plain English. It's used for behavior-driven development (BDD).

Advantages:
● It is an open-source automated software testing tool.
● It helps in writing acceptance tests for our web applications.
Disadvantages:
● Integration and its dependency on generating reports through plugins can be
challenging enough.
● Every time a new attribute or feature undergoes it, we have to ensure all current steps
and validate them to see if they can be used.

Selenium : Selenium is an open-source testing tool that automates web application testing
across browsers and operating systems. It can be used for a variety of test types, including
system testing, regression testing, and performance testing.

Advantages:
● This tool is open-source and widely supports all languages and frameworks.
● It comes with heavy library packages.
● It supports cross-browser automation, API automation, and database automation.
CCS366- SOFTWARE TESTING AND
● Testers can use it for regression, exploratory testing, and quick reproduction of bugs.
● It is highly known for its flexibility with ease of implementation.

Disadvantages:
● Test Maintenance in selenium can become cumbersome and even expensive
sometimes
● Selenium requires coding skills, if not exceptional but above average
● It is only supported for web applications
● Technical support and its reliability can cause problems
5.3 SELENIUM: INTRODUCING WEB DRIVER AND WEB ELEMENTS
Selenium is a powerful tool for controlling web browsers through programs. It is functional
for all browsers, works on all major OS, and its scripts are written in various languages i.e.,
Python, Java, C#, etc., we will be working with Python. Selenium has four major
components : Selenium IDE, Selenium RC, Selenium Web driver, and Selenium GRID.

1. Selenium IDE
Selenium IDE is a Firefox add-on that allows users to record, edit, debug, and play back tests
captured in the Selenese format, which was introduced in the Selenium Core version. It also
provides us with the ability to convert these tests into the Selenium RC or Selenium
WebDriver format. We can use Selenium IDE to do the following:
● Create quick and simple scripts using record and replay, or use them in exploratory testing
● Create scripts to aid in automation-aided exploratory testing
● Create macros to perform repetitive tasks on Web pages
2. Selenium RC (Remote control)
Selenium Remote Control (RC) was one of the earliest Selenium tools,
preceding WebDriver. It allowed testers to write automated web application tests in various
programming languages like Java, C#, Python, etc. The key feature of Selenium RC was its
ability to interact with web browsers using a server, which acted as an intermediary between
the testing code and the browser. Its architecture is complex and has limitations. One must
have good programming language while working with Selenium RC.
3. Selenium WebDriver
Selenium WebDriver is the successor of Selenium RC (Remote Control), which has been
officially deprecated. Selenium WebDriver accepts commands using the JSON-Wire protocol
(also called Client API) and sends them to a browser launched by the specific driver class
(such as ChromeDriver, FirefoxDriver, or IEDriver). This is implemented through a browser-
specific browser driver. It works with the following sequence:
1. The driver listens to the commands from Selenium
2. It converts these commands into the browser's native API
CCS366- SOFTWARE TESTING AND
3. The driver takes the result of native commands and sends the result back to Selenium.

We can use Selenium WebDriver to do the following:


● Create robust, browser-based regression automation
● Scale and distribute scripts across many browsers and platforms
● Create scripts in your favourite programming language.
Features of Selenium Web driver
● Cross platform support
● APIs for different languages
● Support for different frameworks
● Easy to use
4. Selenium Grid
Selenium Grid is a Server that allows us to run tests on browser instances running on
remote machines and in parallel, thus spreading a load of testing across several machines. We
can create a Selenium Grid, where one server runs as the Hub, managing a pool of Nodes.
Selenium Grid enables us to execute tests in parallel on multiple machines by
managing different types of browsers, their versions, and operating system configurations
centrally.
Two key components of Selenium grid are Web driver and Web Elements

5.3.1 WebElements
A web page is composed of many different types of HTML elements, such as links,
textboxes, dropdown buttons, a body, labels, and forms. These are called WebElements in the
context of WebDriver. Together, these elements on a web page will achieve the user
functionality.
For example, let's look at the HTML code of the login page of a website:
<html>
<body>
<form id="loginForm">
<label>Enter Username: </label>
<input type="text" name="Username"/>
<label>Enter Password: </label>
<input type="password" name="Password"/>
<input type="submit"/>
</form>
<a href="forgotPassword.html">Forgot Password ?</a>
</body>
</html>
In the preceding HTML code, there are different types of WebElements, such as <html>,
<body>, <form>, <label>, <input>, and <a>, which together make a web page provide the
Login feature for the user. Let's analyze the following WebElement:
CCS366- SOFTWARE TESTING AND
<label>Enter Username: </label>
Here, <label> is the start tag of the WebElement label. Enter Username: is the text present
on the label element. Finally, </label> is the end tag, which indicates the end of a
WebElement. Similarly, take another WebElement:
<input type="text" name="Username"/>
In the preceding code, type and name are the attributes of the WebElement input with the
text and Username values, respectively.
UI-automation using Selenium is mostly about locating these WebElements on a web
page and executing user actions on them.

5.4 LOCATING WEB ELEMENTS


Selenium offers a number of built-in locator strategies to uniquely identify an element. One
can locate an element in 8 different ways. Here is a list of locating strategies for Selenium in
python.
Locators Description
The first element with the id attribute value matching the
By.ID
location will be returned.
The first element with the name attribute value matching the
By.NAME
location will be returned.
The first element with the xpath syntax matching the location
By.XPATH
will be returned.
The first element with the link text value matching the location
By.LINK_TEXT
will be returned.
The first element with the partial link text value matching the
By.PARTIAL_LINK_TEXT
location will be returned.
By.TAG_NAME The first element with the given tag name will be returned
The first element with the matching class attribute name will
By.CLASS_NAME
be returned.
The first element with the matching CSS selector will be
By.CSS_SELECTOR
returned.

Eg : 1
<html>
<body>
<form id="loginForm">
<input name="username" type="text" />
<input name="password" type="password" />
<input name="continue" type="submit" value="Login" />
</form>
</body>
<html>
We can locate elements using the following commands
login_form = driver.find_element(By.ID, 'loginForm')
● The first element with the id attribute value matching the location will be returned. If
no element has a matching id attribute, a NoSuchElementException will be raised.

element = driver.find_element(By.NAME, 'username')


● The first element with the name attribute value matching the location will be
returned. If no element has a matching name attribute, a NoSuchElementException
will be raised

Eg : 2
<html>
<body>
CCS366- SOFTWARE TESTING AND
<h1>Welcome</h1>
<p>Are you sure you want to do this?</p>
<a href="continue.html">Continue</a>
<a href="cancel.html">Cancel</a>
</body>
<html>
Now after you have created a driver, you can locate an element using
login_form = driver.find_element(By.LINK_TEXT, 'Continue')
login_form = driver.find_element(By.PARTIAL_LINK_TEXT, 'Conti')
login_form = driver.find_element(By.TAG_NAME, 'h1')

5.5 ACTIONS ON WEB ELEMENTS


To test an application, one needs to perform a number of user actions on it. To
perform any operations on the web application such as double-click, selecting drop-down
boxes, etc. the actions class is required. Actions class is an ability provided by Selenium for
handling keyboard and mouse events. The Action class handles advanced user interactions in
Selenium, like mouse movements, keyboard inputs, and context-click (right-click) actions.
More control and flexibility in automated testing scenarios are possible since it makes it
possible to simulate intricate user interactions that are impossible to accomplish with simple
WebDriver instructions.

Methods of Action Class


● click(WebElement element): The click() function is for clicking on a web element. The
purpose of this technique is to mimic a left click on a designated web element. It is
frequently used to interact with clickable items like checkboxes, buttons, and links.
● doubleClick(WebElement element): doubleClick() helps do a double click on a web
element. A specific web element can be double-clicked using the DoubleClick technique. It
is frequently employed in situations when a double click is necessary to start a process
contextClick(WebElement element): contextClick() lets you right-click on a web element.
This technique mimics a context-click, or right-click, on a designated web element. It comes
in useful when engaging with context menus and initiating right-click operations.
● moveToElement(WebElement element): moveToElement() moves the mouse pointer to
the middle of a web element. The mouse pointer is moved to the center of the designated
web element using the moveToElement function. Hovering over components that display
hidden options or activate dropdown menus is typical usage for it.
● dragAndDrop(WebElement source, WebElement target): dragAndDrop() allows
dragging one element and dropping it onto another. By dragging an element from its present
place and dropping it onto another element, you can execute a drag-and-drop operation using
this approach. It can be used to simulate user operations like rearranging objects or
transferring components between containers.
Example of Action Class in Selenium:
Actions actions = new Actions(driver);
WebElementelement = driver.findElement(By.id("elementId"));
actions.click(element).build().perform();

There are only 5 basic commands that can be executed on an element:


i. click (applies to any element)
ii. send keys (only applies to text fields and content editable elements)
iii. clear (only applies to text fields and content editable elements)
iv. submit (only applies to form elements)
v. select (see Select List Elements)
CCS366- SOFTWARE TESTING AND
i. Click
The element click command is executed on the center of the element. If the center of the element
is obscured for some reason, Selenium will return an element click intercepted error.
Eg :
WebElement element=driver.findElement(By.Id("buttonId"));
element.click();
ii. Send keys
The element send keys command types the provided keys into an editable element. Typically,
this means an element is an input element of a form with a text type or an element with
a content-editable attribute. If it is not editable, an invalid element state error is returned.

Eg :
WebElement element=driver.findElement(By.Id("inputId"));
element.sendKeys(“Hello”);
iii. Clear
The element clear command resets the content of an element. This requires an element to
be editable, and resettable. Typically, this means an element is an input element of a form with
a text type or an element with a content-editable attribute. If these conditions are not met, an
invalid element state error is returned.

Eg : WebElement element=driver.findElement(By.Id("inputId"));
element.clear();
iv. submit() method
The submit() action can be taken on a Form or on an element, which is inside a Form element.
This is used to submit a form of a web page to the server hosting the web application.
Eg :
WebElement form=driver.findElement(By.Id("formId"));
Form.submit();
v. select
Selenium provide Select class to interact with dropdowns and select options. It can
create an instance of the Select class, locate the drop down element and then use methods
like selectByValue( ), selectByIndex( ), etc to choose the desired option
Eg :
WebElement element=driver.findElement(By.Id("dropdownId"));
Select sel = new Select(dropdown);
Sel.selectByIndex(1)
Methods of Action Class
Action class is useful mainly for mouse and keyboard actions. In order to perform such actions,
Selenium provides various methods.
Mouse Actions in Selenium:
1. doubleClick(): Performs double click on the element
2. clickAndHold(): Performs long click on the mouse without releasing it
3. dragAndDrop(): Drags the element from one point and drops to another
4. moveToElement(): Shifts the mouse pointer to the center of the element
5. contextClick(): Performs right-click on the mouse
Keyboard Actions in Selenium:
1. sendKeys(): Sends a series of keys to the element
2. keyUp(): Performs key release
3. keyDown(): Performs keypress without release

Different WebElements will have different actions that can be taken on them. For
example, in a textbox element, we can type in some text or clear the text that is already typed
in it. Similarly, for a button, we can click on it, get the dimensions of it, and so on, but we
CCS366- SOFTWARE TESTING AND
cannot type into a button, and for a link, we cannot type into it.
So, though all the actions are listed in one WebElement interface, it is the test script
developer's responsibility to use the actions that are supported by the target element. In case
we try to execute the wrong action on a WebElement, we don't see any exception or error
thrown and we don't see any action get executed; WebDriver ignores such actions silently.

5.5.1 Getting element properties and attributes


There are various methods to retrieve value and properties from the WebElement interface.

1. The getText() method:


It will return visible text if the element contains any text on it, otherwise it will return
nothing. The API syntax for the getText() method is as follows:
java.lang.String getText()
2. The getCssValue() method
The getCssValue method can be called on all the WebElements. This method is used to fetch
a CSS property value from a WebElement. CSS properties can be fontfamily, background-
color, color, and so on. This is useful when you want to validate the CSS styles that are
applied to your WebElements through your test scripts.
Eg: System.out.println("Font of the box is: " + searchBox.getCssValue("font-family"));

3.The getLocation() method


The getLocation method can be executed on all the WebElements. This is used to get the
relative position of an element where it is rendered on the web page. This position is
calculated relative to the top-left corner of the web page of which the (x, y) coordinates are
assumed to be (0, 0). This method will be of use if your test script tries to validate the layout
of your web page.
Eg : System.out.println("Location of the box is: " + searchBox.getLocation());

4. The getSize() method


The getSize method can also be called on all the visible components of HTML. It will return
the width and height of the rendered WebElement.
The code for that is as follows:
System.out.println("Size of the box is: " + searchBox.getSize());

5.The getTagName() method


The getTagName method can be called from all the WebElements. This will return the
HTML tag name of the WebElement.

5.5.2 Checking the WebElement state


There are methods to check whether the WebElement is displayed in the Browser window,
whether it is editable, and if the WebElement is Radio Button of Checkbox, we can
determine whether it's selected or unselected. Let's see how we can use the methods available
in the WebElement interface.

1. The isDisplayed() method


The isDisplayed action verifies whether an element is displayed on the web page and can be
executed on all the WebElements. The API syntax for the isDisplayed() method is as
follows: boolean isDisplayed()
The preceding method returns a Boolean value specifying whether the target element is
displayed on the web page. The following is the code to verify whether the Search box is
displayed, which obviously should return true in this case:
WebElement searchBox = driver.findElement(By.name("q"));
CCS366- SOFTWARE TESTING AND
System.out.println("Search box is displayed: " + searchBox.isDisplayed());
The preceding code uses the isDisplayed() method to determine whether the element is
displayed on a web page. The preceding code returns true for the Search box:
Search box is displayed: true

2. The isEnabled() method


The isEnabled action verifies whether an element is enabled on the web page and can be
executed on all the WebElements. The API syntax for the isEnabled() method is as follows:
boolean isEnabled()
System.out.println("Search box is enabled: " + searchBox.isEnabled());

3. The isSelected() method


The isSelected method returns a boolean value if an element is selected on the web page and
can be executed only on a radio button, options in select, and checkbox WebElements. When
executed on other elements, it will return false.
System.out.println("Search box is selected: " + searchBox.isSelected());

5.6 DIFFERENT WEB DRIVERS


The WebDriver implementation for Mozilla Firefox, Google Chrome, Microsoft Internet
Explorer, Microsoft Edge, and Safari are given below. With WebDriver becoming a W3C
specification, all of the major browser vendors now support WebDriver natively.
1. Firefox Driver
The new driver for Firefox is called Geckodriver. The Geckodriver provides the
HTTP API described by the W3C WebDriver Protocol to communicate with Gecko
browsers, such as Firefox. It translates calls into the Firefox Remote Protocol (Marionette) by
acting as a proxy between the local and remote ends.
Using Headless Mode
Headless mode is a very useful way to run Firefox for automated testing with Selenium
WebDriver. In headless mode, Firefox runs as normal only you don't see the UI components.
This makes Firefox faster and tests run more efficiently, especially in the CI (Continuous
Integration) environment. During the execution, you will not see the Firefox window on the
screen but the test will be executed in headless mode.
2. Chrome Driver
The ChromeDriver is the WebDriver implementation for Google Chrome. It enables
Selenium to automate interactions with the Chrome browser. It works similar to the
Geckodriver and implements the W3C WebDriver protocol.
Using Headless Mode
Similar to Firefox, we can run tests in headless mode with ChromeDriver. This makes
Chrome tests run faster and tests run more efficiently, especially in the CI (Continuous
Integration) environment. We can run Selenium tests in headless mode by configuring the
Chrome .
3. Internet Explorer Driver:
In order to execute test scripts on the Internet Explorer browser, we need WebDriver's
Internet ExplorerDriver.
4. Edge Driver
Microsoft Edge is the latest web browser launched with Microsoft Windows 10. Microsoft
Edge was one of the first browsers to implement the W3C WebDriver standard and provides
built-in support for Selenium WebDriver.
5. Safari Driver
Apple provides Safari Driver built into the browser. In order to work it with Selenium
WebDriver, we have to set a Develop or Allow Remote Automation option from Safari's
main menu.
CCS366- SOFTWARE TESTING AND

Each Web driver has its own specific configuration requirements such as downloading and
setting up the correct driver ensuring the compatibility with the browser version used. The
web driver implementation act as intermediate between Selenium Web driver API and the
respective Web browsers. This enables integration and automation with the browser actions
for testing purposes.
Comparison of different WebDrivers in Selenium

Web driver Supported Features


Browser
Firefox Driver Fire Fox Flexible, Extensible and supports a variety of
add-ons
Chrome Driver Chrome Fast , stable and easy to use

Internet Explorer Internet Explorer Supports older version of IE


Driver
Edge Driver Microsoft Edge New and improves Web driver for Edge

Safari Driver Apple Safari Supports latest version of Safari

How to choose the right driver ?


Browser Compatibility: Ensure the driver matches the browser version.
Application Under Test: Different drivers perform better with different technologies (e.g.,
JavaScript frameworks).
Features Required: Support for headless mode, handling alerts, etc.
Performance and Execution Speed: Headless drivers typically offer faster execution.
Supported OS Environments: Consider where tests will be executed.

What are the challenges and limitations in Web drivers?


Browser-Specific Issues: Different browsers may render pages differently.
Frequent Updates: Need to regularly update WebDrivers to avoid incompatibility.
Performance Variations: Execution speed can differ between drivers.
Limitations: Certain elements (like CAPTCHAs) may not be automatable.

5.7 : UNDERSTANDING WEB DRIVER EVENTS


What are Web Driver Events?
Web Driver Events are events that are fired by the Web Driver API. These events can be used to
monitor the state of the browser and to react to changes in the browser's state.

Why are Web Driver Events Important ?


Web Driver Events can be used to:
● Monitor the state of the browser: Web Driver Events can be used to monitor the state
of the browser, such as the page title, the URL and the visibility of elements. This
information can be used to verify that the browser is in the correct state.
● React to changes in the browser's state: Web Driver Events can be used to react to
changes in the browser's state. For example, it could use a Web Driver Event to be
notified when a new page is loaded.
● Log events: Web Driver Events can be used to log events. This can be useful for
debugging and for tracking the progress of its automation script.

How to use WebDriver Events ?


CCS366- SOFTWARE TESTING AND
● To use WebDriver Events, it needs to implement the WebDriverEventListener interface.
This interface defines a number of methods that are called when certain events occur.
● Once it has implemented the WebDriverEventListener interface, it can register its
listener with the WebDriver. This can be done using the register() method.
● Once its listener is registered, it will be notified when certain events occur. The events
that are notified depend on the implementation of the WebDriverEventListener interface.
● WebDriver Events are a powerful tool that can be used to monitor the state of the
browser and to react to changes in the browser's state. They can be used for a variety of
purposes, such as verifying that the browser is in the correct state, reacting to changes in
the browser's state and logging events.
● Understanding WebDriver events in Selenium involves being aware of the various events
that occur during test execution and how they can be utilized to enhance test automation.

WebDriver events provide hooks or listeners that allow testers to observe and interact with
different stages of the automation process. Here are the key aspects to understand about
WebDriver events in Selenium:

Event listeners:
● Selenium WebDriver provides an event-driven architecture that allows the registration of
event listeners. Event listeners are objects that implement specific interfaces, such as
WebDriverEventListener or EventListener, to handle different types of events during test
execution.

Types of WebDriver events:


WebDriver events cover various stages and actions during test execution. Some of the
commonly used events include:
● beforeNavigateTo: Triggered before navigating to a new URL
● afterNavigateTo: Triggered after successfully navigating to a new URL.
● beforeNavigate Back: Triggered before navigating back in the browser history.
● afterNavigate Back: Triggered after successfully navigating back in the browser history.
● beforeNavigate Forward: Triggered before navigating forward in the browser history.
● afterNavigate Forward: Triggered after successfully navigating forward in the browser
history.
● beforeFindBy: Triggered before locating a web element on the page.
● afterFindBy: Triggered after successfully locating a web element on the page.
● beforeClickOn: Triggered before clicking on a web element.
● afterClickOn: Triggered after successfully clicking on a web element.
● beforeChangeValueOf: Triggered before changing the value of a web element.
● afterChangeValueOf: Triggered after successfully changing the value of a web element.
● beforeScript: Triggered before executing JavaScript code.
● afterScript: Triggered after successfully executing JavaScript code.
● onException: Triggered when an exception occurs during test execution.
● These are just a few examples of the available WebDriver events. Testers can choose to
implement listeners for specific events that are relevant to their testing needs.

Implementing event listeners:


CCS366- SOFTWARE TESTING AND
● To utilize WebDriver events, it needs to create a custom event listener by implementing
the appropriate interface. For example, implementing the WebDriverEventListener
interface allows it to override the methods associated with different WebDriver events.
Inside these methods, it can define custom actions or assertions based on the event being
triggered.

Registering event listeners:


● After creating the event listener implementation, it needs to register it with the
WebDriver instance using the register() method. This ensures that the event listener is
actively listening for events during test execution.
● Example (Java):
WebDriver driver = new ChromeDriver();
Event Firing WebDriver eventDriver = new EventFiringWebDriver(driver);
MyEventListener eventListener = new MyEventListener(); // Custom event listener implementation
eventDriver.register(eventListener);

● In the example above, the EventFiringWebDriver class is used to wrap the original
WebDriver instance. This allows the event listener to intercept WebDriver events.

Customizing event listeners:


● Event listeners can be customized to perform specific actions based on the events they
handle. For example, it can take screenshots on onException events, log messages on
beforeNavigate To and afterNavigate To events, or validate element visibility on
beforeClickon and afterClickOn events.

Example (Java):
public class MyEventListener implements WebDriverEventListener {
// Implement methods for desired events
@Override
public void beforeClickOn(WebElement element, WebDriver driver) {
// Perform custom actions before clicking on an element System.out.println("About to click
on element: + element);
}
@Override
public void afterClickOn(WebElement element, WebDriver driver) {
// Perform custom actions after clicking on an element System.out.println("Clicked on
element: " + element);
}
// Implement other event methods as needed
}
● The example above demonstrates a custom event listener that logs messages before and
after clicking on web elements.
By utilizing WebDriver events and implementing custom event listeners, testers can gain
more control and insight into the test execution process. This allows for custom actions,
logging, error handling, and validation based on specific events during test automation,
leading to enhanced reporting and improved debugging capabilities

5.8 TestNG
TestNG is an open-source automated testing framework; where NG means Next Generation.
CCS366- SOFTWARE TESTING AND
The design goal of TestNG is to cover a wider range of test categories: unit, functional, end-to-
end, integration, etc., with more powerful and easy-to-use functionalities.

5.8.1 UNDERSTANDING TESTNG.XML


TestNG.xml file is a configuration file that helps in organizing our tests. It allows testers to
create and handle multiple test classes, define test suites and tests.
It makes a tester’s job easier by controlling the execution of tests by putting all the
test cases together and run it under one XML file. This is a beautiful concept, without which,
it is difficult to work in TestNG.

Advantages Of TestNG.xml
● It provides parallel execution of test methods.
● It allows the dependency of one test method on another test method.
● It helps in prioritizing our test methods.
● It allows grouping of test methods into test groups.
● It supports the parameterization of test cases using @Parameters annotation.
● It helps in Data-driven testing using @DataProvider annotation.
● It has different types of assertions that help in validating the expected results with the
actual results.
● It has different types of HTML reports, Extent reports, etc. for a better and clear
understanding of our test summary.
● It has listeners who help in creating logs.

Concepts Used in TestNG.xml

#1) A Suite is represented by one XML file. It can contain one or more tests and is defined
by the <suite> tag.
Example: <suite name=”Search Suite”>

#2) A Test is represented by <test> and can contain one or more TestNG classes.
Example: <test name=”Search Test”>

#3) A Class is a Java class that contains TestNG annotations. Here it is represented by the
<class> tag and can contain one or more test methods.
Example:
<classes>
<class name="com.example.SearchTest"/>
</classes>
CCS366- SOFTWARE TESTING AND
#4) Method : This defines a test method. A test method is a Java method that is annotated with
@Test annotation

#5) Listeners : Listeners are used to listen to events during test execution

TestNG.xml Example:

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


<suite parallel="false" name="Test Suite">
<test name="Test">
<classes>
<class name="com.example.SearchTest"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite --
>

Steps to create a TestNG XML file and execute it:


1. Create a new XML file: Use a text editor or an XML editor to create a new XML file.
Give it a meaningful name, such as "testng.xml".

2. Define XML structure: Define the basic structure of the XML file by adding the root
element. The root element in TestNG XML is typically <suite.
xml
<suite name="Test Suite">
<- Add test configurations and test tags here ->
</suite>
3. Add test configurations: Within the <suite> element, it can add various test
configurations. These configurations may include details such as test parameters, test
environment setup or other global settings.

xml
<suite name="Test Suite">
<parameter name="browser" value="chrome' />
<!-- Add more configurations as needed -->
</suite>
4. Define test tags: Within the <suite> element, it can define one or more <test> tags to
represent individual tests or test groups. Each <test> tag can have a unique name and
may contain one or more <classes> or <packages> tags to specify the test classes or
packages to be executed.

xml
<suite name="Test Suite">
<test name "Test 1">
<classes>
<class name="com.example.tests.TestCase1"/>
<class name="com.example.tests TestCase2"/>
</classes>
</test>
<!-- Add more tests as needed -->
</suite>

5. Save the XML file: Save the testng.xml file with the defined structure and
configurations.
CCS366- SOFTWARE TESTING AND
6. Execute TestNG XML file: To execute the TestNG XML file, it can use various
methods depending on its environment and tools.

a. Command line: Open a command prompt or terminal, navigate to the project


directory and use the TestNG command to execute the testng.xml file.

shell
$ testng testng.xml

b. IDE integration: Many integrated development environments (IDEs) provide


built-in support for executing TestNG XML files. In itr IDE, import the project,
right-click on the testng.xml file, and select the option to run or execute it as a
TestNG test.

7. Build automation tools: If it is using build automation tools like Maven or Gradle, it
can configure the build script to execute the TestNG XML file as part of the build
process.

These steps provide a basic overview of creating and executing a TestNG XML file. The
specific details may vary based on itr project setup, environment and testing requirements. It's
recommended to refer to the TestNG documentation or consult the documentation of its specific
IDE or build automation tool for more detailed instructions on creating and executing TestNG
XML files.

5.9 : ADDING CLASSES, PACKAGES, METHODS TO TEST:

5.9.1 : ADDING CLASSES :


To add classes in a testing.xml file, it need to follow these general steps:
1. Determine the purpose: Understand the purpose of adding classes in the testing.xml file. Is it
adding classes for test cases, test data, configuration, or any other specific use ?
2. Define XML structure: Decide on the XML structure or schema for representing the classes.
Determine the elements, attributes and hierarchy that will be used to define the classes.
3. Open the XML file: Open the testing.xml file using a text editor or an XML editor. Make
sure it has the necessary permissions to modify the file.
4. Locate the appropriate section: Identify the section in the XML file where it wants to add
the classes. This could be an existing section or a new section specifically designated for classes.
5. Add XML elements: Add XML elements to represent the classes within the appropriate
section. Use the defined XML structure or schema to ensure consistency and clarity.
6. Set attributes: If needed, set attributes for the class elements to provide additional
information or metadata about the classes. These attributes could include class names,
identifiers, descriptions or any other relevant details.
7. Specify class properties: Within each class element, specify the properties or characteristics
of the class. This could include details like class names, access modifiers, methods, variables or
any other relevant information.
8. Save the XML file: Once it has added the classes, save the testing.xml file.
● It's important to note that the specific steps for adding classes in a testing.xml file can
vary depending on the context and the intended use of the file. The above steps provide a
general guideline, but the actual implementation may differ based on the XML structure,
tool or framework it is using for testing.
CCS366- SOFTWARE TESTING AND
● If we are working with a specific testing framework or tool, refer to its documentation or
guidelines to understand the recommended approach for adding classes in the testing.xml
file associated with that framework or tool. Example:
● Here are the steps on how to add classes in testing.xml:
1. Create a new XML file and save it as "testing.xml".
2. Open the XML file in a text editor.
3. Add the following code to the XML file.
XML
<suite name="MyTestSuite">
<test name="MyTest">
<class name="com.example.MyTestClass1"/>
<class name="com.example.MyTestClass2"/>
</tost>
</suite>
4. Save the XML file.
5. Run the tests by running the "testing.xml" file from the command line or from an IDE.
● The code in the XML file defines a test suite called "MyTestSuite" that contains two
tests, "MyTest1" and "MyTest2"., The "MyTest1" test runs the class
“com.example.MyTestClass1” and the "MyTest2" test runs the class "com. example.
MyTestClass2".
● To add more classes to the XML file, it simply needs to add more "class" elements to the
"test" element. For example, to add a class called "com.example.MyTestClass3" to the
XML file, it would add the following code:

XML
<class name="com.example.MyTestClass3"/>
● Once it has added the classes to the XML file, it can run the tests by running the
"testing.xml" file from the command line or from an IDE.
● Here are some additional tips for adding classes to testing.xml:
● The name of the class element must match the fully qualified name of the Java class.
● The order in which the classes are defined in the XML file determines the order in which
the tests will be executed.
● It can use the "groups" element to group the classes together. This can be helpful for
running the tests in parallel or filtering them out.

5.9.2 : Adding Packages


● In software testing, packages in XML are used to group together classes and methods
that are related to a specific functionality or feature. This can be helpful for organizing
the tests and for running them in parallel.
● To add packages to an XML file for software testing, it can use the <packages> element.
The <packages> element contains a list of <package> elements, each of which defines a
package name. For example, the following XML code defines two packages:

XML
<packages>
<package name="com.example.mypackage1"/>
<package name="com.example.mypackage2"/>
</packages>
CCS366- SOFTWARE TESTING AND
● Once it has added the packages to the XML file, it can run the tests by running the XML
file from the command line or from an IDE.
● To define packages in a testing.xml file, it can follow these steps:

1. Determine the organization strategy: Decide on the organization strategy for its test cases.
Identify how it wants to group and categorize them using packages. Consider factors such as
functionality, modules, features or any other meaningful criteria.
2. Define XML structure: Determine the XML structure or schema for representing packages
in the testing.xml file. Decide on the appropriate XML elements, attributes and hierarchy that
will be used to define packages
3. Open the XML file: Open the testing.xml file using a text editor or an XML editor. Ensure
that it has the necessary permissions to modify the file.
4. Identify the appropriate section: Identify the section in the XML file where it wants to add
the packages. This section could be specifically designated for packages or any other section
suitable for organizing test cases.
5. Add package elements: Within the appropriate section, add XML elements to represent the
packages. Use the defined XML structure or schema to ensure consistency.
6. Set package attributes: For each package element, set the necessary attributes to define the
package. This could include attributes like package names, identifiers, descriptions or any other
relevant metadata.
7. Nest packages if required: If its organization strategy involves nested or hierarchical
packages, create the necessary nested package elements within the appropriate parent packages.
8. Associate test cases: Associate the relevant test cases with their respective packages. It can
use XML elements or attributes to reference or include test cases within the package elements.
9. Save the XML file: Once it has defined the packages and associated test cases, save the
testing.xml file.

● The above steps provide a general guideline, but the actual implementation may differ
based on the requirements of its specific testing environment.
● Here are some of the benefits of using packages in XML for software testing:
• Improved organization: Packages can help to improve the organization of the tests by
grouping together classes and methods that are related to a specific functionality or
feature.
• Parallel execution: Packages can be used to run tests in parallel, which can help to
improve the performance of the testing process.
• Filtering: Packages can be used to filter out tests that it do not want to run.
Overall, packages in XML can be a valuable tool for organizing and running tests in
software testing.

5.9.3 : Adding Methods to Test


● When it comes to testing XML files, there are several methods it can employ depending
on its specific needs and goals. Here are a few common approaches:
1. Manual inspection: This is the simplest method and involves visually inspecting the
XML file to ensure its structure, content and any defined rules are correct. It can use a
text editor or an XML-specific tool to review the file.
2. XML validators: XML validation tools automatically check the XML file against a
specified schema or Document Type Definition (DTD). This method ensures that the
(XML conforms to the defined rules and structure) Examples of XML validators include
XMLSpy, Xerces and XML.Starlet.
CCS366- SOFTWARE TESTING AND
3. Unit testing: If it is using XML as part of a larger software system, it can write unit tests
specifically designed to validate the XML processing logic. These tests can verify that
the XML is parsed correctly, data is extracted properly and any transformations or
manipulations produce the expected results.
4. XML schema testing: If its XML uses a schema definition, it can write test cases that
cover different scenarios based on the schema's rules. These tests can check for valid and
invalid inputs, edge cases and boundary conditions to ensure the XML behaves as
expected.
5. XPath testing: XPath is a query language used to navigate XML documents. It can write
XPath expressions to select specific elements or attributes within the XML and validate
that the results match its expectations. XPath testing is particularly useful when it needs
to extract data from XML files or verify specific values.
6. Integration testing: In scenarios where XML files are exchanged between different
systems or services, integration testing can be performed to verify the end-to-end flow.
This involves testing the XML generation, transmission and consumption by the
receiving system, ensuring proper data exchange and handling.
7. Performance testing: If it is dealing with large XML files or high-volume XML
processing, performance testing can help identify bottlenecks, optimize processing times,
and ensure the system can handle the expected load. Performance testing tools can
simulate various workloads and measure XML processing performance.

• By applying these testing methods to its XML file, it can ensure its correctness, validate
its adherence to defined rules, verify data extraction, test integration scenarios and assess
performance characteristics.
● The testing methods it choose depend on the specific requirements and context of its
XML usage. It's often beneficial to employ a combination of these techniques to
thoroughly test XML files and their related processes.

• Suppose it has an XML file that represents a collection of books. Each book has attributes
such as title, author, publication year, and price. Here's a sample XML file:
xml
<library>
<book>
<title>The Great Gatsby</title>
<author>F. Scott Fitzgerald</author>
<year>1925</year>
<price>10.99</price>
</book> <book>
<title>To Kill a Mockingbird</title>
<author>Harper Lee</author>
<year>1960</year>
<price>12.99</price>
</book> </library>

5.10 : Test Reports


Reporting is the most important part of any test execution, as it helps the user understand the
result of the test execution, point of failure, and the reasons for failure.
TestNG generates multiple reports as part of its test execution. These reports mainly include:
CCS366- SOFTWARE TESTING AND
● TestNG HTML report: This is the default report that is generated and is the most
commonly used. It provides a detailed overview of the test execution, including the test
cases that were run, their results and any errors or failures that occurred.
● TestNG email-able report: This is a formatted version of the HTML report that is
optimized for sending as an email attachment.
● TestNG report XML: This is an XML version of the report that can be used for further
processing or analysis.
● JUnit report XML: This is an XML version of the report that is compatible with JUnit,
another popular testing framework.

The following is an example of a testng.xml file that generates test reports:


<?xml version="1.0" encoding="UTF-8"?>
<suite name="My Test Suite">
<test name="My Test">
<classes> <class name="com.example.MyTest"/>
</classes>
</test>
</suite>

This file will generate the following reports:


test-output/index.html: The TestNG HTML report.
test-output/emailable-report.html: The TestNG email-able report.
test-output/report.xml: The TestNG report XML
test-output/junitreport.xml: The JUnit report XML

To view the reports, it can open them in a web browser. The HTML reports will provide a
graphical overview of the test execution, while the XML reports can be used for further
processing or analysis.

The test report in XML format consists of three main sections:


<metadata>, <summary>, and <testcases>
1. The <metadata> section contains metadata about the test execution. It includes a timestamp
(<timestamp>) indicating when the test report was generated, the tester's name (<tester>), and
the version of the software being tested (<version>).
2. The <summary> section provides an overview of the test execution. It includes the total
number of tests executed (<totalTests>), the number of tests that passed (<passedTests>), the
number of tests that failed (<failedTests), the number of tests that were skipped
(<skippedTests>), and the overall duration of the test execution (<duration>).
3. The <testcases> section contains individual <testcase> elements for each test case executed.
Each <testcase> element includes information such as the test case name (<name>), the status
of the test case (<status>), the duration of the test case execution (<duration>), and any log
messages generated during the test case execution (<logs>).
4. The <logs> element contains a list of <log> elements that capture log messages related to the
test case. Each <log> element has a level attribute to indicate the log level, such as "info",
"error", or "warning".
5. The <error> element, if present, captures details about the error that occurred during the test
case execution. It includes an error message (<message>) and a stack trace (<stacktrace>).

• By using this XML structure, it can generate comprehensive test reports that capture metadata,
summary information, individual test case details, logs and error information, providing valuable
CCS366- SOFTWARE TESTING AND
insights into the software testing process.

You might also like