Skip to content

Commit b94ce0d

Browse files
Merge branch 'trunk' into Fix2445
2 parents cc00ee5 + e49b07e commit b94ce0d

File tree

5 files changed

+77
-12
lines changed

5 files changed

+77
-12
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+
}

website_and_docs/content/documentation/webdriver/waits.en.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Solving our example with an implicit wait looks like this:
8282
{{< gh-codeblock path="/examples/javascript/test/waits/waits.spec.js#L39" >}}
8383
{{< /tab >}}
8484
{{< tab header="Kotlin" >}}
85-
{{< badge-code >}}
85+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L19" >}}
8686
{{< /tab >}}
8787
{{< /tabpane >}}
8888

@@ -118,7 +118,7 @@ JavaScript also supports [Expected Conditions]({{< ref "support_features/expecte
118118
{{< gh-codeblock path="/examples/javascript/test/waits/waits.spec.js#L52" >}}
119119
{{% /tab %}}
120120
{{< tab header="Kotlin" >}}
121-
{{< badge-code >}}
121+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L36-L37" >}}
122122
{{< /tab >}}
123123
{{< /tabpane >}}
124124

@@ -154,6 +154,6 @@ The easiest way to customize Waits in Java is to use the `FluentWait` class:
154154
{{< badge-code >}}
155155
{{< /tab >}}
156156
{{< tab header="Kotlin" >}}
157-
{{< badge-code >}}
157+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L51-L60" >}}
158158
{{< /tab >}}
159159
{{< /tabpane >}}

website_and_docs/content/documentation/webdriver/waits.ja.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Solving our example with an implicit wait looks like this:
8282
{{< gh-codeblock path="/examples/javascript/test/waits/waits.spec.js#L39" >}}
8383
{{< /tab >}}
8484
{{< tab header="Kotlin" >}}
85-
{{< badge-code >}}
85+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L19" >}}
8686
{{< /tab >}}
8787
{{< /tabpane >}}
8888

@@ -118,7 +118,7 @@ JavaScript also supports [Expected Conditions]({{< ref "support_features/expecte
118118
{{< gh-codeblock path="/examples/javascript/test/waits/waits.spec.js#L52" >}}
119119
{{% /tab %}}
120120
{{< tab header="Kotlin" >}}
121-
{{< badge-code >}}
121+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L36-L37" >}}
122122
{{< /tab >}}
123123
{{< /tabpane >}}
124124

@@ -154,6 +154,6 @@ The easiest way to customize Waits in Java is to use the `FluentWait` class:
154154
{{< badge-code >}}
155155
{{< /tab >}}
156156
{{< tab header="Kotlin" >}}
157-
{{< badge-code >}}
157+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L51-L60" >}}
158158
{{< /tab >}}
159159
{{< /tabpane >}}

website_and_docs/content/documentation/webdriver/waits.pt-br.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Solving our example with an implicit wait looks like this:
8282
{{< gh-codeblock path="/examples/javascript/test/waits/waits.spec.js#L39" >}}
8383
{{< /tab >}}
8484
{{< tab header="Kotlin" >}}
85-
{{< badge-code >}}
85+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L19" >}}
8686
{{< /tab >}}
8787
{{< /tabpane >}}
8888

@@ -118,7 +118,7 @@ JavaScript also supports [Expected Conditions]({{< ref "support_features/expecte
118118
{{< gh-codeblock path="/examples/javascript/test/waits/waits.spec.js#L52" >}}
119119
{{% /tab %}}
120120
{{< tab header="Kotlin" >}}
121-
{{< badge-code >}}
121+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L36-L37" >}}
122122
{{< /tab >}}
123123
{{< /tabpane >}}
124124

@@ -154,6 +154,6 @@ The easiest way to customize Waits in Java is to use the `FluentWait` class:
154154
{{< badge-code >}}
155155
{{< /tab >}}
156156
{{< tab header="Kotlin" >}}
157-
{{< badge-code >}}
157+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L51-L60" >}}
158158
{{< /tab >}}
159159
{{< /tabpane >}}

website_and_docs/content/documentation/webdriver/waits.zh-cn.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Selenium 内置了一种自动等待元素出现的方式, 称为 _隐式等待_
9292
{{< gh-codeblock path="/examples/javascript/test/waits/waits.spec.js#L39" >}}
9393
{{< /tab >}}
9494
{{< tab header="Kotlin" >}}
95-
{{< badge-code >}}
95+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L19" >}}
9696
{{< /tab >}}
9797
{{< /tabpane >}}
9898

@@ -133,7 +133,7 @@ JavaScript also supports [Expected Conditions]({{< ref "support_features/expecte
133133
{{< gh-codeblock path="/examples/javascript/test/waits/waits.spec.js#L52" >}}
134134
{{% /tab %}}
135135
{{< tab header="Kotlin" >}}
136-
{{< badge-code >}}
136+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L36-L37" >}}
137137
{{< /tab >}}
138138
{{< /tabpane >}}
139139

@@ -174,7 +174,7 @@ The easiest way to customize Waits in Java is to use the `FluentWait` class:
174174
{{< badge-code >}}
175175
{{< /tab >}}
176176
{{< tab header="Kotlin" >}}
177-
{{< badge-code >}}
177+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L51-L60" >}}
178178
{{< /tab >}}
179179
{{< /tabpane >}}
180180

0 commit comments

Comments
 (0)