Pass boolean parameter from pageObjects Common function

In my selenium test case, I have many items to verify (eg. toCheck_isUserLogin, toCheck_isGenderChkbxExists etc)
I have group this checking into pageObjects common function for reusable purpose.
Other than write each checking item Pass/Fail, I have a column in excel to specify overall test result (Pass/Fail)

Assume one of my test case, gender checkbox is not found on the page, It will write test result fail to column ‘COL_IS_GENDER_CHKBX_EXISTS’
also It should pass Testfail=true into main script so at @AfterMethod the overall test result for the test case will be fail since one of the verify items failed.

After I move the code to pageObject, I’m not able to pass Testfail value to main test script, could anyone help me to check whats wrong
with my code, thanks.

// Selenium Main Test Script


public class MyTestCase_01 extends SuiteRBase{

Read_XLS FilePath_TestResult = null;

static boolean TestCasePass = true;

static boolean Testskip = false;

static boolean Testfail = false;

static int DataSet = -1;

public WebDriver driver;
@BeforeTest

public void checkCaseToRun() throws IOException{
init();

FilePath_TestResult = MyTestCase_01_TestResult;

TestCaseName = this.getClass().getSimpleName();

// code..

}
@Test(dataProvider="MyTestCase_01Data")

public void MyTestCase_01Test(String ColTestCaseName, String ColUsername, String ColPassword, String ColGender) throws Exception{
// code...

try{
Login_Page.toCheck_isUserLogin(FilePath_TestResult, TestCaseName, DataSet+1, Testfail);
// This was my code before move it into pageObjects Login_Page.java

/*    Boolean isGenderChkbxExists = driver.findElements(By.xpath(Object.getProperty("verify_isGenderChkbxExists"))).size()!= 0;

if (isGenderChkbxExists == true){

SuiteUtility.WriteResultUtility(FilePath_TestResult, TestCaseName, Constant.COL_IS_GENDER_CHKBX_EXISTS,

DataSet+1, Constant.KEYWORD_PASS);

Testfail = false;

}else{

SuiteUtility.WriteResultUtility(FilePath_TestResult, TestCaseName, Constant.COL_IS_GENDER_CHKBX_EXISTS,

DataSet+1, Constant.KEYWORD_FAIL);

Testfail=true;

}    */

Register_Page.toCheck_isGenderChkbxExists(FilePath_TestResult, TestCaseName, DataSet+1, Testfail);
}catch(Exception e){

Testfail = true;

throw (e);

}
if(Testfail){

// At last, test data assertion failure will be reported In testNG reports and It will mark your test data, test case and test suite as fail.

s_assert.assertAll();

}

}
@AfterMethod

public void reporterDataResults() throws Exception{

if(Testskip){

Add_Log.info(TestCaseName+" : Reporting test data set line "+(DataSet+1)+" as SKIP In excel.");

// 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, Constant.KEYWORD_SKIP);

}

else if(Testfail){

Add_Log.info(TestCaseName+" : Reporting test data set line "+(DataSet+1)+" as FAIL In excel.");

// 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, Constant.KEYWORD_FAIL);

}else{

Add_Log.info(TestCaseName+" : Reporting test data set line "+(DataSet+1)+" as PASS In excel.");

// 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, Constant.KEYWORD_PASS);

}

// At last make both flags as false for next data set.

Testskip=false;

Testfail=false;

}

}

// pageObjects Login_Page.java


public class Login_Page extends BaseClass{

private static WebElement element = null;

static boolean Testfail = false;

public Login_Page(WebDriver driver){

super(driver);

}

public static WebElement toCheck_isUserLogin(Read_XLS xls, String sheetName, int rowNum, Boolean Testfail) throws Exception{

try{

Boolean isUserLogin = driver.findElements(By.xpath(Object.getProperty("verify_isUserLogin"))).size()!= 0;

if (isUserLogin == true){

SuiteUtility.WriteResultUtility(xls, sheetName, Constant.COL_IS_USER_LOGIN, rowNum, Constant.KEYWORD_PASS);

Testfail = false;

}else{

SuiteUtility.WriteResultUtility(xls, sheetName, Constant.COL_IS_USER_LOGIN, rowNum, Constant.KEYWORD_FAIL);
// Pass testfail true to main script so at @AfterMethod it will write overall test result 'fail'

Testfail = true;

}

}catch(Exception e){

throw(e);

}

return element;

}

public static WebElement toCheck_isGenderChkbxExists(Read_XLS xls, String sheetName, int rowNum, Boolean Testfail) throws Exception{

try{

Boolean isGenderChkbxExists = driver.findElements(By.xpath(Object.getProperty("verify_isGenderChkbxExists"))).size()!= 0;

if (isGenderChkbxExists == true){

SuiteUtility.WriteResultUtility(xls, sheetName, Constant.COL_IS_GENDER_CHKBX_EXISTS, rowNum, Constant.KEYWORD_PASS);

Testfail = false;

}else{

// write into column 'COL_IS_GENDER_CHKBX_EXISTS' fail

SuiteUtility.WriteResultUtility(xls, sheetName, Constant.COL_IS_GENDER_CHKBX_EXISTS, rowNum, Constant.KEYWORD_FAIL);
// Pass testfail true to main script so at @AfterMethod it will write overall test result 'fail'

Testfail=true;

}

}catch(Exception e){

throw(e);

}

return element;

}

}

Pls let’s me know if need more information, thanks.

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.