Concise API

Here we will provide some examples how Selenide can be used to write short and expressive UI tests.

Example 1: Checking the page title

LONG way:

assertEquals("EPP", getElement(By.tagName("title")).getText());

SHORTER way:

assertElement(By.tagName("title"), hasText("EPP"));

CONCISE way:

assertEquals("EPP", title());

Example 2: Checking the number of elements

LONG way:

assertEquals(2, getElements(By.className("item")).size());

BETTER way:

assertEquals(2, $$(".item").size());

BEST way:

$$(".item").shouldHave(size(2));

Example 3: Finding elements inside parent

LONG way:

 assertThat(getElement(By.id("documentsTable"))
                                 .findElement(By.tagName("tbody"))
                                 .findElements(By.tagName("tr")).size(), equalTo(4));

CONCISE way:

$("#documentsTable", 2).findAll("tbody tr").shouldHave(size(4));