-
Notifications
You must be signed in to change notification settings - Fork 1
/
ByTestIdTest.kt
55 lines (41 loc) · 1.29 KB
/
ByTestIdTest.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
package seleniumtestinglib.locators
import seleniumtestinglib.JsFunction
import seleniumtestinglib.TL.By.testId
import seleniumtestinglib.driver
import seleniumtestinglib.render
import java.util.regex.Pattern
import kotlin.test.Test
import kotlin.test.assertEquals
class ByTestIdTest {
@Test
fun `by test id`() {
driver.render(""" <div data-testid="custom-element" /> """)
val result = driver.findElement(testId("custom-element"))
assertEquals("div", result.tagName)
}
@Test
fun regex() {
driver.render(""" <div data-testid="custom-element" /> """)
val result = driver.findElement(testId(Pattern.compile("custom")))
assertEquals("div", result.tagName)
}
@Test
fun function() {
driver.render(""" <div data-testid="custom-element" /> """)
val result = driver.findElement(testId(JsFunction("c => c.startsWith('custom')")))
assertEquals("div", result.tagName)
}
@Test
fun `not exact`() {
driver.render(
"""
<div>
<span data-testid='foobar'>I accept</span>
<p>I accept</p>
</div>
"""
)
val result = driver.findElement(testId("foo", exact = false))
assertEquals("span", result.tagName)
}
}