title: Selenium java - Pass boolean parameter from pageObjects Common function
body: <p>In my selenium test case, I have many items to verify (eg. <code>toCheck_isUserLogin</code>, <code>toCheck_isGenderChkbxExists</code> etc). </p>
  
  <p>I have group this checking into pageObjects common function for reusable purpose.
  Other than write each checking item <code>Pass/Fail</code>, I have a column in excel to specify overall test result (Pass/Fail)</p>
  
  <p>Assume one of my test case, <code>gender checkbox</code> is not found on the page, It should  write test result <code>fail</code> to column <code>'COL_IS_GENDER_CHKBX_EXISTS'</code>. </p>
  
  <p>Also It should pass <code>Testfail=true</code> into main script so at <code>@AfterMethod</code> the overall test result for the test case will be <code>fail</code> since one of the verify items failed.</p>
  
  <p>After I move the code to pageObject, I'm not able to pass <code>Testfail</code> value to main test script, could anyone help me to check whats wrong
  with my code, thanks.</p>
  
  <p><code>// Selenium Main Test Script</code></p>
  
  <pre><code>    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;
      }   
  }
  </code></pre>
  
  <p><code>// pageObjects Login_Page.java</code></p>
  
  <pre><code>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;
      }
  }
  </code></pre>
  
  <p>Pls let's me know if need more information, thanks.</p>