-
Notifications
You must be signed in to change notification settings - Fork 579
Snippets
Andrei Solntsev edited this page Mar 12, 2023
·
6 revisions
$(".username").shouldHave(text("John"));
All "should"- methods automatically wait until web element appears and gets given property (text in this example). Timeout is 4 seconds by default.
$("#username").shouldHave(text("Hello, Johny!"), Duration.ofSeconds(8));
Note that you need these overloaded
should*
methods in rare specific cases - when you definitely know that this is a long-lasting query, and event is designed to happen after a pause (longer than default 4 seconds).
$$("#paymentScheduleTable tr").shouldHave(size(12));
$("#paymentScheduleTable tr", 5).shouldHave(text("42.00 USD"));
clearBrowserCache();
Here we will provide some examples how Selenide can be used to write short and expressive UI tests.
import static com.codeborne.selenide.Selenide.webdriver;
import static com.codeborne.selenide.WebDriverConditions.*;
webdriver().shouldHave(url("https://auth.google.com"));
webdriver().shouldHave(url("https://mastercard.ee"), Duration.ofSeconds(42));
webdriver().shouldNotHave(url("http://yandex.ru");
webdriver().shouldNotHave(urlStartingWith("ftp://"));
webdriver().shouldHave(currentFrameUrl(baseUrl + "/login.html"));
webdriver().shouldHave(currentFrameUrlStartingWith(baseUrl + "/logout.html"));
$$(".item").shouldHave(size(2));
For comparison, Selenium way:
assertEquals(2, getElements(By.className("item")).size());
$("#documentsTable", 2).findAll("tbody tr").shouldHave(size(4));
For comparison, Selenium way:
assertThat( getElement(By.id("documentsTable")).findElement( By.tagName("tbody")).findElements( By.tagName("tr")).size(), equalTo(4));