UNIT-IV
Automation Framework:
➢ A framework development is a continuous process and it needs time for development of
an exhaustive framework.
➢ A framework requires regular updates and maintenance. For example, some libraries may
be deprecated, for that we may have to update the libraries, additional libraries may be
added in some cases to make the framework more powerful.
➢ Once a dynamic framework has been developed after a period of time, new test scripts can
be developed in a very short span of time. Along with that, maintenance also becomes
relatively easier.
Benefits of Automation Framework:
A well-designed Test Automation Framework offers several benefits to software development and
testing teams. Some of the key benefits include:
1. Efficiency: A framework provides a structured approach to test automation, making it easier and
faster to create, execute, and maintain automated tests. This efficiency translates to quicker
feedback on software quality.
2. Reusability: Modular components and reusable libraries in a framework allow test scripts to be
reused across different test scenarios, reducing duplication of effort and making maintenance more
manageable.
3. Maintainability: Frameworks enforce best practices for organizing test scripts and test data. This
results in easier maintenance as changes to the application or testing requirements can be
accommodated more smoothly.
4. Consistency: Frameworks promote consistent coding practices and testing methodologies across
the team. This consistency leads to uniform test scripts, making them easier to understand and
troubleshoot.
5. Scalability: A framework’s modularity and organized structure enable the testing team to easily
scale up the number of test cases without sacrificing maintainability.
6. Parallel Execution: Many frameworks support parallel test execution, allowing multiple tests to
be run concurrently. This reduces the overall test execution time, enabling quicker feedback in
larger test suites.
7. Reduced Manual Effort: By automating repetitive and time-consuming testing tasks, a
framework frees up QA teams to focus on more exploratory and creative testing activities.
====================================================================
Types of Automation Frameworks:
The types of automation frameworks are listed below −
1. Keyword Driven Framework
2. Data Driven Framework
1
3. Hybrid Driven Framework
1. Keyword Driven Framework:
➢ A keyword testing or a keyword driven framework is a set of guidelines followed while
automating test cases, in which the implementation logic and the technical information are
hidden. The usage and maintenance of a keyword driven framework is very easy.
➢ A group of keywords in a particular and purposeful order has to be incorporated as a part of test
case preparation to perform a particular task or tasks on the application. All these keywords are
described in the common repository or a reusable library.
Advantages:
➢ No technical knowledge required to create, execute, and maintain the test cases built on a
keyword driven testing framework.
➢ The test cases can be reused to a large extent in a keyword driven testing framework.
Disadvantages:
➢ Implementation of the keyword driven testing framework and its logic require high technical
skills.
➢ The unnecessary keywords created in the keyword driven testing framework may cause
confusion.
2. Data Driven Framework:
➢ In a data driven testing framework, more than one set of data can be run against the same test
case, thus the same application can be tested against a wide data range without requiring
additional code. Thus code is developed once but reused multiple times.
➢ A data driven testing framework allows multiple execution of test cases without increasing the
number of test cases. Sometimes, test data is generated automatically and this allows the
application to be tested against a wide range of random data sets. In such a scenario, a data
driven testing framework ensures a more robust and quality product.
Advantages:
➢ A single test script can be executed with multiple data sets, significantly reducing the need
to write separate scripts for each scenario.
➢ Test data is stored externally (e.g., in spreadsheets or databases), allowing for easier updates
and modifications without altering the core test script logic.
Disadvantages:
➢ Testers need strong programming skills and a good understanding of the chosen scripting
language to effectively design, implement, and maintain the framework and its associated
scripts.
➢ Managing large volumes of test data can become complex, requiring robust data management
strategies to ensure data quality, organization, and accessibility.
2
3. Hybrid Driven Framework:
➢ A hybrid framework is adopted to utilize essential features of both the keyword and data driven
frameworks. It helps to make the test cases more flexible and individual features can exist
independently without affecting the others.
➢ The test cases created with a hybrid framework are easier to maintain and addition of new test
cases to this type of framework require less of time.
Advantages:
➢ It is free and open source. Can be used across multiple platforms, browsers, and devices.
➢ Easy to maintain and scalable.
Disadvantages:
➢ Technical expertise is required to create a hybrid framework.
➢ It is difficult to port the test cases created using a hybrid framework to another application.
=====================================================================
How to install TestNG in Eclipse:
We can install TestNG in Eclipse from the TestNG plugin site in such cases.
Step 1: Go to Eclipse help and click on the “Install New Software” button.
Step 2: Enter the TestNG plugin link “[Link] in the search
bar. It will fetch the required plugin. Ensure the check bar is selected, and click the next button to
start the installation.
3
Step 3: Accept the license agreement and hit the Finish button. The installation status is visible
in the bottom right corner. Provide permission wherever required. Once installation is complete,
restart the IDE to notice changes.
4
Setting Up TestNG Eclipse Tests From Your Existing Java Projects
Once we have successfully installed TestNG on Eclipse, we can integrate it with existing Java
projects to create tests by doing the following:
Step 1: Writing a test with TestNG on Eclipse is very simple. First, find the project you need
from the explorer on the left and right-click on it.
=====================================================================
TestNG Annotations:
➢ TestNG is an open-source Java Testing testing framework for automation testing.
➢ It is built on the foundation of JUnit and NUnit.
➢ TestNG is a testing framework widely used in Selenium WebDriver for automation
testing.
➢ It provides a wide range of annotations that help in organizing and controlling the flow
of test cases.
➢ These annotations give extra information about our methods or classes and start with
the '@' symbol.
➢ TestNG is one of the most widely used open-source testing frameworks used in the
automation testing suite.
➢ This framework is built upon the foundation of JUnit and NUnit thus introducing some
new functionalities that make it more powerful and easier to use.
➢ TestNG allows you to easily define test case dependencies, annotations, grouping, test
sequencing and data-driven testing.
Advantages:
5
➢ TestNG provides parallel execution of test methods
➢ It allows to define dependency of one test method over other method
➢ It allows to assign priority to test methods
Disadvantages:
➢ TestNG has many annotations and XML configuration files.
➢ Beginners may find it confusing at first to understand the flow and setup.
➢ Running tests through [Link] can become complicated in large projects.
Types of TestNG Annotations:
1. BeforeSuite: @BeforeSuite is executed before the execution of all the test cases inside a
TestNG Suite.
2. AfterSuite: @AfterSuite is executed after the execution of all the test cases inside a
TestNG Suite.
3. BeforeTest: @BeforeTest is executed before the execution of all the @test annotated
methods inside a TestNG Suite
4. AfterTest: @AfterTest is executed after the execution of all the @test annotated methods
inside a TestNG Suite.
5. BeforeClass: @BeforeClass is executed before all the methods of the current class start
their execution.
6. AfterClass: @AfterClass is executed after all the methods of the current class finish their
execution.
7. BeforeMethod: @BeforeMethod is executed before each test method within a test class.
Suppose there are n test methods within a test class; then n times the @BeforeMethod
annotated method will be invoked.
8. AfterMethod: @AfterMethod is executed after each test method within a test class.
Suppose there are n test methods within a test class; then n times the @AfterMethod
annotated method will be invoked.
9. BeforeGroups: When you annotate a method with @BeforeGroups, TestNG ensures that
this method is invoked before any test method belonging to the specified groups is
executed.
10. AfterGroup: @AfterGroups should be executed after all the test methods belonging to a
specified group have been run.
===================================================================
TestNG Listeners
TestNG listeners are interfaces in the TestNG framework that allow you to hook into the test
execution process. They enable customization of test behavior, such as logging, reporting, or
taking actions before, after, or when a test fails, passes, or is skipped.
Benefits of using TestNG Listeners with Selenium
6
TestNG Listeners are one of the key features of TestNG, and when used in conjunction with
Selenium, they offer several benefits.
• Enhanced Test Reporting: By implementing listeners, you can capture and log events
occurring during test execution, such as test case start, test case failure, test case success,
etc.
• Test Result Analysis: Define custom actions to be taken when a test fails, such as
capturing a screenshot, logging additional information, or sending a notification. This
enables you to take immediate corrective actions and facilitates efficient debugging.
• Test Data Manipulation: Listeners provide hooks to modify or manipulate test data during
runtime. You can use listeners to dynamically update test data, parameters, or
configurations before or after each test case execution.
• Test Execution Control: Listeners allow you to define conditions and logic for executing
or skipping tests based on specific criteria.
• Test Parallelization: TestNG parallel test execution and listeners play a crucial role in
parallel test management. This can significantly reduce the test execution time, enabling
quicker release cycles.
• Custom Test Execution Behaviors: The flexibility to define custom behaviors during test
execution allows you to tailor the testing framework to suit your requirements and enhance
test automation capabilities.
=====================================================================