Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package dev.selenium.waits

import dev.selenium.BaseTest
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.openqa.selenium.By
import org.openqa.selenium.ElementNotInteractableException
import org.openqa.selenium.WebDriver
import org.openqa.selenium.support.ui.FluentWait
import org.openqa.selenium.support.ui.Wait
import org.openqa.selenium.support.ui.WebDriverWait
import java.time.Duration


class WaitsTest : BaseTest() {

@Test
fun implicit() {
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2))
driver.get("https://www.selenium.dev/selenium/web/dynamic.html")
driver.findElement(By.id("adder")).click()

val added = driver.findElement(By.id("box0"))

Assertions.assertEquals("redbox",added.getDomAttribute("class"))

}

@Test
fun explicit() {

driver.get("https://www.selenium.dev/selenium/web/dynamic.html")
val revealed = driver.findElement(By.id("revealed"))
driver.findElement(By.id("reveal")).click()

val wait = WebDriverWait(driver, Duration.ofSeconds(2))
wait.until { revealed.isDisplayed }

revealed.sendKeys("Displayed")
Assertions.assertEquals("Displayed", revealed.getDomProperty("value"))
}

@Test
fun explicitWithOptions() {

driver.get("https://www.selenium.dev/selenium/web/dynamic.html")

val revealed = driver.findElement(By.id("revealed"))
driver.findElement(By.id("reveal")).click()

val wait: Wait<WebDriver?> =
FluentWait(driver)
.withTimeout(Duration.ofSeconds(2))
.pollingEvery(Duration.ofMillis(300))
.ignoring(ElementNotInteractableException::class.java)

wait.until {
revealed.sendKeys("Displayed")
true
}

Assertions.assertEquals("Displayed", revealed.getDomProperty("value"))
}

}
6 changes: 3 additions & 3 deletions website_and_docs/content/documentation/webdriver/waits.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Solving our example with an implicit wait looks like this:
{{< gh-codeblock path="/examples/javascript/test/waits/waits.spec.js#L39" >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L19" >}}
{{< /tab >}}
{{< /tabpane >}}

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

Expand Down Expand Up @@ -154,6 +154,6 @@ The easiest way to customize Waits in Java is to use the `FluentWait` class:
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L51-L60" >}}
{{< /tab >}}
{{< /tabpane >}}
6 changes: 3 additions & 3 deletions website_and_docs/content/documentation/webdriver/waits.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Solving our example with an implicit wait looks like this:
{{< gh-codeblock path="/examples/javascript/test/waits/waits.spec.js#L39" >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L19" >}}
{{< /tab >}}
{{< /tabpane >}}

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

Expand Down Expand Up @@ -154,6 +154,6 @@ The easiest way to customize Waits in Java is to use the `FluentWait` class:
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L51-L60" >}}
{{< /tab >}}
{{< /tabpane >}}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Solving our example with an implicit wait looks like this:
{{< gh-codeblock path="/examples/javascript/test/waits/waits.spec.js#L39" >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L19" >}}
{{< /tab >}}
{{< /tabpane >}}

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

Expand Down Expand Up @@ -154,6 +154,6 @@ The easiest way to customize Waits in Java is to use the `FluentWait` class:
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L51-L60" >}}
{{< /tab >}}
{{< /tabpane >}}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Selenium 内置了一种自动等待元素出现的方式, 称为 _隐式等待_
{{< gh-codeblock path="/examples/javascript/test/waits/waits.spec.js#L39" >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt#L19" >}}
{{< /tab >}}
{{< /tabpane >}}

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

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

Loading