Monday, June 2, 2014

table manners for selenium capsules

Here is a simple table,

Let us see how Selenium Capsules can help to read the content of it.

The Table class only has two methods now, getHeader and getRows, Stream is a new collection type appears in Java 8.

And here is the test to read the table,

You can see, the table supports type, it will return the type in a Stream. For this table, we define a simple domain class called Person,

    class Person {
        private final String firstName;
        private final String lastName;
        private final int points;

        Person(String firstName, String lastName, int points) {

            this.firstName = firstName;
            this.lastName = lastName;
            this.points = points;

        public String toString() {
            return firstName + "|" + lastName + "|" + points;

When we construct the Table, we need to pass a Locator to locate the table and a Mapper to map the contents in a row to the domain class,

        Locator<AbstractPage, Element> locator = Locators.<AbstractPage>element(MAIN).and(element(TABLE));

        Locator<Stream<Element>, Person> mapper = (stream) -> {
            Iterator<String> iterator =;
            return new Person(,, PARSE_INT.locate(;

The mapper will read all the TD tags in the TR tags and call the new Person for each TR tag.
            return new Person("Jill", "Smith", 50);

it prints this when you run it

The following code is called Method Reference in Java 8.


It has good table manners.

No comments:

Post a Comment