Hybrid Driven Framework

In this tutorial, we will design Hybrid driven framework using Selenium WebDriver. The Hybrid framework is one which has a flavour of Data Driven as well Keyword Driven. As discussed in earlier tutorials, Data Driven is one which is derived from external data (i.e. test data is kept in some external file like excel sheet or CSV file or Database, etc.), whereas Keyword Driven is one which has keyword driving the execution, say for example “openbrowser” is a keyword which will open a browser of your choice and perform required action.

PS: This tutorial is going to be a long post. Keep your Eclipse ready and design the framework along with it.

Let us first understand the flow of execution of the framework which we will be designing.

Architechture design of Hybrid Driven Framework:

Hybrid driven framework using Selenium WebDriver

Flow of Execution:

  1. Execution of the framework starts from reading the configuration file (config.properties). This file will give us the location of the Input file, name of the input file (AutomationInput.xlsx), and the location of the output File (Result file).
  2. Input file (AutomationInput.xlsx) file is an excel sheet; it contains the first sheet as Testsuite. Test suite sheet has four columns, 1. Name of the test case; 2. Run Flag (whether to execute respective test case or not); 3. Comments and 4. Run Status.
  3. Name of the test case in test suite sheet is same as the test case sheet name. There is one sheet corresponding to each test case.
  4. Each test case consists of 6 columns namely 1. Keyword; 2. Locator; 3. Argument; 4. Comment; 5. Run Status and 6. Return value.
  5. Each row in a test case sheet represents a test step.
  6. The first column will be a Keyword; a corresponding method is executed for each keyword. It may require a Locator or an Argument. If a keyword does not need a Locator or Argument, then those columns are kept empty.
  7. After execution of a test step, the result of the test step is updated with PASS/FAIL in Run Status field.
  8. Comments are updated in comment column if any test step fails or skipped with proper reason.
  9. If a keyword returns some value that is updated in Return value Column.
  10. Each step is executed in the the sequential column. If one or more step fails in a test case, its corresponding test case is also marked as FAIL in the test suite.
  11. Once all the test cases of a test suite are executed, and the corresponding status is updated in both sheets, a result file with a new name (timestamp appended) is saved in result folder.
  12. Logs and screenshots are also saved in the output folder.

Directory Structure of the Framework:

The framework we are designing will have below directory structure:

  • CommonLibs Directory
    • CommonDriver class file
      • This Class file consists of commonly used methods like OpenBrowser, CloseBrowser, SetPageLoadTimeot, SetElementDetectionTimeout, all possible actions like clickElement, setText, getText etc.
    • Utils Class
      • This class file consists of utility methods used in the framework like getProperties (reading data from a properties file) etc.
    • Excel Driver
      • This class file consists of methods which are required to read from an Excel Sheet, like CreateAWorkbook, OpenAnExcelSheet, getCellData, setCellData, etc.
    • Keyword Utility
      • This Keyword Utility
    • driver
      • Driver Class
  • Project Specific Directory
    • Page1 (POM design pattern)
    • Page2

This directory consists of class files – one class file for each page

  • Test cases
    • This directory consists of class files which have methods to test various scenarios.

Refer below screenshot for the same:

Directory Structure of Hybrid Framework

TestSuite Sheet:

test-suite

Testcase 1:

test-case1

CommonDriver Class File:

package commonLibs;

