@DataProvider
 public String[][] getXlsData() throws Exception {
   String[][] data = null;
   ExcelUtils.setExcelFile(
       Constant.Path_TestData + Constant.File_TestData, Constant.File_TestappNameSheet);
   data = ExcelUtils.getXlsRowData(Constant.Total_Col_MetLifeGSSP);
   return data;
 }
  public static int getRowContains(String searchString, int colNum) throws Exception {
    int i;

    try {
      int rowCount = ExcelUtils.getRowUsed();
      for (i = 0; i < rowCount; i++) {
        if (ExcelUtils.getCellData(i, colNum).equalsIgnoreCase(searchString)) {
          break;
        }
      }
      return i;
    } catch (Exception e) {
      Log.error("Class ExcelUtil | Method getRowContains | Exception desc : " + e.getMessage());
      throw (e);
    }
  }
 @AfterClass
 public void afterClass() throws Exception {
   // Printing logs to end the test case
   Log.endTestCase(sTestCaseName);
   // Closing the opened driver
   driver.close();
   // Closing the opened excel file
   ExcelUtils.closeExcelFile();
 }
 // Find Function for Searching the value in  Admin validation xls --- Dom
 public static int[][] getTotalRowContains(String searchString, int colNum) throws Exception {
   int i;
   try {
     int rowCount = ExcelUtils.getRowUsed();
     int count = 0;
     int[][] arr = new int[1][3];
     for (i = 0; i < rowCount; i++) {
       if (ExcelUtils.getCellData(i, colNum).equalsIgnoreCase(searchString)) {
         count++;
       }
     }
     arr[0][0] = count;
     arr[0][1] = ExcelUtils.getRowContains(searchString, colNum);
     arr[0][2] = arr[0][1] + count;
     return arr;
   } catch (Exception e) {
     Log.error("Class ExcelUtil | Method getRowContains | Exception desc : " + e.getMessage());
     throw (e);
   }
 }
  public static String[][] geteUpgradeTestData(int col) throws Exception {

    try {
      int row = ExcelUtils.getRowUsed();
      String[][] testData = new String[row - 1][col];
      int i, j;
      // System.out.println("row -->"+row);
      for (i = 0; i < row - 1; i++) {
        for (j = 0; j < col; j++) {
          testData[i][j] = ExcelUtils.getCellData(i + 2, j);
          //	Log.info("i-->"+i+" j---"+j+" --->"+testData[i][j]);

        }
      }
      return testData;
    } catch (Exception e) {
      Log.error("Class ExcelUtil | Method getRowUsed | Exception desc : " + e.getMessage());
      //	System.out.println(e.getMessage());
      throw (e);
    }
  }
  public static String getlatitudevalue(int i, int start) throws Exception {

    String latitude = null;
    try {
      latitude = ExcelUtils.getCellData(i, start);

    } catch (Exception e) {
      Log.error("Class ExcelUtil | Method getRowContains | Exception desc : " + e.getMessage());
      throw (e);
    }

    return latitude;
  }
 public static int[] getColNameIndex(String colName, int totalCol) throws Exception {
   int[] colIndex = null;
   String temp = null, col = null;
   int j = 0;
   for (int i = ExcelUtils.getFirstRowNum(); i < totalCol; i++) {
     temp = ExcelUtils.getCellData(1, i).replace(" ", "");
     col = colName.replace(" ", "");
     if (temp.equalsIgnoreCase(col)) {
       j++;
     }
   }
   colIndex = new int[j];
   j = 0;
   for (int i = ExcelUtils.getFirstRowNum(); i < totalCol; i++) {
     temp = ExcelUtils.getCellData(1, i).replace(" ", "");
     col = colName.replace(" ", "");
     if (temp.equalsIgnoreCase(col)) {
       colIndex[j] = i;
       j++;
     }
   }
   return colIndex;
 }
  // This method is to write in the Excel cell, Row num and Col num are the parameters
  @SuppressWarnings("static-access")
  public static void setCellData(String Result, int RowNum, int ColNum, String path, String sheet)
      throws Exception {
    try {

      Row = ExcelWSheet.getRow(RowNum);
      Cell = Row.getCell(ColNum, Row.RETURN_BLANK_AS_NULL);
      if (Cell == null) {
        Cell = Row.createCell(ColNum);
        Cell.setCellValue(Result);
      } else {
        Cell.setCellValue(Result);
      }
      // Constant variables Test Data path and Test Data file name
      FileOutputStream fileOut = new FileOutputStream(path);
      ExcelWBook.write(fileOut);
      fileOut.flush();
      fileOut.close();
      ExcelUtils.closeExcelFile();
      ExcelUtils.setExcelFile(path, sheet);
    } catch (Exception e) {
      throw (e);
    }
  }
 public static int getMileCellRows(String sTestCaseName, int colNum, int start, int end)
     throws Exception {
   int i;
   try {
     for (i = start; i < end; i++) {
       if (ExcelUtils.getCellIntData(i, colNum).equalsIgnoreCase(sTestCaseName)) {
         break;
       }
     }
     return i;
   } catch (Exception e) {
     Log.error("Class ExcelUtil | Method getRowContains | Exception desc : " + e.getMessage());
     throw (e);
   }
 }
