// Path: src/test/java/com/frameworkium/integration/wikipedia/pages/EnglishCountiesPage.java
// public class EnglishCountiesPage extends BasePage<EnglishCountiesPage> {
// 
//     @Visible
//     @CacheLookup
//     @FindBy(css = "table.wikitable") // luckily there's only one
//     private OptimisedStreamTable listTable;
// 
//     public static EnglishCountiesPage open() {
//         return PageFactory.newInstance(EnglishCountiesPage.class,
//                 "https://en.wikipedia.org/wiki/List_of_ceremonial_counties_of_England");
//     }
// 
//     public int populationOf(String countyName) {
//         Predicate<WebElement> headerLookUp = e -> e.getText().trim().startsWith("County");
//         Predicate<WebElement> lookUpCellMatcher = e -> e.getText().trim().equals(countyName);
//         Predicate<WebElement> targetColHeaderLookup = e -> e.getText().trim().startsWith("Population");
//         String population = listTable
//                 .getCellsByLookup(headerLookUp, lookUpCellMatcher, targetColHeaderLookup)
//                 .findFirst()
//                 .orElseThrow(NotFoundException::new)
//                 .getText()
//                 .replaceAll(",", "");
//         return Integer.parseInt(population);
//     }
// 
//     public Stream<Integer> densities() {
//         return listTable
//                 // hard-coded index because headers are now row-span=2
//                 .getColumn(6)
//                 .map(WebElement::getText)
//                 .map(density -> density.replaceAll(",", ""))
//                 .map(Integer::parseInt);
//     }
// 
// }
// 
// Path: src/test/java/com/frameworkium/integration/wikipedia/pages/EnglishCountiesUsingListsPage.java
// public class EnglishCountiesUsingListsPage extends BasePage<EnglishCountiesUsingListsPage> {
// 
//     @Visible(checkAtMost = 1)
//     @CacheLookup
//     @FindBy(css = "table.wikitable > tbody > tr > td:nth-child(1)")
//     private List<WebElement> countyColumn;
// 
//     @CacheLookup
//     @FindBy(css = "table.wikitable > tbody > tr > td:nth-child(2)")
//     private List<WebElement> populationColumn;
// 
//     @CacheLookup
//     @FindBy(css = "table.wikitable > tbody > tr > td:nth-child(7)")
//     private List<WebElement> densityColumn;
// 
//     public static EnglishCountiesUsingListsPage open() {
//         return PageFactory.newInstance(EnglishCountiesUsingListsPage.class,
//                 "https://en.wikipedia.org/wiki/List_of_ceremonial_counties_of_England");
//     }
// 
//     public int populationOf(String countyName) {
//         String population =
//                 populationColumn.get(findCountyIndex(countyName))
//                         .getText()
//                         .replaceAll(",", "");
//         return Integer.parseInt(population);
//     }
// 
//     private int findCountyIndex(String countyName) {
//         return IntStream.range(0, countyColumn.size())
//                 .filter(i -> Objects.equals(countyColumn.get(i).getText(), countyName))
//                 .findFirst()
//                 .orElseThrow(() -> new NoSuchElementException(
//                         "County name '" + countyName + "' not found"));
//     }
// 
//     public Stream<Integer> densities() {
//         return densityColumn.stream()
//                 .map(WebElement::getText)
//                 .map(density -> density.replaceAll(",", ""))
//                 .map(Integer::parseInt);
//     }
// 
// }


import com.frameworkium.core.ui.tests.BaseUITest;
import com.frameworkium.integration.wikipedia.pages.EnglishCountiesPage;
import com.frameworkium.integration.wikipedia.pages.EnglishCountiesUsingListsPage;
import org.testng.annotations.Test;
import static com.google.common.truth.Truth.assertThat;
package com.frameworkium.integration.wikipedia.tests;



/**
 * This test demonstrates the different between using StreamTable and Lists
 * of WebElements.
 * <p>The trade-off is between readability, maintainability and performance.
 * <p>The List option is slightly longer and slightly more difficult to maintain,
 * especially if your table is changing shape (but not header text), however it
 * is significantly faster.
 */
@Test
public class EnglishCountiesTest extends BaseUITest {