import java.io.File;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public class CommonDriver {
	
	private WebDriver Driver;
	private long pageLoadTimeOut;
	private long elementDetectionTimeout;
	
	public CommonDriver(){
		pageLoadTimeOut = 60l;
		elementDetectionTimeout = 30l;
	}
	
	public void setPageLoadTimeOut(long pageLoadTimeOut){
		this.pageLoadTimeOut = pageLoadTimeOut;
	}

	public void setElementDetectionTimeout(long elementDetectionTimeout) {
		this.elementDetectionTimeout = elementDetectionTimeout;
	}
	
	public void openBrowser(String browserType, String url){
		try {
			browserType = browserType.trim();
			url = url.trim();
			
			if(browserType.equalsIgnoreCase("chrome") || 
					browserType.equalsIgnoreCase("google") ||
					browserType.equalsIgnoreCase("google chrome")) {
				System.setProperty("webdriver.chrome.driver", 
						"C:\\workspace_edureka\\libs\\chromedriver.exe");
				Driver = new ChromeDriver();
			} else if(browserType.equalsIgnoreCase("ie") || 
					browserType.equalsIgnoreCase("internet") ||
					browserType.equalsIgnoreCase("internet explorer")) {
				System.setProperty("webdriver.ie.driver", 
						"C:\\workspace_edureka\\libs\\IEDriverServer.exe");
				Driver = new InternetExplorerDriver();
			} else if(browserType.equalsIgnoreCase("ff") || 
					browserType.equalsIgnoreCase("firefox") ||
					browserType.equalsIgnoreCase("mozilla firefox")) {
				
				Driver = new FirefoxDriver();
			} else {
				throw new Exception("Invalid Browser type : "+ browserType);
			}
			
			Driver.manage().deleteAllCookies();
			Driver.manage().window().maximize();
			
			Driver.manage().timeouts().pageLoadTimeout(pageLoadTimeOut, TimeUnit.SECONDS);
			Driver.manage().timeouts().implicitlyWait(elementDetectionTimeout, TimeUnit.SECONDS);
			
			if(url.isEmpty()){
				url = "about:blank";
			}
			
			Driver.get(url);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	//---------------------------------------------------------------------------------
		
		public void click(By oBy){
			try {
				Driver.findElement(oBy).click();
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}
	//---------------------------------------------------------------------------------
		
		public void clear(By oBy){
			try {
				Driver.findElement(oBy).clear();
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}
	//---------------------------------------------------------------------------------
		public void setText(By oBy, String value){
			try {
				Driver.findElement(oBy).sendKeys(value);
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}
		
		//---------------------------------------------------------------------------------
		
		public String getText(By oBy){
			try {
				return Driver.findElement(oBy).getText();
			} catch (Exception e) {
				e.printStackTrace();
				return "";
			}
		}
	
	//---------------------------------------------------------------------------------
		public void selectItemFromDropdown(By oBy, String item){
			try {
				Select dropdown = new Select(Driver.findElement(oBy));
				dropdown.selectByVisibleText(item);
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	//---------------------------------------------------------------------------------
		
		public WebDriver getDriver(){
			return Driver;
		}
	//---------------------------------------------------------------------------------
		
		public void closeBrowser(){
			try {
				if(Driver != null){
					Driver.close();
				}
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	//---------------------------------------------------------------------------------
		
		public void closeAllBrowser(){
			try {
				if(Driver != null){
					Driver.quit();
				}
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	//---------------------------------------------------------------------------------
		public void waitTillElementVisible(By oBy, long timeoutInSeconds){
			try {
				
				WebDriverWait wait = new WebDriverWait(Driver, timeoutInSeconds);
				
				wait.until(ExpectedConditions.visibilityOfElementLocated(oBy));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}

		public void navigateToUrl(String sValue) {
			
			try {
				
				Driver.navigate().to(sValue);
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}

		public void saveSnapShot(String fileName) {
			try {
				
				TakesScreenshot oCamera;
				File tmpFile, imgFile;
				
				
				fileName = fileName.trim();
				
				if(new File(fileName).exists()){
					throw new Exception("File already exists..");
				}
				
				imgFile = new File(fileName);
				oCamera = (TakesScreenshot) Driver;
				tmpFile = oCamera.getScreenshotAs(OutputType.FILE);
				FileUtils.copyFile(tmpFile, imgFile);
				
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}

		public boolean isSelected(By oBy) {
			try {
				return Driver.findElement(oBy).isSelected();
			} catch (Exception e) {
				e.printStackTrace();
				return false;
			}
			
		}
		
		public boolean isDisplayed(By oBy) {
			try {
				return Driver.findElement(oBy).isDisplayed();
			} catch (Exception e) {
				e.printStackTrace();
				return false;
			}
			
		}
		
		public boolean isEnabled(By oBy) {
			try {
				return Driver.findElement(oBy).isEnabled();
			} catch (Exception e) {
				e.printStackTrace();
				return false;
			}
			
		}
		
		//---------------------------------------------------------------------------------
	
}

Utils Class File:

package commonLibs;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Date;
import java.util.Properties;

import org.openqa.selenium.By;

public class Utils {
	
	
	
	public static void waitForSeconds(long seconds){
		try {
			
			Thread.sleep(seconds*1000L);
		} catch (Throwable t) {
			
		//	log.debug(t.getMessage());
		}
	}
	
	
	public static By getLocatorBy(String sLocatorString){
		try{
			
			String[] aLocator;
			
			sLocatorString = sLocatorString.trim();
			if(sLocatorString.isEmpty() || ! sLocatorString.contains(":=")){
				
				throw new Exception("Invalid Locator String");
			} 
			
			aLocator = sLocatorString.split(":=");
			
			if(aLocator[0].equalsIgnoreCase("id")){
				return By.id(aLocator[1]);
			}
			
			if(aLocator[0].equalsIgnoreCase("Class")){
				return By.className(aLocator[1]);
			}
			
			if(aLocator[0].equalsIgnoreCase("xPath")){
				return By.xpath(aLocator[1]);
			}
			
			if(aLocator[0].equalsIgnoreCase("css")){
				return By.cssSelector(aLocator[1]);
			}
			
			if(aLocator[0].equalsIgnoreCase("link")){
				return By.linkText(aLocator[1]);
			}
			
			if(aLocator[0].equalsIgnoreCase("partialLink")){
				return By.partialLinkText(aLocator[1]);
			}
			
			if(aLocator[0].equalsIgnoreCase("name")){
				return By.name(aLocator[1]);
			}
			
			if(aLocator[0].equalsIgnoreCase("tagname")){
				return By.tagName(aLocator[1]);
			}
			
			throw new Exception("Invalid locator String...");
			
		} catch(Throwable t){
			System.err.println(t.getMessage());
			
		//	log.debug(t.getMessage());
			return null;
		}
	}
	//----------------------------------------------------------------
	public static Properties getProperties(String sPropertiesFile){
		
		try {
			InputStream oFileReader;
			Properties oProperty;
			
			oFileReader = new FileInputStream(sPropertiesFile);
			oProperty = new Properties();
			
			oProperty.load(oFileReader);
			
			return oProperty;
			
			
		} catch (Exception e) {
			e.printStackTrace();
		//	log.debug(e.getMessage());
			return null;
		}
		
		
	}
	
	//---------------------------------------------------------------
	
	public static String getDateTimeStamp(){

		Date oDate;
		String[] sDatePart;
		String sDateStamp;
		
		
		oDate = new Date();
		System.out.println(oDate.toString());
		//Mon Sep 07 17:28:42 IST 2015

		sDatePart = oDate.toString().split(" ");
		
		sDateStamp = sDatePart[5] + "_" +
				sDatePart[1] + "_" +
				sDatePart[2] + "_" +
				sDatePart[3] ;
		
		sDateStamp = sDateStamp.replace(":",  "_");
		System.out.println(sDateStamp);
		
		//2016_Jan_31_10_47_48
		return sDateStamp;
	}



}

Excel Driver Class File:

package commonLibs;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;


import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelDriver {
	
	private InputStream oFileReader;
	private OutputStream oFileWriter;
	private Workbook oExcelWorkbook;
	private String sExcelFileName;
	
	public void createExcelWorkbook(String sFilename){
		
		try {
			
			sFilename = sFilename.trim();
			
			if(sFilename.isEmpty()){
				throw new Exception("Invalid file name..");
			}
			
			if(new File(sFilename).exists()){
				throw new Exception("File already exists");
			}
			
			if(sFilename.endsWith("xlsx")) {
				oExcelWorkbook = new XSSFWorkbook();
			} else if(sFilename.endsWith("xls")){
				oExcelWorkbook = new HSSFWorkbook();
			} else {
				throw new Exception("Invalid File Extension...");
			}
			
			oFileWriter = new FileOutputStream(sFilename);
			oExcelWorkbook.write(oFileWriter);
			oFileWriter.close();
			oExcelWorkbook.close();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	//----------------------------------------------------------------------------
	
	public void openExcelWorkbook(String sFileName){
		try {
			
			sFileName = sFileName.trim();
			
			if(sFileName.isEmpty()){
				throw new Exception("File Name not specified");
			}
			
			if(! (new File(sFileName)).exists()){
				throw new Exception("File doesnot exist.. ");
			}
			
			oFileReader = new FileInputStream(sFileName);
			sExcelFileName = sFileName;
			
			oExcelWorkbook = WorkbookFactory.create(oFileReader);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	//----------------------------------------------------------------------------
	
	public void save(){
		try {
			
			oFileWriter = new FileOutputStream(sExcelFileName);
			oExcelWorkbook.write(oFileWriter);
			
			oFileWriter.close();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	//----------------------------------------------------------------------------
	
	
	public void saveAs(String sFileNewName){
		try {
			sFileNewName = sFileNewName.trim();
			if(sFileNewName.isEmpty()){
				throw new Exception("File name does not exists");
			}
			
			if((new File(sFileNewName)).exists()){
				throw new Exception("File already exists");
			}
			
			oFileWriter = new FileOutputStream(sFileNewName);
			oExcelWorkbook.write(oFileWriter);
			
			oFileWriter.close();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	//----------------------------------------------------------------------------
	
	public void close(){
		try {
			
			oExcelWorkbook.close();
			oFileReader.close();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	//----------------------------------------------------------------------------
	
	public void createSheet(String sSheetName){
		try {
			
			sSheetName = sSheetName.trim();
			
			if(sSheetName.isEmpty()){
				throw new Exception("Sheet name not specified..");
			}
			
			Sheet oSheet;
			
			oSheet = oExcelWorkbook.getSheet(sSheetName);
			
			if(oSheet != null){
				throw new Exception("Sheet Already exist...");
			}
			
			oExcelWorkbook.createSheet(sSheetName);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	//----------------------------------------------------------------------------
	
	public int getRowCountoFSheet(String sSheetName){
		try {
			
			sSheetName = sSheetName.trim();
			
			if(sSheetName.isEmpty()){
				throw new Exception("Sheet name not specified..");
			}
			
			Sheet oSheet;
			
			oSheet = oExcelWorkbook.getSheet(sSheetName);
			
			if(oSheet == null){
				throw new Exception("Sheet doesnot exist...");
			}
			
			return oSheet.getLastRowNum();
			
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}
	//----------------------------------------------------------------------------
	
	public int getCellCount(String sSheetName, int iRow){
		try {
			
			sSheetName = sSheetName.trim();
			
			if(sSheetName.isEmpty()){
				throw new Exception("Sheet name not specified..");
			}
			
			Sheet oSheet;
			
			oSheet = oExcelWorkbook.getSheet(sSheetName);
			
			if(oSheet == null){
				throw new Exception("Sheet doesnot exist...");
			}
			
			if(iRow < 1){
				throw new Exception("Row Index start from 1");
			}
			
			Row oRow;
			
			oRow = oSheet.getRow(iRow);
			if(oRow == null ){
				return 0;
			} else {
				return oRow.getLastCellNum();
			}
			
			
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}
	//----------------------------------------------------------------------------
	
	public String getCellData(String sSheetName, int iRow, int iCell){
		try {
			
			sSheetName = sSheetName.trim();
			
			if(sSheetName.isEmpty()){
				throw new Exception("Sheet name not specified..");
			}
			
			Sheet oSheet;
			
			oSheet = oExcelWorkbook.getSheet(sSheetName);
			
			if(oSheet == null){
				throw new Exception("Sheet doesnot exist...");
			}
			
			if(iRow < 1 || iCell < 1){
				throw new Exception("Row and cell Index start from 1");
			}
			
			Row oRow;
			
			oRow = oSheet.getRow(iRow-1);
			if(oRow == null ){
				return "";
			} 
			
			Cell oCell;
			
			oCell = oRow.getCell(iCell-1);
			
			if(oCell == null ){
				return "";
			} else {
				
				if(oCell.getCellType() == Cell.CELL_TYPE_NUMERIC){
					return String.valueOf((int) oCell.getNumericCellValue());
			} else {
				return oCell.getStringCellValue();
			}
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
	}
	
	//----------------------------------------------------------------------------
	
	public void setCellData(String sSheetName, int iRow, int iCell, String sValue){
try {
			
			sSheetName = sSheetName.trim();
			
			if(sSheetName.isEmpty()){
				throw new Exception("Sheet name not specified..");
			}
			
			Sheet oSheet;
			
			oSheet = oExcelWorkbook.getSheet(sSheetName);
			
			if(oSheet == null){
				throw new Exception("Sheet doesnot exist...");
			}
			
			if(iRow < 1 || iCell < 1){
				throw new Exception("Row and cell Index start from 1");
			}
			
			Row oRow;
			
			oRow = oSheet.getRow(iRow-1);
			if(oRow == null ){
				oSheet.createRow(iRow-1);
				oRow = oSheet.getRow(iRow-1);
			} 
			
			Cell oCell;
			
			oCell = oRow.getCell(iCell-1);
			
			if(oCell == null ){
				oRow.createCell(iCell-1);
				oCell = oRow.getCell(iCell-1);
			} 
			oCell.setCellValue(sValue);
}
			
			
		 catch (Exception e) {
			e.printStackTrace();
		
		}
	
	}
	
//----------------------------------------------------------------------------
}

Keyword Utility:

package commonLibs;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

public class KeywordUtility {	
	CommonDriver Driver;
	
	public KeywordUtility(){
		Driver  = new CommonDriver();
	}
	
	public String performAction(String sActionName, By oBy, String sValue){
		sActionName = sActionName.trim();
		
		if(sActionName.isEmpty()){
			return ""; 
		}
		
		if(sActionName.equalsIgnoreCase("click")){
			Driver.click(oBy);
			
			return "";
		}
		
		if(sActionName.equalsIgnoreCase("openbrowser")){
			
			Driver.openBrowser(sValue, "about:blank");
		
			return "";
		}
		
		if(sActionName.equalsIgnoreCase("setPageLoadTimeOut")){
			
			Driver.setPageLoadTimeOut(Long.valueOf(sValue));
			
			
			return "";
		}
		
		if(sActionName.equalsIgnoreCase("setElementDetectionTimeout")){
			
			Driver.setElementDetectionTimeout(Long.valueOf(sValue));
			
			
			return "";
		}
		
		if(sActionName.equalsIgnoreCase("navigateToUrl")){
			
			Driver.navigateToUrl(sValue);
			
			
			return "";
		}
		
		if(sActionName.equalsIgnoreCase("navigateBack")){
				
			Driver.getDriver().navigate().back();
				
				
				return "";
			}
			
		if(sActionName.equalsIgnoreCase("navigateForward")){
			
			Driver.getDriver().navigate().forward();
			
			
			return "";
		}
		
		if(sActionName.equalsIgnoreCase("closeAllBrowser")){
			
			Driver.closeAllBrowser();
			
			
			return "";
		}
		
		if(sActionName.equalsIgnoreCase("closeCurrentBrowser")){
			
			Driver.closeBrowser();
			
			
			return "";
		}
		
		if(sActionName.equalsIgnoreCase("waitTillElementIsVisible")){
			
			
			Driver.waitTillElementVisible(oBy, Long.valueOf(sValue));
			
			return "";
		}
		
		if(sActionName.equalsIgnoreCase("savepagesnapshot")){
			
			Driver.saveSnapShot(sValue);
			
			
			return "";
		}
		
		
		if(sActionName.equalsIgnoreCase("clear")){
			
			Driver.getDriver().findElement(oBy).clear();
			return "";
		}
		
		
		
		if(sActionName.equalsIgnoreCase("acceptAlert")){
			
			Driver.getDriver().switchTo().alert().accept();
			return "";
		}
		
		if(sActionName.equalsIgnoreCase("rejectAlert")){
			
			Driver.getDriver().switchTo().alert().dismiss();
			return "";
		}
		
		if(sActionName.equalsIgnoreCase("selectDefaultframe")){
			Driver.getDriver().switchTo().frame(sValue);
			return "";
		}
		
		if(sActionName.equalsIgnoreCase("gettext")){
			return Driver.getText(oBy);
			 
		}
		
		if(sActionName.equalsIgnoreCase("getTitle")){
			return Driver.getDriver().getTitle();
			 
		}
		
		if(sActionName.equalsIgnoreCase("getUrl")){
			return Driver.getDriver().getCurrentUrl();
			 
		}
		
		if(sActionName.equalsIgnoreCase("setText")){
			 Driver.setText(oBy, sValue);
			 return "";
		}
		
		if(sActionName.equalsIgnoreCase("getstatus")){
			return String.valueOf(Driver.isSelected(oBy));
			 
		}
		
		if(sActionName.equalsIgnoreCase("isVisible")){
			return String.valueOf(Driver.isDisplayed(oBy));
			 
		}
		
		if(sActionName.equalsIgnoreCase("isEnabled")){
			return String.valueOf(Driver.isEnabled(oBy));
			 
		}
		
		if(sActionName.equalsIgnoreCase("selectitem")){
			Driver.selectItemFromDropdown(oBy, sValue);
			return "";
		}
		
		if(sActionName.equalsIgnoreCase("getItemsCount")){
			Select olist;
			WebElement oElement;
			
			oElement = Driver.getDriver().findElement(oBy);
			olist = new Select(oElement);
			
			return String.valueOf(olist.getOptions().size());
			
		}
		
				
		
		return "Error: Unknown keyword..";

	}



}

Driver Class File:

package driver;

import java.util.Properties;

import org.openqa.selenium.By;

import commonLibs.ExcelDriver;
import commonLibs.KeywordUtility;
import commonLibs.Utils;

public class DriverClass {



	
	private static KeywordUtility oKwDriver;
	private static String sDriverPropertyFile = "C:\\workspace_edureka\\EdurekaFramework27092016\\config\\config.properties";	
	private static Properties oDriverProperties;
	private static String sInputFileFolder;
	private static String sResultFolder;
	private static String sMainDriverInputFile;
	private static ExcelDriver oExcelDriver;
	private static String sCurrentTestCaseStatus;

	public static void main(String[] args) {
		
		oDriverProperties = Utils.getProperties(sDriverPropertyFile);
		
		sInputFileFolder = oDriverProperties.getProperty("InputFolder").trim();
		sMainDriverInputFile= oDriverProperties.getProperty("DriverInputFile").trim();
		sResultFolder = oDriverProperties.getProperty("OutputFolder").trim();
		
		
		TestSuiteDriver();
		
	//	TestCaseDriver(sMainDriverInputFile);
		
		exportToExcel();

	}
	
private static void TestSuiteDriver(){
		
		String sTestCaseSheetName, sRunFlag, sRunStatus, sComment;
		String sDriverExcelFile;
		int iRow, iRowCount;
		
		sDriverExcelFile = sInputFileFolder + "\\" + sMainDriverInputFile;
		oExcelDriver = new ExcelDriver();
		oExcelDriver.openExcelWorkbook(sDriverExcelFile);
		
		iRowCount = oExcelDriver.getRowCountoFSheet("TestSuite");
		
		for(iRow=2;iRow <=iRowCount+1;iRow++){
			sTestCaseSheetName="";
			sRunFlag="";
			sRunStatus="";
			sComment="";
			sCurrentTestCaseStatus = "Pass";
			
			sTestCaseSheetName= oExcelDriver.getCellData("TestSuite", iRow, 2);
			sRunFlag=oExcelDriver.getCellData("TestSuite", iRow, 3);
			
			
			sTestCaseSheetName = sTestCaseSheetName.trim();
			
			sRunFlag = sRunFlag.toLowerCase().trim();
			
			if(sRunFlag.equals("yes")){
				oKwDriver = null;
				sRunStatus = TestCaseDriver(sTestCaseSheetName);
				
				if (sRunStatus == "") {
					if(sCurrentTestCaseStatus == "Pass"){
						sRunStatus = "Pass";
					} else {
						sRunStatus = "Fail";
						sComment = "One or more steps got Failed";
					}
					
				} else {
					sComment = sRunStatus;
					sRunStatus = "Fail";
				}
				
			} else{
				sRunStatus = "Skipped";
				sComment = "Because, Run Flag was set to " + sRunFlag;
			}
			
			oExcelDriver.setCellData("testSuite", iRow, 4, sRunStatus);
			oExcelDriver.setCellData("testSuite", iRow, 5, sComment);
		}
		
	}

private static String TestCaseDriver(String sSheetName){
	int iRow, iRowCount;
	
	String sTestCaseDriverreturnvalue="";
	
	String sActionKeyword;
	String sObjectLocator;
	String sArgumentValue;
	String sRunStatus;
	String sComment;
	String sReturnValue;
	By oBy;
	
	try {
			
			oKwDriver = new KeywordUtility();
			iRowCount = oExcelDriver.getRowCountoFSheet(sSheetName);
			
			for(iRow=2;iRow <= iRowCount + 1;iRow++){
				sActionKeyword = "";
				sObjectLocator ="";
				sArgumentValue ="";
				sRunStatus = "";
				sComment = "";
				sReturnValue ="";
				oBy = null;
				
				sActionKeyword = oExcelDriver.getCellData(sSheetName, iRow, 2).trim();
				sObjectLocator =oExcelDriver.getCellData(sSheetName, iRow, 3).trim();
				sArgumentValue =oExcelDriver.getCellData(sSheetName, iRow, 4).trim();
				
				if(sObjectLocator != "" && !sObjectLocator.equals("")){
					oBy = Utils.getLocatorBy(sObjectLocator);
				}
				
				if(sActionKeyword == ""){
					sRunStatus = "Skipped";
					sComment = "No Action Keyword";
				} else {
					try {
						
					sReturnValue =	oKwDriver.performAction(sActionKeyword, oBy, sArgumentValue);
					
						if(sReturnValue.toLowerCase().contains("error")){
							sRunStatus = "Fail";
							sComment = sReturnValue;
							sReturnValue ="";
							sCurrentTestCaseStatus = "Fail";
						} else {
							sRunStatus = "Pass";
						}
						
					} catch (Exception e) {
						sRunStatus = "Exception";
						sComment = e.getMessage();
						sCurrentTestCaseStatus = "Fail";
					}
				}
				
				oExcelDriver.setCellData(sSheetName, iRow, 5, sRunStatus);
				oExcelDriver.setCellData(sSheetName, iRow, 7, sReturnValue);
				oExcelDriver.setCellData(sSheetName, iRow, 6, sComment);
				
			}
			
		
	} catch (Exception e) {
		sTestCaseDriverreturnvalue = e.getMessage();
		sCurrentTestCaseStatus = "Fail";
	}
	
	return sTestCaseDriverreturnvalue ;
}

private static void exportToExcel(){
	String sOutputFileName;
	String sDateTimeStamp;
	
	sDateTimeStamp = Utils.getDateTimeStamp();
	
	sOutputFileName = sResultFolder + "\\Result as on "+ sDateTimeStamp + ".xlsx";
	
	oExcelDriver.saveAs(sOutputFileName);
}
}

PS: For any questions queries or comment feel free to write us at saurabh@qatechhub.com or support@qatechhub.com. Happy Learning ?

Saurabh Dhingra

About the Author

Saurabh Dhingra

Follow Saurabh Dhingra: