Skip to content

Commit 8fa5f12

Browse files
committed
added Kotlin waits tests
1 parent 8ac3b91 commit 8fa5f12

File tree

1 file changed

+65
-0
lines changed
  • examples/kotlin/src/test/kotlin/dev/selenium/waits

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package dev.selenium.waits
2+
3+
import dev.selenium.BaseTest
4+
import org.junit.jupiter.api.Assertions
5+
import org.junit.jupiter.api.Test
6+
import org.openqa.selenium.By
7+
import org.openqa.selenium.ElementNotInteractableException
8+
import org.openqa.selenium.WebDriver
9+
import org.openqa.selenium.support.ui.FluentWait
10+
import org.openqa.selenium.support.ui.Wait
11+
import org.openqa.selenium.support.ui.WebDriverWait
12+
import java.time.Duration
13+
14+
15+
class WaitsTest : BaseTest() {
16+
17+
@Test
18+
fun implicit() {
19+
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2))
20+
driver.get("https://www.selenium.dev/selenium/web/dynamic.html")
21+
driver.findElement(By.id("adder")).click()
22+
23+
val added = driver.findElement(By.id("box0"))
24+
25+
Assertions.assertEquals("redbox",added.getDomAttribute("class"))
26+
27+
}
28+
29+
@Test
30+
fun explicit() {
31+
32+
driver.get("https://www.selenium.dev/selenium/web/dynamic.html")
33+
val revealed = driver.findElement(By.id("revealed"))
34+
driver.findElement(By.id("reveal")).click()
35+
36+
val wait = WebDriverWait(driver, Duration.ofSeconds(2))
37+
wait.until { revealed.isDisplayed }
38+
39+
revealed.sendKeys("Displayed")
40+
Assertions.assertEquals("Displayed", revealed.getDomProperty("value"))
41+
}
42+
43+
@Test
44+
fun explicitWithOptions() {
45+
46+
driver.get("https://www.selenium.dev/selenium/web/dynamic.html")
47+
48+
val revealed = driver.findElement(By.id("revealed"))
49+
driver.findElement(By.id("reveal")).click()
50+
51+
val wait: Wait<WebDriver?> =
52+
FluentWait(driver)
53+
.withTimeout(Duration.ofSeconds(2))
54+
.pollingEvery(Duration.ofMillis(300))
55+
.ignoring(ElementNotInteractableException::class.java)
56+
57+
wait.until {
58+
revealed.sendKeys("Displayed")
59+
true
60+
}
61+
62+
Assertions.assertEquals("Displayed", revealed.getDomProperty("value"))
63+
}
64+
65+
}

0 commit comments

Comments
 (0)