diff --git a/examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt b/examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt new file mode 100644 index 00000000000..13b9e9c9797 --- /dev/null +++ b/examples/kotlin/src/test/kotlin/dev/selenium/waits/WaitsTest.kt @@ -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 = + 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")) + } + +} \ No newline at end of file diff --git a/website_and_docs/content/documentation/webdriver/waits.en.md b/website_and_docs/content/documentation/webdriver/waits.en.md index 75a0ff3528e..65483bddbea 100644 --- a/website_and_docs/content/documentation/webdriver/waits.en.md +++ b/website_and_docs/content/documentation/webdriver/waits.en.md @@ -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 >}} @@ -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 >}} @@ -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 >}} diff --git a/website_and_docs/content/documentation/webdriver/waits.ja.md b/website_and_docs/content/documentation/webdriver/waits.ja.md index af33834feae..815a31a9622 100644 --- a/website_and_docs/content/documentation/webdriver/waits.ja.md +++ b/website_and_docs/content/documentation/webdriver/waits.ja.md @@ -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 >}} @@ -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 >}} @@ -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 >}} diff --git a/website_and_docs/content/documentation/webdriver/waits.pt-br.md b/website_and_docs/content/documentation/webdriver/waits.pt-br.md index e5e3b47f0a0..88cf8601db6 100644 --- a/website_and_docs/content/documentation/webdriver/waits.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/waits.pt-br.md @@ -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 >}} @@ -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 >}} @@ -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 >}} diff --git a/website_and_docs/content/documentation/webdriver/waits.zh-cn.md b/website_and_docs/content/documentation/webdriver/waits.zh-cn.md index 7aee4f2b557..1baf4c95a22 100644 --- a/website_and_docs/content/documentation/webdriver/waits.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/waits.zh-cn.md @@ -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 >}} @@ -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 >}} @@ -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 >}}