    public void exploring_english_counties_data_with_stream_table() {
// Path: src/test/java/com/frameworkium/integration/wikipedia/pages/EnglishCountiesPage.java
// public class EnglishCountiesPage extends BasePage<EnglishCountiesPage> {
// 
//     @Visible
//     @CacheLookup
//     @FindBy(css = "table.wikitable") // luckily there's only one
//     private OptimisedStreamTable listTable;
// 
//     public static EnglishCountiesPage open() {
//         return PageFactory.newInstance(EnglishCountiesPage.class,
//                 "https://en.wikipedia.org/wiki/List_of_ceremonial_counties_of_England");
//     }
// 
//     public int populationOf(String countyName) {
//         Predicate<WebElement> headerLookUp = e -> e.getText().trim().startsWith("County");
//         Predicate<WebElement> lookUpCellMatcher = e -> e.getText().trim().equals(countyName);
//         Predicate<WebElement> targetColHeaderLookup = e -> e.getText().trim().startsWith("Population");
//         String population = listTable
//                 .getCellsByLookup(headerLookUp, lookUpCellMatcher, targetColHeaderLookup)
//                 .findFirst()
//                 .orElseThrow(NotFoundException::new)
//                 .getText()
//                 .replaceAll(",", "");
//         return Integer.parseInt(population);
//     }
// 
//     public Stream<Integer> densities() {
//         return listTable
//                 // hard-coded index because headers are now row-span=2
//                 .getColumn(6)
//                 .map(WebElement::getText)
//                 .map(density -> density.replaceAll(",", ""))
//                 .map(Integer::parseInt);
//     }
// 
// }
// 
// Path: src/test/java/com/frameworkium/integration/wikipedia/pages/EnglishCountiesUsingListsPage.java
// public class EnglishCountiesUsingListsPage extends BasePage<EnglishCountiesUsingListsPage> {
// 
//     @Visible(checkAtMost = 1)
//     @CacheLookup
//     @FindBy(css = "table.wikitable > tbody > tr > td:nth-child(1)")
//     private List<WebElement> countyColumn;
// 
//     @CacheLookup
//     @FindBy(css = "table.wikitable > tbody > tr > td:nth-child(2)")
//     private List<WebElement> populationColumn;
// 
//     @CacheLookup
//     @FindBy(css = "table.wikitable > tbody > tr > td:nth-child(7)")
//     private List<WebElement> densityColumn;
// 
//     public static EnglishCountiesUsingListsPage open() {
//         return PageFactory.newInstance(EnglishCountiesUsingListsPage.class,
//                 "https://en.wikipedia.org/wiki/List_of_ceremonial_counties_of_England");
//     }
// 
//     public int populationOf(String countyName) {
//         String population =
//                 populationColumn.get(findCountyIndex(countyName))
//                         .getText()
//                         .replaceAll(",", "");
//         return Integer.parseInt(population);
//     }
// 
//     private int findCountyIndex(String countyName) {
//         return IntStream.range(0, countyColumn.size())
//                 .filter(i -> Objects.equals(countyColumn.get(i).getText(), countyName))
//                 .findFirst()
//                 .orElseThrow(() -> new NoSuchElementException(
//                         "County name '" + countyName + "' not found"));
//     }
// 
//     public Stream<Integer> densities() {
//         return densityColumn.stream()
//                 .map(WebElement::getText)
//                 .map(density -> density.replaceAll(",", ""))
//                 .map(Integer::parseInt);
//     }
// 
// }


// Path: src/test/java/com/frameworkium/integration/wikipedia/tests/EnglishCountiesTest.java
import com.frameworkium.core.ui.tests.BaseUITest;
import com.frameworkium.integration.wikipedia.pages.EnglishCountiesPage;
import com.frameworkium.integration.wikipedia.pages.EnglishCountiesUsingListsPage;
import org.testng.annotations.Test;
import static com.google.common.truth.Truth.assertThat;

package com.frameworkium.integration.wikipedia.tests;



/**
 * This test demonstrates the different between using StreamTable and Lists
 * of WebElements.
 * <p>The trade-off is between readability, maintainability and performance.
 * <p>The List option is slightly longer and slightly more difficult to maintain,
 * especially if your table is changing shape (but not header text), however it
 * is significantly faster.
 */
@Test
public class EnglishCountiesTest extends BaseUITest {

    public void exploring_english_counties_data_with_stream_table() {
        EnglishCountiesPage page = EnglishCountiesPage.open();