@BeforeTest public void checkCaseToRun() throws IOException { // Called init() function from SuiteBase class to Initialize .xls Files init(); // To set SuiteTwo.xls file's path In FilePath Variable. FilePath = TestCaseListExcelTwo; TestCaseName = this.getClass().getSimpleName(); // SheetName to check CaseToRun flag against test case. SheetName = "TestCasesList"; // Name of column In TestCasesList Excel sheet. ToRunColumnNameTestCase = "CaseToRun"; // Name of column In Test Case Data sheets. ToRunColumnNameTestData = "DataToRun"; // To check test case's CaseToRun = Y or N In related excel sheet. // If CaseToRun = N or blank, Test case will skip execution. Else It will be executed. if (!SuiteUtility.checkToRunUtility( FilePath, SheetName, ToRunColumnNameTestCase, TestCaseName)) { // To report result as skip for test cases In TestCasesList sheet. SuiteUtility.WriteResultUtility(FilePath, SheetName, "Pass/Fail/Skip", TestCaseName, "SKIP"); // To throw skip exception for this test case. throw new SkipException( TestCaseName + "'s CaseToRun Flag Is 'N' Or Blank. So Skipping Execution Of " + TestCaseName); } // To retrieve DataToRun flags of all data set lines from related test data sheet. TestDataToRun = SuiteUtility.checkToRunUtilityOfData(FilePath, TestCaseName, ToRunColumnNameTestData); }
// @AfterMethod method will be executed after execution of @Test method every time. @AfterMethod public void reporterDataResults() { if (Testskip) { // If found Testskip = true, Result will be reported as SKIP against data set line In excel // sheet. SuiteUtility.WriteResultUtility( FilePath, TestCaseName, "Pass/Fail/Skip", DataSet + 1, "SKIP"); } else if (Testfail) { // To make object reference null after reporting In report. s_assert = null; // Set TestCasePass = false to report test case as fail In excel sheet. TestCasePass = false; // If found Testfail = true, Result will be reported as FAIL against data set line In excel // sheet. SuiteUtility.WriteResultUtility( FilePath, TestCaseName, "Pass/Fail/Skip", DataSet + 1, "FAIL"); } else { // If found Testskip = false and Testfail = false, Result will be reported as PASS against // data set line In excel sheet. SuiteUtility.WriteResultUtility( FilePath, TestCaseName, "Pass/Fail/Skip", DataSet + 1, "PASS"); } // At last make both flags as false for next data set. Testskip = false; Testfail = false; }
// To report result as pass or fail for test cases In TestCasesList sheet. @AfterTest public void closeBrowser() { // To Close the web browser at the end of test. closeWebBrowser(); if (TestCasePass) { SuiteUtility.WriteResultUtility(FilePath, SheetName, "Pass/Fail/Skip", TestCaseName, "PASS"); } else { SuiteUtility.WriteResultUtility(FilePath, SheetName, "Pass/Fail/Skip", TestCaseName, "FAIL"); } }
// This data provider method will return 3 column's data one by one In every Iteration. @DataProvider public Object[][] SuiteTwoCaseTwoData() { // To retrieve data from Data 1 Column,Data 2 Column and Expected Result column of // SuiteTwoCaseTwo data Sheet. // Last two columns (DataToRun and Pass/Fail/Skip) are Ignored programatically when reading test // data. return SuiteUtility.GetTestDataUtility(FilePath, TestCaseName); }