Skip to main content

Keyword Driven Framework Introduction - Part 1



Before starting this topic check the below articles once

Automation using Selenium Java
First script using Java
Types of Automation Framework


    Keyword Driven Framework is one of the automation framework types. In this type keywords specific to the function are saved in a separate file and test data is isolated. Tester's work is to map the keyword functions as per the required scripts. Other names for this framework are Table driven or Action Based testing.

The necessity for this Framework

    TDD is a good framework when compared to other previous frameworks. But that requires a tester with more programming knowledge. I am not saying Keyword Driven framework doesn't need programming knowledge. But it provides manual scripters to map the automation scripts to their test cases. For example, Navigating to the site is the essential thing. To perform this action automation tester will write a background script. To use this script manual tester will enter some keywords associated with the automation script like Navigate to the website.

Before getting into the framework, learn read and write in excel file using Apache POI

Fill the excel in the format that is convenient


Below are the steps to start the framework designing

Create a java project and add all required selenium package to the project
  1. Create 1 package(testDataFile) only for excel file and contains the main method to access all details about excel
  2. Create another package (testDataAndOtherStartupMethods) that contains ActionWord class contains methods having logical code for action keywords, TestDataAccessMethods class contains methods to access excel data
  3. Create another package for configurations required for test cases and that contains class GlobalVariables that had all common variables using in the project and action words class which contains all the actions in the excel sheet
The project structure will be like below




ActionWords.java

package testDataAndOtherStartupMethods;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import globalVariables.GlobalVariables;
public class ActionWords {
public static WebDriver driver;
public void openBrowser() {
driver = new ChromeDriver();
}
public void NavigateApplication() {
driver.get(GlobalVariables.applicationURL);
}
}

This class contains a logical code that is used to link the keyword in the excel file. Method name should be the same as in the excel sheet action word column. 

TestDataAccessMethods.java

package testDataAndOtherStartupMethods;
import java.io.FileInputStream;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class TestDataAccessMethods {
     private static XSSFSheet sheet;
     private static XSSFWorkbook wBook;
     private static XSSFCell Cell;
public static void setExcelFile(String Path,String SheetName) throws Exception {
     FileInputStream file = new FileInputStream(Path);
     wBook= new XSSFWorkbook(file);
     sheet = wBook.getSheet(SheetName);
  }
public static String getCellData(int RowNum, int ColNum) throws Exception{
    Cell = sheet.getRow(RowNum).getCell(ColNum);
    String cellData= Cell.getStringCellValue();
    return cellData;
  }
}

This class is used to combine methods that are used to fetch the excel detail. This is the same as in the TDD framework. 

GlobalVariables.java

package configurations;
import org.openqa.selenium.By;
public class GlobalVariables {
public static String applicationURL ="https://www.amazon.in/";
public static String testDataFileLocation = "F:\\JavaLearn\\KeywordDrivenFramework\\src\\testDataFile\\MyProgress.xlsx";
public static String sheetName = "UserDetails";

public static int testCaseIDCol = 0;
public static int testScenarioIDCol=1;
public static int actionKeywordCol = 2;

public By signInUserName = By.name("email");
public By userNameContinue = By.id("continue");
public By signIn = By.cssSelector("span[class=nav-action-inner]");
public By myAccountOverlay = By.cssSelector("a[data-nav-ref='nav_ya_signin']");
public By passwordField = By.cssSelector("input[type='password']");
public By loginSubmitButton = By.id("signInSubmit");
}

Let us continue the remaining section in the next part

Comments