コード例 #1
0
    @DataProvider(name = "placeOrderCredentials")
    public Iterator<Object[]> readFromExcelIterator() throws FileNotFoundException, IOException {
      //	prop.load(getClass().getResourceAsStream("AutomationEnv.properties"));
      // String sourceXlsFileName=(String)prop.get("signUpAndOrderCard");
      String fileName =
          "C:\\Users\\WINQA\\workspace\\NewHkAutomationSuite\\Excel\\signUpandPlace.xls";
      int sheetNo = 0;
      ArrayList<Object[]> excelDataArray = new ArrayList<Object[]>();
      int cnt = 0;
      try {

        InputStream input = new BufferedInputStream(new FileInputStream(fileName));

        POIFSFileSystem fs = new POIFSFileSystem(input);
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(sheetNo);

        Iterator rows = sheet.rowIterator();

        while (rows.hasNext()) {
          int cellCount = 0;
          int flagStop = 0;
          HSSFRow row = (HSSFRow) rows.next();
          System.out.println("\n");
          Iterator cells = row.cellIterator();

          List<String> readExcelData = new LinkedList<String>();

          while (cells.hasNext()) {
            if (cellCount <= 10) {
              int cellValueInt;
              String CellValue;
              HSSFCell cell = (HSSFCell) cells.next();

              if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) {
                // System.out.print( cell.getNumericCellValue()+"     " );
                cellValueInt = (int) cell.getNumericCellValue();
                CellValue = Integer.toString(cellValueInt);
              } else {
                CellValue = cell.getStringCellValue();
              }
              readExcelData.add(CellValue);
              cnt++;

              cellCount++;
            }

            if (cellCount == 11) break;
          }
          excelDataArray.add(new Object[] {readExcelData});
        }

      } catch (IOException ex) {
        ex.printStackTrace();
      }
      return excelDataArray.iterator();
    }
コード例 #2
0
    // test for cod
    // @Parameters("BaseURL")
    @Test(dataProvider = "placeOrderCredentials", enabled = true)
    public void navigateAndAddToCart(List<String> dataArray)
        throws InterruptedException, IOException {
      openBrowser(baseUrl, browser);
      sendKeys(
          homePage.getSearchBox(),
          "After search products grid",
          "sign up",
          driver.getCurrentUrl(),
          dataArray.get(3),
          driver,
          tcID);
      Thread.sleep(3000);
      Click(
          homePage.getSearchBtn(), "search btn", "homepage", driver.getCurrentUrl(), driver, tcID);
      Click(
          searchResultPage.getFirstProductResult(),
          "First product",
          "Search results",
          driver.getCurrentUrl(),
          driver,
          tcID);
      Click(
          productDetailPage.getBuyNowBtn(),
          "Buy now btn",
          "Product detail page",
          driver.getCurrentUrl(),
          driver,
          tcID);
      Thread.sleep(3000);

      boolean isCartExist =
          verifyIsExist(
              productDetailPage.getCartMouseOver(),
              "Mouse over on your cart",
              "Product detail page",
              driver.getCurrentUrl(),
              driver,
              tcID);
      System.out.println("Is cart exist? " + isCartExist);
      if (isCartExist) {
        // proceedToCart();
        driver.get(baseUrl + "/beta/cart/Cart.action");
      }
      Click(
          cartFlow.getPlaceOrderBtn(),
          "Place order btn in Cart",
          "Product detail page",
          driver.getCurrentUrl(),
          driver,
          tcID);
      // Sign up
      sendKeys(
          loginPage.getEmailIdTextBox(),
          "Login page",
          "sign up",
          driver.getCurrentUrl(),
          dataArray.get(0),
          driver,
          tcID);
      sendKeys(
          loginPage.getPasswordTextBox(),
          "Login page",
          "sign up",
          driver.getCurrentUrl(),
          dataArray.get(1),
          driver,
          tcID);
      Click(
          loginPage.getSignInBtn(),
          "Create an account button",
          "Sign in page",
          driver.getCurrentUrl(),
          driver,
          tcID);
      boolean isExistingAddress =
          verifyIsExist(
              cartFlow.getAddress1Box(),
              "Address 1 box",
              "Address page",
              driver.getCurrentUrl(),
              driver,
              tcID);
      if (!isExistingAddress) {
        sendKeys(
            cartFlow.getNewAddNameTextBox(),
            "Login page",
            "sign up",
            driver.getCurrentUrl(),
            signUpName,
            driver,
            tcID);
        sendKeys(
            cartFlow.getNewAddMobileTextBox(),
            "Login page",
            "sign up",
            driver.getCurrentUrl(),
            "9560489739",
            driver,
            tcID);
        sendKeys(
            cartFlow.getNewAddLine1TextBox(),
            "Login page",
            "sign up",
            driver.getCurrentUrl(),
            signUpPass,
            driver,
            tcID);
        sendKeys(
            cartFlow.getNewAddPinCode(),
            "Login page",
            "sign up",
            driver.getCurrentUrl(),
            "110085",
            driver,
            tcID);
        sendKeys(
            cartFlow.getNewAddCity(),
            "Login page",
            "sign up",
            driver.getCurrentUrl(),
            signUpPass,
            driver,
            tcID);
        selectDropdownElementByIndex(
            cartFlow.getNewAddStateDropDown(),
            "Address page",
            "Selecting state",
            driver.getCurrentUrl(),
            driver,
            10,
            tcID);
        Click(
            cartFlow.getNewAddContinueBtn(),
            "Continue btn",
            "Continue Btn",
            driver.getCurrentUrl(),
            driver,
            tcID);
      } else {
        Click(
            cartFlow.getAddress1Box(),
            "Continue btn",
            "Continue Btn",
            driver.getCurrentUrl(),
            driver,
            tcID);
      }
      Click(
          cartFlow.getPayNowBtn(),
          "Continue btn",
          "Continue Btn",
          driver.getCurrentUrl(),
          driver,
          tcID);
      Click(
          paymentPage.getCodTab(),
          "Continue btn",
          "Continue Btn",
          driver.getCurrentUrl(),
          driver,
          tcID);
      Click(
          paymentPage.getCodPayment(),
          "Continue btn",
          "Continue Btn",
          driver.getCurrentUrl(),
          driver,
          tcID);
      driver.quit();
    }