Testing Frameworks
Testing Frameworks
What is a Framework ?
A framework is the basic structure of something. It’s a set of ideas or facts that provide support for
01 something. In the case of business problems, a framework creates the basic structure that gives
focus and support to the problem you’re trying to solve.
03 When you install a software framework, the first thing that you need to
take care of is the system requirements. Once a framework is installed
and configured, it creates a directory structure.
For example, fig. (i) illustrates the directory structure of the Framework.
Each of these folders could have additional directories. Directories can
further have files, classes, templates, and more.
04
What is a Framework?
Difference between a Library and a Framework
04 Framework : A collection of libraries which provide unique properties and behaviour to your application. (All in-
gredients)
Library : A well defined set of instructions which provide unique properties and behaviour to your data. (Oil on
Fish)
Example: Let's say you want to cook a fish curry. Then you need ingredients like oil, spices and
other utilities. You also need fish which is your base to prepare your dish on (This is data of your
application). all ingredients together called a framework. Now you goanna use them one by one or
in combination to make your fish curry which is your final product.
Now, if you consider only one ingredient, like say oil. Now what brand of oil you want to use is up
to you. This will only change taste of your application. Their use depends on the developer's pref-
erence and they are easily replaceable.
04
Benefits & Disadvantages
Benefits
• It helps in avoiding the duplication of test cases as well that is used to automate across the platforms.
• It improves test efficiency.
• It maximizes the test coverage and functionality of the application.
• It also defines the reusability of code.
• The multiple data sets can be executed easily.
• It helps in avoiding the hard code data.
• It lowers the cost of maintenance and easily scalable.
• Testing and debugging the code is a lot easier and can be done even by testers who do not own the code
04
• It helps the team to organize the test suites and helps in improving the test efficiency.
Disadvantages :
• The scripts developed using a particular framework are not reusable for other frameworks.
• The individual should have good knowledge of frameworks as well.
• Sometimes the data and complexity make the automating test not working in favour of the tester.
Types of Framework
There are five common types of test automation frameworks, each with their own architecture and differing benefits and disadvantages.
• There is no need to write custom code, so expertise in • The scripts developed using this framework aren’t reusable.
test automation is not necessary. The data is hardcoded into the test script, meaning the test
• This is one of the fastest ways to generate test scripts cases cannot be re-run with multiple sets and will need to be
since they can be easily recorded in a minimal amount of modified if the data is altered.
time. • Maintenance is considered a hassle because any changes
• The test workflow is easier to understand for any party to the application will require a lot of rework. This model is
involved in testing since the scripts are laid out in a se- not particularly scalable as the scope of testing expands.
quential manner.
• This is also the easiest way to get up and running with
automated testing, especially with a new tool.
Types of Framework
Modular Based Testing Framework
02
Modular Based Testing Framework
• If any changes are made to the application, only the • Data is still hard-coded into the test script since the tests are
module and it’s associated individual test script will executed separately, so you can’t use multiple data sets.
needs to be fixed, meaning you won’t have to tinker with • Programming knowledge is required to set up the framework
the rest of the application and can leave it untouched.
• Creating test cases takes less effort because test scripts
for different modules can be reused.
Types of Framework
Data-Driven Framework
03
Data-Driven Framework
• Tests can be executed with multiple data sets. • You’ll need a highly-experienced tester who is proficient in
• Multiple scenarios can be tested quickly by varying the various programming languages to properly utilize this
data, thereby reducing the number of scripts needed. framework design. They will need to identify and format the
• Hard-coding data can be avoided so any changes to the external data sources and to write code (create functions)
test scripts do not affect the data being used that connect the tests to those external data sources seam-
• You’ll save time by executing more tests faster. lessly.
• Setting up a data-driven framework takes a significant
amount of time.
Types of Framework
Keyword Driven Testing Framework
04
Keyword Driven Testing Framework
In a keyword-driven framework, each function of the applic-
ation under test is laid out in a table with a series of instruc-
tions in consecutive order for each test that needs to be run.
In a similar fashion to the data-driven framework, the test
data and script logic are separated in a keyword-driven
framework, but this approach takes it a step further.
eration for a Website say YAHOO MAIL. The table will look like this • Minimal scripting knowledge is needed.
Step 1: Creating Data Table (Different from Test-Data Table created in Data • A single keyword can be used across multiple test
Driven Framework). This Data Table contains Action to be performed on scripts, so the code is reusable.
GUI Objects and corresponding arguments if any. Each row repres- • Test scripts can be built independent of the application
ents one Test Step. under test.
Step 2: Writing Code in the form of Component Functions. Disadvantages
Choose a program- Choose a unit test Design the framework Build the compo- Choose a reporting Integrate framework with
ming language framework architecture nent mechanism other tools
Choose a programming language
In what programming language do I want to write my tests?
You can also write Selenium tests using the famous Beha-
vior-Driven Development (BDD) method.
In brief, BDD helps boost the readability of your tests by
structuring a test flow into Given, When, and Then (GWT)
statements.
As a result, not only test automation engineers with pro-
gramming skills but also domain experts and business test-
ers can understand the tests and contribute meaningfully to
the process of test creation, test result debugging, and test
maintenance.
Some tools that you can leverage if you choose BDD:
• Cucumber (support for most major languages)
• SpecFlow (for C#)
Choose a unit test framework
Now we’ve selected the most suitable programming Its recommend TestNG since it offers several important be-
language, we now need to pick a unit test framework nefits, such as:
that we will build our framework upon • TestNG is similar to JUnit, but it is much more powerful
than JUnit—especially in terms of testing integrated
classes. And better yet, TestNG inherits all of the bene-
fits that JUnit has to offer.
Java • TestNG gives you the ability to write more flexible and
Python Junit, TestNG, JBehave powerful tests. Some of the highlight features are: easy
annotations, grouping, sequencing, and parameterizing.
Python
Java C#
PyTest, PyUnit
C#
MSTest, xUnit, NUnit
JS
JavaScript
JEST, Jasmine
Design the
Framework
architecture
Now, it’s time to take a look at our
framework’s architecture. After re-
ferring to many big and small Sel-
enium projects, come up with a
sustainable, maintainable, and
scalable architecture shown in the
diagram. Its highly recommend that
you follow this architecture or at
least the core principles behind it.
SeleniumCore
(POM)has become the de-facto pattern used A simple Page object
in test automation frameworks because it re- • A constructor that receives a WebDriver object
duces duplication of code thus reduces the and sets its internal WebDriver object to that
test maintenance cost. object.
• The element locators that help the WebDriver
Applying POM means we’ll organize the UI object find the web elements you want to in-
elements into pages. A page can also include teract with. E.g. userNameTextBox
“actions” or business flows that you can per- • Methods to perform on the Login page such
form on the page. For instance, if your web as setUserName(), setPassword(),
app includes several pages called the Login clickLogin(), and most importantly–login()
page, Home page, Register page, etc., we’ll method that combines all of the three methods
create the corresponding PageObjects for above.
them such as LoginPage, HomePage, Re-
gisterPage, etc.
Automation
Framework
SeleniumCore SeleniumTest
Choose a reporting mechanism
At the end of the day, test automation will be useless if we cannot
Hopefully we now scale up our volume of automated tests get useful insights from the test results to take meaningful correct-
quickly and run them frequently enough to justify the upfront ive actions. There are a lot of options available out there for log-
investment. As you run more and more tests, you’ll soon find ging your automated tests.
that understanding test results will be difficult without a good Reporting mechanisms provided by testing frameworks such as
reporting mechanism. Junit and TestNG are often generated in XML format, which can
easily be interpreted by other software like CI/CD tools (Jenkins).
Unfortunately, those XMLs are not so easy to read for us human
beings.
10% Third party libraries such as ExtentReport and Allure can help
Passed you create test result reports that are human-readable. They also
include visuals like pie charts and screenshots.
20% Failed
There is an open-source Java reporting library called ReportNG.
It’s a simple HTML plug-in for the TestNG unit-testing framework
70% Skipped that provides a simple, color-coded view of the test results. The
sweet spot is: setting up ReportNG is very easy.