In the previous tutorial, we have learned about the Environment setup for Selenium WebDriver in C# In this tutorial, we are going to discuss what is an automation framework, different types of automation frameworks, and their structures.
What is Automation Framework?
A framework in programming is a tool that provides pre-made components or solutions that are customized in order to speed up development. A framework has included a library in which all the pre-made components and solutions are stored.
Mainly the aim of frameworks is to provide a common structure so that developers don’t have to redo it they can reuse the code provided from the scratch. So we can say that the frameworks allow us to cut out much of the work and save a lot of time of developers.
Types of Automation Framework
There are mainly three types of Frameworks that are module framework, data-driven framework, and keyword driven framework. Let’s have a look at all these.
Modular Automation Framework
So the first type of framework is a modular framework where for every UI component there will be a currosponding class in the project.
For example- TextBox is a UI component in my project I can use Textbox helper which is going to perform the action related to the Textbox.
This is the architecture of the modular framework which we are going to develop.
- Base class: We will have a base class that will take care of starting and stopping the WebDriver.
- App.config: it will act as a configuration file that will contain the configuration required for running the test. for example- what kind of browser I want to use, what type of username and password I need to use for login inside the application etc.
- Generic class: this class will have the methods which are common to all the test cases.
- Component helper: component helper will have classes specific to the component. For example- I can have a TextBox helper for handling the Textbox, a Button helper for handling the Button, and so on.
- Login mechanism: for the login mechanism, we will use log4j.
Data-Driven Automation Framework
The next type of framework is a data-driven framework so first, we will develop the modular framework then we will enhance it to make it a data-driven framework.
So in the case of the modular framework whatever the data required for the script will be hardcoded inside the script itself but in the case of the data-driven framework.
All those data will be stored on some external file such as an excel file and during the runtime, we are going to read the data from the excel file and supply in the script for reading the data in the excel file we will use an excel data reader.
Once our data-driven framework is done we will enhance it to a keyword-driven framework.
For example: here the data which is username and password for the application is stored in the excel file which is outside the script and during the runtime the data will be read from the excel file.
Keyword Driven Automation Framework
Now in the case of keyword-driven framework instead of storing the data, we will store the test tabs inside the excel file. Every step will be mapped to a keyword that will be unique and that unique keyword will be mapped to a method inside the project.
For example- if I want to login inside the application I need to open the webpage, I need to provide a username password, I need to click on the login button.
So I need to follow the four steps for login into the application now these four steps will be documented inside the excel file which is mapped to the corresponding keyword and during the runtime, our program will read those keywords and perform the corresponding action.
When we see the Example of a keyword-driven file where the control type represents the keywords and the rest of the columns represent what is the additional data required for performing the action.
Automation Framework structures in Selenium C#
Now we will discuss framework structure, which means the direct structure which we are going to follow in our framework.
so the First directory is a base class that will contain the classes for starting and stopping the WebDriver.
component helper which contains the specific components classes.
For example- TextBox, Button, Combo box all are web components so I can use Textbox helper, Button helper, and Combo box helper from my Component Helper directory.
configuration directory will contain the classes which is going to read the data from app.config, not only from app.config but from XML data files or flat files it depends on where we want to load our configuration.
it contains the classes which read the data from the excel files.
So these are the come handy in the data-driven or in the keyword-driven.
this directory will contain the user-defined interfaces. Suppose we want to enforce a certain structure to our framework, so for that, we might use interfaces so those interfaces will go inside the interfaces directory.
later we will learn about the page object model so we will have corresponding classes for the web pages so those classes we will place inside the PageObject directory.
this directory will have classes that Contain the constant key or constant property.
For example, a timeout is a property and I want to make it a constant so for all such types of constant keys or property will place inside the classes of the settings directory.
if I want to make any user-defined exception so it will go inside the custom exception directory.
finally, the test script folder contains the automation script, test script can have a subfolder or subdirectory also
For example, I can have module 1 and module 2 so on which will contain the automation script corresponding to module1 and module2.
So after creating this structure our framework skeleton will look like this in this we will have all the directories BaseClass, ComponentHelper, ExcelReader, TestScript for storing our automation script inside it we will have subdirectory module1 which contains the specific script for the module1.
When we will move to the next level we will learn to use these directories and classes in our project.
So I hope you all now understand what is framework, what types of frameworks we use and what is the basic structure of the framework.