示例#10
0
  // Following TestNg Test case pattern, and divided a Test case in to three different part.
  // In Before Method, your code will always be the same for every other test case.
  // In other way before method is your prerequisites of your main Test Case
  @BeforeMethod
  public void beforeMethod() throws Exception {
    // Configuring Log4j logs, please see the following posts to learn about Log4j Logging
    // http://www.toolsqa.com/test-case-with-log4j/
    // http://www.toolsqa.com/log4j-logging/
    DOMConfigurator.configure("log4j.xml");

    // Getting the Test Case name, as it will going to use in so many places
    // The main use is to get the TestCase row from the Test Data Excel sheet
    sTestCaseName = this.toString();
    // From above method we get long test case name including package and class name etc.
    // The below method will refine your test case name, exactly the name use have used
    sTestCaseName = Utils.getTestCaseName(this.toString());

    // Start printing the logs and printing the Test Case name
    Log.startTestCase(sTestCaseName);

    // Setting up the Test Data Excel file using Constants variables
    // For Constant Variables please see http://www.toolsqa.com/constant-variables/
    // For setting up Excel for Data driven testing, please see
    // http://www.toolsqa.com/data-driven-testing-excel-poi/
    ExcelUtils.setExcelFile(Constant.Path_TestData + Constant.File_TestData, "Sheet1");

    // Fetching the Test Case row number from the Test Data Sheet
    // This row number will be feed to so many functions, to get the relevant data from the Test
    // Data sheet
    iTestCaseRow = ExcelUtils.getRowContains(sTestCaseName, Constant.Col_TestCaseName);

    // Launching the browser, this will take the Browser Type from Test Data Sheet
    driver = Utils.OpenBrowser(iTestCaseRow);

    // Initializing the Base Class for Selenium driver
    // Now we do need to provide the Selenium driver to any of the Page classes or Module Actions
    // Will soon write a post on Base Class
    new BaseClass(driver);
  }
  public static String[] getXlsRowData(int iTestRowNum, int Total_Col) throws Exception {

    String[] testData = new String[Total_Col];
    int i;
    try {
      for (i = 0; i < testData.length; i++) {
        testData[i] = ExcelUtils.getCellData(iTestRowNum, i);
        //	System.out.println(testData[i]);
      }
      return testData;
    } catch (Exception e) {
      Log.error("Class ExcelUtil | Method getRowUsed | Exception desc : " + e.getMessage());
      //	System.out.println(e.getMessage());
      throw (e);
    }
  }
  public static int getMileRowNumber(int mile, int colNum, int start, int end) throws Exception {
    int rowNo = 0;
    try {

      for (int j = start; j < end; j++) {
        if (mile <= Integer.parseInt(ExcelUtils.getCellIntData(j, colNum))) {
          rowNo = j;
          break;
        }
      }
      return rowNo;
    } catch (Exception e) {
      Log.error("Class ExcelUtil | Method getRowContains | Exception desc : " + e.getMessage());
      throw (e);
    }
  }
  @BeforeClass
  public void setUp() throws Exception {

    // Configuring Log4j logs.
    new BaseClass();
    DOMConfigurator.configure(BaseClass.bLog);
    // Setting Excel File -- Test Data xls File
    ExcelUtils.setExcelFile(
        Constant.Path_TestData + Constant.File_TestData, Constant.File_TestappNameSheet);
    // Getting the Test Case name, as it will going to use in so many places
    // The main use is to get the TestCase row from the Test Data Excel sheet
    sTestCaseName = this.toString();
    Log.info(sTestCaseName);
    sTestCaseName = Utils.getTestCaseName(this.toString());
    Log.info(sTestCaseName);
    Log.startTestCase(sTestCaseName);
    testStep = new HelperFunction();
  }
  @Test(dataProvider = "getXlsData")
  public void testUserRegistration(
      String SrNo,
      String TestCaseName,
      String FirstName,
      String LastName,
      String CitizenId,
      String DOB,
      String ZipCode,
      String Email,
      String ConfirmEmail,
      String MobileNumber,
      String NeedToExecute,
      String Result,
      String Comments)
      throws Exception {

    try {

      flag = false;
      // Fatching Test Data from the Test Data file and store into the array [] object.
      Log.info("Fatching Test Data from the Test Data file and store into the array [] object.");
      rowIndex = Integer.parseInt(SrNo);
      rowData = ExcelUtils.getXlsRowData(rowIndex, Constant.Total_Col_MetLifeGSSP);
      // Checking if test case need to be executed or not
      Log.info(
          "Value of rowData[Constant.Col_MetLifeGSSP_NeedToExecute] -->"
              + rowData[Constant.Col_MetLifeGSSP_NeedToExecute]
              + "--"
              + NeedToExecute);
      System.out.println("No -->" + SrNo);
      if (NeedToExecute.equalsIgnoreCase("Yes")) {
        // Init the Webdriver with  Opening the browser and URL
        Log.info("Webdriver init and Opening the test application");
        driver = Utils.OpenBrowser(Constant.appName);
        Log.info("Webdriver initilazied and test application open");
        // Developing the Test Step into the Modules and based on the result we verify that the step
        // is pass or not.
        // TestBase.Assert() Function is used for assertion and this will stop the execution if
        // assert is fail.
        // TestBase.verifyAssert() Function is used for assertion verification but it will not stop
        // the execution and after capturing the error it continue the execution.

        // If function() return true then the execution will move to next step of the test case step
        // otherwise it fail and stop the execution.

        // Test Step 1
        Log.info("Execution Test Step -->openRegistrationLink");
        flag = testStep.openRegistrationLink(driver, rowIndex, sTestCaseName, rowData);
        Log.info("Test Step openRegistrationLink result -- >" + flag);
        TestBase.verifyTrue(flag);

        // Test Step 2
        if (flag) {
          Log.info("Execution Test Step -->registrationCustomer");
          flag = testStep.registrationCustomer(driver, rowIndex, sTestCaseName, rowData);
          Log.info("Test Step registrationCustomer result -- >" + flag);
          TestBase.verifyTrue(flag);
        }
        // Test Step 3
        if (flag) {
          Log.info("Execution Test Step -->verifyCaptcha");
          flag = testStep.verifyCaptcha(driver, rowIndex, sTestCaseName, rowData);
          Log.info("Test Step verifyCaptcha result -- >" + flag);
          TestBase.verifyTrue(flag);
        }
        // Test Step 3
        if (flag) {
          Log.info("Execution Test Step -->verifyRegistration");
          flag = testStep.verifyRegistration(driver, rowIndex, sTestCaseName, rowData);
          Log.info("Test Step verifyRegistration result -- >" + flag);
          TestBase.verifyTrue(flag);
        }

        Log.info("Final Result of the test case -->" + sTestCaseName + "-->" + flag);
        // Printing the result of the test case in the excel Result Column and TestNG report.

        if (flag) {
          ExcelUtils.setExcelFile(
              Constant.Path_TestData + Constant.File_TestData, Constant.File_TestappNameSheet);
          ExcelUtils.setCellData(
              "Pass",
              rowIndex,
              Constant.Col_MetLifeGSSP_Result,
              Constant.Path_TestData + Constant.File_TestData,
              Constant.File_TestappNameSheet);
          ExcelUtils.setCellData(
              "Test Case executed successfully.",
              rowIndex,
              Constant.Col_MetLifeGSSP_Comments,
              Constant.Path_TestData + Constant.File_TestData,
              Constant.File_TestappNameSheet);
          Reporter.log(sTestCaseName + " Test Case Pass");
        } else {
          throw new Exception("Test Case Failed because of Verification");
        }
      }
      // If Test Case need not to be executed.
      else {
        Log.info("Test Case need not to be executed");
        // Writing comment on the test data file why this case is skipped from the execution.
        ExcelUtils.setExcelFile(
            Constant.Path_TestData + Constant.File_TestData, Constant.File_TestappNameSheet);
        ExcelUtils.setCellData(
            "Skip",
            rowIndex,
            Constant.Col_MetLifeGSSP_Result,
            Constant.Path_TestData + Constant.File_TestData,
            Constant.File_TestappNameSheet);
        ExcelUtils.setCellData(
            "Need To Execute Request is selected as No",
            rowIndex,
            Constant.Col_MetLifeGSSP_Comments,
            Constant.Path_TestData + Constant.File_TestData,
            Constant.File_TestappNameSheet);
        throw new SkipException("Skiping This Test as 'Need To Execute' Request is selected as No");
      }

    } catch (SkipException e) {
      throw (e);
    }
  }
 public static String[] getRowData(int colNo) throws Exception {
   String[] temp = new String[ExcelUtils.getRowUsed()];
   for (int i = 0; i < temp.length; i++) temp[i] = ExcelUtils.getCellData(i, colNo);
   return temp;
 }
