<img alt="" src="https://secure.leadforensics.com/150446.png " style="display:none;">

Automation using Selenium WebDriver Frameworks

Uddhav Naik Sep 26, 2016

Java selenium Automation testing Selenium WebDriver Frameworks Hybrid Test Framework Keyword Driven Test Framework Data Driven Test framework

Frameworks help to structure our code and make the maintenance process easy. Without frameworks we will place all our code and data in same place which is neither re-usable nor readable. Using frameworks provides beneficial outcomes like increase code re-usage, higher portability, reduced script maintenance cost, etc.

Pre-requisites:

  • Basic programming knowledge of Java
  • Understanding of TestNG Framework
  • Installation of Eclipse IDE and Java

There are mainly three types of frameworks created by Selenium WebDriver to automate manual test cases. Based on the requirements of the project any of the below frameworks can be implemented:

  • Data Driven Test framework
  • Keyword Driven Test framework
  • Hybrid Test framework

1.      Data Driven Test framework

In data driven framework all of our test data is generated from some external files like excel, csv, XML or some database table. Selenium Webdriver Data-Driven Framework is where test input and output values are from data files (ODBC sources, CVS files, Excel files, and DAO objects) and are loaded into variables in captured or manually coded scripts.

2.      Keyword Driven Test Framework:

In keyword driven test framework, all the operations and instructions are written in some external file like excel worksheet. In this framework, keywords are developed which are equal to a unit level functionality. It is an independent framework which performs automation based on the keywords specified in the excel sheet. Based on the type of application, the number of keywords will be increased to handle different functionalities. Keyword driven test framework is a 5-step framework as described below:

Step 1)

  • The driver script Execute.java will call ReadExcelFile.java
  • ReadExcelFile.java has POI script to read data from an Excel

Step 2)

  • ReadExcelFile.java will read data from TestCase.xlsx
  • Here is how the sheet looks like-

Selenium_blog_image.png

  • According to the keywords written in excel file, the framework will perform the operation on UI.
  • For example, we need to click on a button 'Login'. Correspondingly, the excel sheet will have a keyword 'Click'. Now the AUT can have hundreds of button on a page, to identify a Login button, in excel we will input Object Name as loginButton and object type as name (see highlighted row in above image). The Object Type could be xpath, name, css or any other value

Step 3) ReadExcelFile.java will pass this data to the driver script Execute.java

Step 4)

  • For all of our UI web elements we need to create an object repository where we will place their element locator (like xpath, name, css path, class name etc.)
  • java (our driver script) will read the entire Object Repository and store it in a variable
  • To read this object repository we need a ReadObject class which has a getObjectRepository method to read it.
  • java (our driver script) will read the entire Object Repository and store it in a variable
  • To read this object repository we need a ReadObject class which has a getObjectRepository method to read it.

NOTE: You may think why we need to create an object repository. The answer, it helps in code maintenance. For example, we are using a button with name = btnlogin in 10 different test cases. In future, the developer decides to change the name from btnlogin to submit. You will have to make change in all the 10 test cases. In case of an object repository, you will make change just once in the repository.

Step 5)

  • The driver will pass the data from excel and Object Repositoy to UIOperation class.
  • UIOperation class has functions to perform actions corresponding to keywords like CLICK, SETTEXT etc. mentioned in the excel sheet.
  • UIOperation class is a java class which has the actual implementation of the code to perform operations on web elements. 

3.      Hybrid Test Framework

Hybrid Test framework is a concept where we are using the advantage of both Keyword and data driven framework.

Here for keywords we will use excel files to maintain test cases and for test data we can use data provider of TestNG framework.

Here in our hybrid framework we don't need to change anything in Keyword driven framework, here we just need to replace ExecuteTest.java file with HybridExecuteTest.java file.

This ‘HybridExecuteTest.java’ file has all the code for keyword driven with data provider concept.

Fill the below form to download Java files

e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.