-
Notifications
You must be signed in to change notification settings - Fork 1
/
ByAltTextTest.kt
66 lines (49 loc) · 1.93 KB
/
ByAltTextTest.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
package seleniumtestinglib.locators
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
import org.openqa.selenium.NoSuchElementException
import seleniumtestinglib.JsFunction
import seleniumtestinglib.TL.By.altText
import seleniumtestinglib.driver
import seleniumtestinglib.render
import java.util.regex.Pattern
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class ByAltTextTest {
@ParameterizedTest
@ValueSource(strings = ["img", "input", "area"])
fun `by alt text`(tagName: String) {
driver.render("<$tagName alt='Incredibles 2 Poster' src='/incredibles-2.png' />")
val result = driver.findElement(altText("Incredibles 2 Poster"))
assertEquals(tagName, result.tagName)
}
@Test
fun `not exact`() {
driver.render("<img alt='Incredibles 2 Poster' src='/incredibles-2.png' />")
val result = driver.findElement(altText("incredibles 2", exact = false))
assertEquals("img", result.tagName)
}
@Test
fun regex() {
driver.render("<img alt='Incredibles 2 Poster' src='/incredibles-2.png' />")
val result = driver.findElement(altText(Pattern.compile("incred", Pattern.CASE_INSENSITIVE)))
assertEquals("img", result.tagName)
}
@Test
fun function() {
driver.render("<div alt='Incredibles 2 Poster' src='/incredibles-2.png' />")
val result = runCatching {
driver.findElement(altText(JsFunction("c => c.startsWith('inc')")))
}
assertTrue(result.exceptionOrNull() is NoSuchElementException)
}
@Test
fun `by alt text not-valid type`() {
driver.render("<div alt='Incredibles 2 Poster' src='/incredibles-2.png' />")
val result = runCatching {
driver.findElement(altText("Incredibles 2 Poster"))
}
assertTrue(result.exceptionOrNull() is NoSuchElementException)
}
}