Unit V
Unit V
1. Test automation tools: Various tools and frameworks are available to facilitate
automated software testing. These tools provide features such as test script creation,
test case management, test execution, reporting. and integration with other software
development tools. Examples of popular test automation tools include Selenium,
Appium, TestComplete, JUnit, NUnit and Cucumber.
2. Test scripting: Automated tests are typically written as scripts or code that
interacts with the software being tested. Test scripts can be created using different
programming languages, such as Java, Python, C# or. JavaScript, depending on the
chosen test automation tool or framework. The scripts simulate user actions like
clicking buttons, entering data, navigating through screens and verifying expected
results.
3. Test coverage and efficiency: Automated testing allows for a broader and more
comprehensive test coverage compared to manual testing. It enables the execution
of a large number of test cases and scenarios that may be time-consuming or
impractical to perform manually. Automated tests can be executed repeatedly,
ensuring consistent and reliable results. This efficiency enables faster feedback
cycles and facilitates quicker identification and resolution of software defects.
Unit testing: Unit tests are small, self-contained tests that test individual
units of code.
Integration testing: Integration tests test how different units of code
interact with each other.
Functional testing: Functional tests test the functionality-of the software as
a whole.
Regression testing: Regression tests are used to check that new changes to
the software have not introduced any bugs.
Increased speed: Automated tests can be run much faster than manual tests, which
can save a lot of time.
Reduced cost: Automated tests can help to reduce the cost of software testing by
freeing up manual testers to focus on other tasks.
Improved quality: Automated tests can help to improve the quality of software by
catching bugs that would otherwise be missed.
Increased confidence: Automated tests can help to increase confidence in the
quality of software by providing evidence that the software has been thoroughly
tested.
A unit test that checks that a function returns the correct value.
An integration test that checks that two modules communicate correctly.
A functional test that checks that a user can successfully complete a task.
A regression test that checks that a new change to the software has not
introduced any bugs.
Here are some key points to consider when discussing automated testing of web
applications in detail:
Types of automated tests
a. Functional testing: This type of testing verifies that the web application
functions
correctly by. simulating user actions such as clicking buttons, filling out forms and
navigating between pages. It checks if the expected outputs and behaviours are
consistent with the application's requirements.
b. Regression testing: Regression testing ensures that existing features and
functionalities of the web application ‘remain intact after new changes or
enhancements are introduced. By Tunning automated tests, developers can quickly
identify any regressions or unintended side effects caused by code modifications.
c. Cross-browser testing: Web applications need to be compatible with multiple
web browsers such as Chrome, Firefox, Safari and Internet Explorer. Automated
cross-browser testing ensures that the application behaves consistently across
different browsers and platforms, identifying any browser-specific issues.
d. Performance testing: Automated performance testing assesses the web
application's responsiveness, scalability and resource usage under various loads. It
measures response times, server performance, database performance and identifies
bottlenecks to ensure optimal performance.
e. Security testing: Automated security testing detects vulnerabilities and potential
security risks in web applications. It includes tests such as SQL injection, cross-site
scripting (XSS), and authentication testing to uncover security flaws and protect
against potential attacks.
Increased speed: Automated tests can be run much faster than manual tests, which
can save a lot of time.
Reduced cost: Automated tests can help to reduce the cost of web application
testing by freeing up manual testers to focus on other tasks.
Improved quality: Automated tests can help to improve the quality of web
applications by catching bugs that would otherwise be missed.
Increased confidence: Automated tests can help to increase confidence in the
quality of web applications by providing evidence that the web applications have
been thoroughly tested.
How to select the right automation tool for web application testing?
Selecting the right automation tool for web application testing depends on
several factors.
Here are some considerations to help it choose the appropriate automation
tool:
Application type and technology: Consider the type of web application it is testing
and the technologies used to develop it. Some automation toois are better suited for
specific types of applications, such as Angular; React or Java-based applications.
Test requirements: Evaluate its testing requirements and the features provided by
different automation tools. Consider whether it needs support for cross-browser
testing, mobile testing, API testing, data-driven testing or performance testing.
Programming language: Determine the programming language it and itr team are
most comfortable with. Some tools are language-specific, so choosing a tool that
supports the programming language it is familiar with can streamline the
automation process.
Learning curve: Consider the leaming curve associated with the automation tool.
Evaluate the case of use, availability of documentation, online resources and
community support. Tools with a large user community often have extensive
resources available.
Integration and extensibility: Assess how well the automation tool integrates with
other tools and frameworks in its testing ecosystem. Determine if it can be easily
integrated with its existing test management systems, continuous integration tools or
defect tracking systems.
Cost and licensing: Consider the cost implications and licensing requirements of
the automation tool. Some tools are open source, while others require a commercial
license. Evaluate whether the tool's cost aligns with itr budget and the value it
provides.
Reduced cost: Automated tests can help to reduce the cost of web application
testing by freeing up manual testers to focus on other tasks.
Improved quality: Automated tests can ‘help to improve the quality of web
applications by catching bugs that would otherwise be missed.
Functional testing: Functional testing checks that the web applications meet their
requirements.
Performance testing: Performance testing checks that the web applications can
handle the expected load.
Security testing: Security testing checks that the web applications are secure from
attack.
Usability testing: Usability testing checks that the web applications are easy to use.
2. Development: The next step is to develop the automated tests. This involves
writing code that can execute the test cases automatically.
3.Execution: Once the automated tests are developed, they need to be executed.
This can be done manually or automatically.
4. Reporting: The final step is to report on the results of the automated tests. This
includes identifying any bugs that were found, and providing recommendations for
fixing them.
What are the tools available for automating web application testing?
There are many different tools available for automating web application
testing, including:
Selenium
Watir
Appium
JMeter
SoapUI
LoadRunner
There are several popular test automation tools and frameworks specifically
designed for web application testing. These tools provide features to interact with
web elements, simulate user actions and perform validations. Some commonly used
tools include:
b. Selenium RC: In the case of working with Selenium RC (Remote Control), one
must have good knowledge of at least one programming language. This tool allows
it to develop responsive design tests in any scripting language of its choice. Server
and client libraries are the two main components of Selenium RC. Its architecture is
complex and it has its limitations.
Two key components of Selenium are the WebDriver and web elements.
Rich API: WebDriver offers a comprehensive set of methods and commands for
effective automated testing, leading to improved software quality and faster release
cycles.
what is Selenium WebDriver?
Synchronization:
WebDriver provides synchronization mechanisms, such as waits; popular
tool for web application testing and it can also be used for other tasks such
as web to ensure that the browser and web elements have loaded completely
before. scraping and data extraction.
WebDriver provides a set of APIs that can be used to interact with web
browsers. These ae of test scripts. APIs allow it to do things like navigate to
web pages, click on buttons, enter text into text.
Selenium test script - Selenium test script is the test code written in any of the
mentioned programming languages that are interpreted by the driver.
Browsers - Selenium WebDriver supports multiple web browsers to test and run
applications on.
APIs for different languages: Selenium WebDriver provides APIs for a variety of
programming languages, including Java, Python, C#, and Ruby. This means that it
can use it to automate web browser interactions in its preferred programming
language.
Easy to use: Selenium WebDriver is relatively easy to use. The APIs are well-
documented, and there are a number of tutorials and resources available online.
WD: The ID attribute is a unique identifier for an HTML element. It can use the ID
attribute to locate an element by its ID.
Name: The name attribute.is another unique identifier for an HTML element. It can
use the name attribute to locate an element by its name.
CSS selector: A CSS selector is a way to select an HTML element by its CSS
properties. It can use CSS selectors to locate elements by their tag name, class name
or other CSS properties.
XPath: XPath is a language for locating XML elements. It can use XPath to locate
HTML elements by their XPath expression.
Here are the commonly used methods for locating web elements in Selenium:
Conclusion
Actions on web elements are an essential part of Selenium automation.
There are a-variety of actions that it can perform on web elements in Selenium and
the best method to use will vary depending on the specific situation.
Clicking and dragging: The Actions class can be used to click and drag an element
to a new location.
Moving the mouse: The Actions class. can be used to move the mouse pointer to a
specific location on the screen.
Keys: The Actions class can be used to simulate keyboard input.
The Actions class is a powerful tool that can be used to perform complex actions on
web elements. However, it is important to note that the Actions class can be slow,
so it should only be used when necessary.
Here are some common actions that can be performed on web elements using
Selenium:
1. Clicking on Elements:
We can simulate a user clicking on a web element using the click() method.
This isbcommonly used for buttons, links, checkboxes, radio buttons and other
clickable elements.
Example (Java):
6. Submitting Forms:
To submit a form, it can use the submit() method on the form element. This
triggers the form submission and performs any associated actions.
Example (Java):
7. WebDriver for other Browsers: Selenium WebDriver also provides support for
other less commonly used browsers, such as, PhantomJS (a headless browser),
HTMLUnitDriver (a headless Java-based, browser), and more. These drivers allow
Selenium to automate interactions with these specific browsers.
React to changes in the browser's state: WebDriver Events can be used to react to
changes in the browser's state. For example; it could use a WebDriver Event to be
notified when a new page is loaded.
Log events: WebDriver Events can be used to log events. This can-be useful for
debugging and for tracking the progress of its automation script.
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 powerfill 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.
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:
5.8 Testing
Testing in software testing refers to the process of evaluating a software
application or system to identify defects, errors, or issues. It involves executing the
software with various test cases and scenarios to verify its behavior and ensure its
quality.
The purpose of testing is to uncover any bugs, validate the functionality,
assess the performance, and confirm that the software meets the requirements and
expectations of its users. By conducting testing, software development teams can
detect and fix issues early in the development lifecycle, which helps in delivering a
reliable and high-quality product.
There are different types of testing performed during the software testing life
cycle, including:
System testing: System testing evaluates the entire system as a whole, checking if
all the components are integrated properly and the system meets the specified
requirements.
Acceptance testing: Acceptance testing is performed to validate whether the
software meets the acceptance criteria and satisfies the user's requirements. It can be
done by the end-users or client to determine if the software is ready for deployment.
Security testing: Security’ testing checks for vulnerabilities and weaknesses in the
software to ensure that sensitive data is protected and the software is resilient
against potential security threats.
To create a TestNG XML file and execute it, follow these steps:
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>.
3. Add test configurations: Within the <syite> element, it can add various test
configurations. These configurations may include details such as test parameters,
test
environment setup or other global settings.
5. Save the XML file: Save the testng.xml file with the defined structure and
configurations.
6. Execute TestNG XML file: To execute the TestNG XML file, it can use various
methods depending on its environment and tools.
shell
$ testng testng.xml
1. Test case management: XML can be-used to define and store test cases in a
structured manner. The XML file may contain information such as test case ID,
description, preconditions, test steps, expected results and any additional metadata
related to the test case.
2. Test data management: XML can be employed to store test data sets for
executing test cases. The XML file can define different test data scenarios, input
values, expected outputs and any other relevant data required for testing different
aspects of the software.
4, Test suites: XML can be used to define test- suites, which group related test
cases
together. The XML file can include information about the test suite name,
description
and references to the individual test cases that belong to the suite.
5. Test results: XML can be employed to store test results in a structured format.
The
XML file may contain information such as test case status (pass/fail), execution
time,
error messages and any additional details captured during the testing process.
Testing.xml is a configuration file that is used to define test suites and tests
in TestNG. It is an XML file that contains the following elements:
suite: This element defines a test suite. A test suite is a collection of tests that are
run
together.
test: This element defines a test. A test is a single unit of testing that is used to
verify the functionality of a software application.
class: This element defines a class that contains test methods.
method: This element defines a test method. A test method is a Java method that is
annotated with the @Test annotation:
In software testing and design, Testing. xml is used to define the following:
The test cases that need to. be executed.
The order in which the tests should be executed.
The parameters that need to be passed to the tests.
The groups of tests that need to be run.
The listeners that need to be notified of test events.
Here are some of the benefits of using Testing.xml in software testing and
design:
Increased test automation: Testing. -xml can be used to automate the testing
process, which can save time and improve the efficiency of the testing team.
Improved test coverage: By defining the tests in an XML file, it can ensure that all
of the important functionality of the software is tested.
Enhanced test reporting: Testing xml can be used to generate detailed test reports,
which can help it to identify and fix any defects in the software.
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?
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.
Example:
Here are the steps on how to add classes in testing.xml:
XML
<suite name="MyTestSuite'> _
<test name="MyTest">
<class name="com.example. MyTestClass1'/>
<class name="com.example MyTestClass2"/>
</test>
</suite>
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/>
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.11 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>
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.
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.
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.
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.
When working with a specific testing framework or tool, it's advisable to refer to its
documentation or guidelines to understand the recommended approach for defining.
Packages in the testing.xml file associated with that framework or tool.
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 does not want to run.
2. XML validators: XML validation tools automatically check thé 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 XMLStarlet.
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.
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:
<book>
<title>'The Great Gatsby</title>
<author>F, Scat Fitzgerald</author>
<year>1925</year>
<price>10.99</price> r
</book>
<book>
<title>To Kill a Mockingbird </title>
author>Harper Lee</author>
> <year>1960</year>
<price>12.99</price>
</book>
</library>
1. Manual inspection: It can visually inspect the XML file to ensure it has the
correct
structure and content. Check that the opening and closing tags match, attributes are
properly formatted and data is correctly enclosed within elements.
3. Unit testing: Write unit tests that verify the correctness of itr XML processing
logic. For example, it can test if a function extracts the book titles correctly from the
XML file or if the price calculation is accurate. These tests can be automated and
run as part of its development or deployment process.
4. XML schema testing: If it has an XML schema definition (XSD), it can write
test
cases to cover different scenarios based on the schema’s rules. For example, it can
create tests to ensure that all books have a valid publication year or that the price is
within an acceptable range.
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, these reports are generated by default in
the test-output folder. The location of the reports can be changed by setting the
output Directory property in the testng.xml file.
Code snippet
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.
<testreport>
<metadata>
<timestamp> 2023-06-27 15:30:00</timestamp>
<tester>John Doe</tester>.
<version>1.0.0</version>
</metadata>
<summary>
<totalTests>10</totalTests>
<passedTests>8</passedTests>
<failedTests>2</failedTests>
<skippedTests>0</skippedTests> -
<duration> 00:15:25 </duration>.
</summary>
<testcases>
<testcase>
<name>LoginTest</name>
<status>passed</status>
<duration> 00:01:05 </duration>
<logs>
<log level="info'> Successfully logged in</log>
<flogs>
</testcase>
<testcase>
<name>RegistrationTest</name>
<status>failed</status>
<duration>00:02;15</duration>
<logs>
3. What are the tools available for automating web application testing?
There are. many different tools available for automating web application
testing, including:
Selenium
Watir
Appium
JMeter
SoapUI
LoadRunner
suite: This element defines a test suite. A test suite is a collection of tests that are
run
together.
test: This element defines a test. A test is a single unit of testing that is used to
verify the functionality of a software application.
class: This element defines a class that contains test methods.
method: This element defines a test method. A test method is a Java method that is
annotated with the Test annotation.
parameter: This element defines a parameter that can be passed to a test method.
groups: This element defines a group of tests. Tests can be grouped together for
various purposes, such as running them in parallel or filtering them out.
listeners: This element defines’ listeners that are used to listen to events during test
execution.
Monitor the state of the browser: WebDriver 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: WebDriver events can be used to react to
changes in the browser's state. For example, it could use a WebDriver event to be
notified when a new page is loaded.
Log events: WebDriver. events can be used to log events, this can be useful for
debugging and for tracking the progress of its automation script.
ID: The id attribute is a unique identifier for an element on a web page. It is the
most
reliable locator but it is not always available.
Name: The name attribute is used to identify an element on a web page, It is not as
reliable as the id attribute but it is more commonly used.
Class name: The class attribute is used to identify an element on a web page by its
class name. It is not as reliable as the id or name attributes but it is more commonly
used.
Link text: The link text is the visible text of a link element. It is 4 reliable locators
but it is only applicable to link elements.
Partial link text: The partial Jink text is a portion of the visible text of a link
element. It is a reliable locator but it is only applicable to link elements.
There are a few different ways to handle dynamic web elements in Selenium
WebDriver:
Use XPath or CSS selectors to locate the element.
Use a wait statement to wait until the-element is visible.
Use a JavaScript command to get the element's value or attributes.
Use a combination of these methods.
PART B & C
1.What are the different types of automated software testing? Discuss about the key
factors to be considered in automated software testing?
2. Why automate web application testing? How to select the right automation tool
for web application testing?
3. What is Selenium WebDriver? Discuss in detail about the components of
Selenium?
4. What are the different locators in Selenium WebDriver? How to use locators to
locate web elements?
5. How to add classes, package, and methods to automated tests?
6. How to use test reports to improve the quality of automated tests?
7. What is Testing xml? How to use Testing xml to configure automated tests?
8 How can you generate and analyze test reports using automation frameworks
(e.g., TestNG, ExtentReports)?
9. How can you identify and locate web elements on a web page for automation?
10. How can you simulate user interactions such as clicks, inputs, and selections?