コード例 #1
0
 public void proceedToCart() throws InterruptedException {
   Thread.sleep(1000);
   System.out.println("inside proceed to cart");
   Actions actions = new Actions(driver);
   actions.moveToElement(driver.findElement(By.xpath(productDetailPage.getCartMouseOver())));
   actions.pause(1000);
   WebElement proceedToCart =
       driver.findElement(By.xpath(productDetailPage.getProceedToCartBtn()));
   actions.moveToElement(proceedToCart).sendKeys(Keys.ENTER).perform();
   String title = driver.getTitle();
   System.out.println(title);
   /*(new WebDriverWait(driver, 5))
   .until(ExpectedConditions.presenceOfElementLocated(By.xpath(productDetailPage.getProceedToCartBtn()))).click();*/
   String temp = driver.getTitle();
   if (temp.equals(title)) {
     System.out.println("Cart button was not clicked,trying again");
     proceedToCart();
   } else return;
 }
コード例 #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();
    }