-
Notifications
You must be signed in to change notification settings - Fork 1
/
ByDisplayValueTest.kt
105 lines (82 loc) · 3.1 KB
/
ByDisplayValueTest.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
99
100
101
102
103
104
105
package seleniumtestinglib.locators
import org.openqa.selenium.By.tagName
import org.openqa.selenium.support.ui.Select
import seleniumtestinglib.JsFunction
import seleniumtestinglib.TL.By.displayValue
import seleniumtestinglib.TL.By.placeholderText
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 ByDisplayValueTest {
@Test
fun input() {
driver.render("<input placeholder='username' />")
driver.findElement(placeholderText("username")).sendKeys("selenium")
val result = driver.findElement(displayValue("selenium"))
assertEquals("input", result.tagName)
}
@Test
fun `not exact`() {
driver.render("<input placeholder='username' />")
driver.findElement(placeholderText("username")).sendKeys("selenium")
val result = driver.findElement(displayValue("SELEN", exact = false))
assertEquals("input", result.tagName)
}
@Test
fun regex() {
driver.render("<input placeholder='username' />")
driver.findElement(placeholderText("username")).sendKeys("selenium")
val result = driver.findElement(displayValue(Pattern.compile("selenium", CASE_INSENSITIVE)))
assertEquals("input", result.tagName)
}
@Test
fun function() {
driver.render("<input placeholder='username' />")
driver.findElement(placeholderText("username")).sendKeys("selenium")
val result = driver.findElement(displayValue(JsFunction("c => c.startsWith('selen')")))
assertEquals("input", result.tagName)
}
@Test
fun textarea() {
driver.render("<textarea id='x'></textarea>")
driver.findElement(tagName("textarea")).sendKeys("selenium")
val result = driver.findElement(displayValue("selenium"))
assertEquals("textarea", result.tagName)
}
@Test
fun select() {
driver.render(
"""
<select>
<option value="">State</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
</select>
"""
)
driver.findElement(tagName("select")).let(::Select).selectByVisibleText("Alaska")
val result = driver.findElement(displayValue("Alaska"))
assertEquals("select", result.tagName)
}
@Test
fun `select multiple`() {
driver.render(
"""
<select multiple>
<option value="">State</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
</select>
"""
)
driver.findElement(tagName("select")).let(::Select).selectByVisibleText("Alabama")
driver.findElement(tagName("select")).let(::Select).selectByVisibleText("Arizona")
val result = driver.findElement(displayValue("Arizona"))
assertEquals("select", result.tagName)
}
}