ExecuteAutomation

Data Driven Testing with Appium using JXL

In the last post we discussed how we can write code using Page Object Model with appium and in this post we will continue to work with same code but will add code related to Data Driven testing using JXL. This post inherits some of the previous posts we discussed in executeautomation like Here is the video of the above discuss Here is the complete code we discussed in video

Test Method

@Test
	public void SimpleTest() throws BiffException, IOException {

		ExcelSheetLibrary excel = new ExcelSheetLibrary("f:\\data.xls");

		CalcAppPage calPage = new CalcAppPage(driver);

		calPage.Add(excel.ReadCell(excel.GetCell("Number1"), 1),
				excel.ReadCell(excel.GetCell("Number2"), 1));

		if (calPage.VerifyResult(excel.ReadCell(excel.GetCell("Result"), 1)))
			System.out.println("PASSED Test");
		else
			System.out.println("FAILED Test");

	}

Excel Library

package com.example.lib;

import java.io.File;
import java.io.IOException;
import java.util.Hashtable;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class ExcelSheetLibrary {

	static Sheet wrksheet;
	static Workbook wrkbook = null;
	static Hashtable dict = new Hashtable();

	// Create a Constructor
	public ExcelSheetLibrary(String ExcelSheetPath) throws BiffException,
			IOException {
		// Initialize
		wrkbook = Workbook.getWorkbook(new File(ExcelSheetPath));
		// For Demo purpose the excel sheet path is hardcoded, but not
		// recommended :)
		wrksheet = wrkbook.getSheet("Sheet1");

		ColumnDictionary();
	}

	// Returns the Number of Rows
	public static int RowCount() {
		return wrksheet.getRows();
	}

	// Returns the Cell value by taking row and Column values as argument
	public static String ReadCell(int column, int row) {
		return wrksheet.getCell(column, row).getContents();
	}

	// Create Column Dictionary to hold all the Column Names
	public static void ColumnDictionary() {
		// Iterate through all the columns in the Excel sheet and store the
		// value in Hashtable
		for (int col = 0; col < wrksheet.getColumns(); col++) {
			dict.put(ReadCell(col, 0), col);
		}
	}

	// Read Column Names
	public static int GetCell(String colName) {
		try {
			int value;
			value = ((Integer) dict.get(colName)).intValue();
			return value;
		} catch (NullPointerException e) {
			return (0);

		}
	}

}
Thanks for reading the post and watching the video !!! Please leave your comments and let me know if there is anything I should update in this post. Thanks, Karthik KK