示例#16
0
  // This is the starting of the Main Test Case
  @Test
  public void main() throws Throwable {
    // Every exception thrown from any class or method, will be catch here and will be taken care
    // off
    // For Exception handling please see
    // http://www.toolsqa.com/selenium-webdriver/exception-handling-selenium-webdriver/
    try {

      // Here we are calling the SignIN Action and passing argument (iTestCaseRow)
      // This is called Modularization, when we club series of actions in to one Module
      // For Modular Driven Framework, please see http://www.toolsqa.com/modular-driven/
      SignIn_Action.Execute(iTestCaseRow);

      // This action is to select the Product category from the Top Navigation of the Home Page
      // I have converted this in to a module, as there are so many logics involved in to this
      // selection
      // And it is always a best idea to keep your logics separate from your test case
      ProductSelect_Action.productType(iTestCaseRow);

      // This action is to select the Product from the Product Listing Page
      // I have again converted this in to a module, as there are so many logics involved in to this
      // selection
      ProductSelect_Action.productNumber(iTestCaseRow);

      // This is to assigning Product Name & Price to the variables from the Check Out page, so that
      // it can be matched later for verification
      CheckOut_Action.Execute();

      // Here we are calling the Payment Details Action and passing argument (iTestCaseRow)
      // This action will provide all the personal detail and payment detail on the page and
      // complete the payment for the selected product
      PaymentDetails_Action.execute(iTestCaseRow);

      // This is to assigning Product Name & Price to the variables from the Confirmation page, so
      // that it can be matched later for verification
      Confirmation_Action.Execute();

      // This is to match the Product Name & Price we have stored in variables of Checkout &
      // Confirmation page
      Verification_Action.Execute();

      // Now your test is about to finish but before that you need to take decision to Pass your
      // test or Fail
      // For selenium your test is pass, as you do not face any exception and you come to the end or
      // you test did not stop anywhere
      // But for you it can be fail, if any of your verification is failed
      // This is to check that if any of your verification during the execution is failed
      if (BaseClass.bResult == true) {
        // If the value of boolean variable is True, then your test is complete pass and do this
        ExcelUtils.setCellData("Pass", iTestCaseRow, Constant.Col_Result);
      } else {
        // If the value of boolean variable is False, then your test is fail, and you like to report
        // it accordingly
        // This is to throw exception in case of fail test, this exception will be caught by catch
        // block below
        throw new Exception("Test Case Failed because of Verification");
      }

      // Below are the steps you may like to perform in case of failed test or any exception faced
      // before ending your test
    } catch (Exception e) {
      // If in case you got any exception during the test, it will mark your test as Fail in the
      // test result sheet
      ExcelUtils.setCellData("Fail", iTestCaseRow, Constant.Col_Result);
      // If the exception is in between the test, bcoz of any element not found or anything, this
      // will take a screen shot
      Utils.takeScreenshot(driver, sTestCaseName);
      // This will print the error log message
      Log.error(e.getMessage());
      // Again throwing the exception to fail the test completely in the TestNG results
      throw (e);
    }
  }