-
Notifications
You must be signed in to change notification settings - Fork 1
/
ByLabelTextTest.kt
98 lines (75 loc) · 2.36 KB
/
ByLabelTextTest.kt
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package seleniumtestinglib.locators
import seleniumtestinglib.JsFunction
import seleniumtestinglib.TL.By.labelText
import seleniumtestinglib.driver
import seleniumtestinglib.render
import java.util.regex.Pattern
import java.util.regex.Pattern.CASE_INSENSITIVE
import kotlin.test.Test
import kotlin.test.assertEquals
class ByLabelTextTest {
@Test
fun `by for`() {
driver.render(
"""
<label for="username-input">Username</label>
<input id="username-input" />
"""
)
val result = driver.findElement(labelText("Username"))
assertEquals("input", result.tagName)
}
@Test
fun `by aria-labeled-by`() {
driver.render(
"""
<label id="username-label">Username</label>
<input aria-labelledby="username-label" />
"""
)
val result = driver.findElement(labelText("Username"))
assertEquals("input", result.tagName)
}
@Test
fun `by wrapping label`() {
driver.render(
"""
<label>
<span>Username</span>
<input />
</label>
"""
)
val result = driver.findElement(labelText("Username"))
assertEquals("input", result.tagName)
}
@Test
fun `aria label`() {
driver.render("<input aria-label='Username' />")
val result = driver.findElement(labelText("Username"))
assertEquals("input", result.tagName)
}
@Test
fun `not exact with selector`() {
driver.render(
"""
<input aria-label='Username' />
<span><div class="x"><input aria-label='Username' /></div></span>
"""
)
val result = driver.findElement(labelText("user", exact = false, selector = "span .x input"))
assertEquals("input", result.tagName)
}
@Test
fun regex() {
driver.render("<input aria-label='Username' />")
val result = driver.findElement(labelText(Pattern.compile("user", CASE_INSENSITIVE)))
assertEquals("input", result.tagName)
}
@Test
fun function() {
driver.render("<input aria-label='Username' />")
val result = driver.findElement(labelText(JsFunction("c => c.startsWith('User')")))
assertEquals("input", result.tagName)
}
}