private boolean hasNext() {
   WebElement element = cataloguePage.getMainBlock().getNextPage();
   if (!CollectionUtils.isEmpty(element.findElements(By.className(NavigationLine.ACTIVE_LINK)))) {
     return true;
   }
   return false;
 }
  private void next() {

    WebElement element = cataloguePage.getMainBlock().getNextPage();
    if (!CollectionUtils.isEmpty(element.findElements(By.className(NavigationLine.ACTIVE_LINK)))) {
      element.findElement(By.className(NavigationLine.ACTIVE_LINK)).click();
    }
  }
Exemple #3
0
  @Test(dataProvider = "readFromExcel", dataProviderClass = DataProviderLayer.class)
  public void testSortingByName(String productType) throws Exception {
    goToMainPage();
    CataloguePage page = cataloguePage.selectProductType(productType);
    SortingTestHelper.setCataloguePage(page);

    helper.verifySortingItemsByNames();
  }
  public List<Item> grabItems() {
    List<Item> result = new ArrayList<Item>();
    List<WebElement> items = cataloguePage.getMainBlock().getDivClassItem();

    for (WebElement item : items) {
      BreadMaker breadMaker = new BreadMaker();
      String name = cataloguePage.getMainBlock().getDivClassName().getText();
      int price = extratNumbers(cataloguePage.getMainBlock().getPriceStrong().getText());

      String description =
          item.findElement(By.xpath(cataloguePage.getMainBlock().CLASS_DESCRIPTION)).getText();
      breadMaker.setName(name);
      breadMaker.setPrice(price);
      breadMaker.setDescription(description);
      result.add(breadMaker);
    }
    return result;
  }
  public Set<String> goToPricePage(List<String> namesList) {

    Set<String> pricePageLinks = new HashSet<String>();
    cataloguePage.getCompareBlock().getPricePageLink().click();
    for (int j = 0; j < namesList.size(); j++) {
      cataloguePage.getCompareBlock().getEditField().sendKeys(namesList.get(j));
      cataloguePage.getCompareBlock().getSearchField().click();

      List<WebElement> linkToDescription = cataloguePage.getCompareBlock().getTdPricePage();

      for (WebElement webElement : linkToDescription) {
        String hrefs = webElement.getAttribute(cataloguePage.getCompareBlock().HREF);
        pricePageLinks.add(hrefs);
      }
      cataloguePage.getCompareBlock().getEditField().clear();
    }
    return pricePageLinks;
  }
 public void verifySortingItemsByNames() {
   cataloguePage.getSortLineBlock().sortByName();
   List<Item> data = new ArrayList<Item>();
   int pageCount = 0;
   while (true && pageCount++ < 3) {
     data.addAll(grabItems());
     if (hasNext()) {
       next();
     } else {
       break;
     }
   }
   System.out.println(data);
   List<Item> namesNew = new ArrayList<Item>(data);
   Collections.sort(namesNew);
   Assert.assertEquals(data, namesNew);
 }
  public void gerUrls(List<String> catalogueLinks, List<String> pricePageLinks) {

    List<String> urlList = new ArrayList<String>();
    List<String> namesList = new ArrayList<String>();

    for (int i = 1; i < 6; i++) {
      List<WebElement> names =
          cataloguePage
              .getDriver()
              .findElements(
                  By.xpath(
                      cataloguePage.getCompareBlock().DIV_CLASS_ITEM_PART_1
                          + i
                          + cataloguePage.getCompareBlock().DIV_CLASS_ITEM_PART_2));
      for (WebElement webElement : names) {
        String hrefs = webElement.getAttribute(cataloguePage.getCompareBlock().HREF);
        String itemNames = webElement.getText();
        namesList.add(itemNames);
        catalogueLinks.add(hrefs);
      }
      cataloguePage
          .getDriver()
          .findElement(
              By.xpath(
                  cataloguePage.getCompareBlock().DIV_CLASS_ITEM_PART_1
                      + i
                      + cataloguePage.getCompareBlock().DIV_CLASS_ITEM_PART_2))
          .click();
      urlList.add(i - 1, itemPage.getDriver().getCurrentUrl());
      cataloguePage.goBack();
      cataloguePage.refreshLocators();
      Assert.assertNotEquals(
          catalogueLinks,
          pricePageLinks,
          " => Some links are shown in search results by mistake! ");
    }
  }
  public void verifySortingItemsByPrices() {
    cataloguePage.getSortLineBlock().sortByPrice();

    List<Item> data = new ArrayList<Item>();
    int pageCount = 0;
    while (true && pageCount++ < 3) {
      data.addAll(grabItems());
      if (hasNext()) {
        next();
      } else {
        break;
      }
    }
    System.out.println(data);

    int prevPrice = 0;
    for (Item refrigirator : data) {
      if (prevPrice > refrigirator.getPrice()) {
        Assert.fail();
      }
      prevPrice = refrigirator.getPrice();
    }
  }