/
LastChildTest.java
39 lines (31 loc) · 1.25 KB
/
LastChildTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package integration;
import com.codeborne.selenide.ex.ElementNotFound;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static com.codeborne.selenide.Condition.attribute;
import static com.codeborne.selenide.Condition.be;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Condition.visible;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
final class LastChildTest extends ITest {
@BeforeEach
void openTestPageWithJQuery() {
openFile("page_with_selects_without_jquery.html");
}
@Test
void canFindLastChildOnAGivenElement() {
$x("//table[@id='user-table']/thead/tr").lastChild().shouldHave(text("Age"));
}
@Test
void chainingLastChildFunctionsCorrectly() {
$("#multirowTable").lastChild().lastChild().shouldHave(attribute("id", "multirowTableSecondRow"));
}
@Test
void throwsExceptionWhenNoChildrenExist() {
String expectedError = String.format("Element not found {By.xpath: //span[@id='hello-world']" +
"/By.xpath: *[last()]}%nExpected: be visible");
assertThatThrownBy(() -> $x("//span[@id='hello-world']").lastChild().should(be(visible)))
.isInstanceOf(ElementNotFound.class)
.hasMessageStartingWith(expectedError);
}
}