Skip to content

Commit

Permalink
Adding JavaScript wait examples (#1451)[deploy site]
Browse files Browse the repository at this point in the history
* adding javascript test examples for waits

* adding examples of Implicit wait and explicit wait for javascript

* adding javascirpt wait examples in ja, pt, zh languages

---------

Co-authored-by: Sri Harsha <[email protected]>
  • Loading branch information
sachhu and harsha509 authored Sep 1, 2023
1 parent cb35c2d commit 86a5047
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
55 changes: 55 additions & 0 deletions examples/javascript/test/waits/waits.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const { suite } = require('selenium-webdriver/testing');
const { By, Browser, until } = require('selenium-webdriver');
const assert = require("node:assert");

suite(function (env) {
describe('Element Interactions', function () {
let driver;

before(async function () {
driver = await env.builder().build();
});

after(async () => await driver.quit());

it('fail', async function () {
await driver.get('https://www.selenium.dev/selenium/web/dynamic.html');
await driver.findElement(By.id("adder")).click();

await assert.rejects(async () => {
await driver.findElement(By.id("box0"))
},
Error
)
});

it('sleep', async function () {
await driver.get('https://www.selenium.dev/selenium/web/dynamic.html');
await driver.findElement(By.id("adder")).click();

await driver.sleep(2000);
let added = await driver.findElement(By.id("box0"));

assert.equal(await added.getAttribute('class'), "redbox")
});

it('implicit', async function () {
await driver.manage().setTimeouts({ implicit: 2000 });
await driver.get('https://www.selenium.dev/selenium/web/dynamic.html');
await driver.findElement(By.id("adder")).click();

let added = await driver.findElement(By.id("box0"));

assert.equal(await added.getAttribute('class'), "redbox")
});

it('explicit', async function () {
await driver.get('https://www.selenium.dev/selenium/web/dynamic.html');
let revealed = await driver.findElement(By.id("revealed"));
await driver.findElement(By.id("reveal")).click();
await driver.wait(until.elementIsVisible(revealed), 2000);
await revealed.sendKeys("Displayed");
assert.equal(await revealed.getAttribute("value"), "Displayed")
})
});
}, { browsers: [Browser.CHROME] });
4 changes: 2 additions & 2 deletions website_and_docs/content/documentation/webdriver/waits.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Solving our example with an implicit wait looks like this:
{{< gh-codeblock path="examples/ruby/spec/waits/waits_spec.rb#L28-L32" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/javascript/test/waits/waits.spec.js#L37-L41" >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
Expand Down Expand Up @@ -115,7 +115,7 @@ This example shows the condition being waited for as a _lambda_. Python also sup
{{< /tab >}}
{{% tab header="JavaScript" %}}
JavaScript also supports [Expected Conditions]({{< ref "support_features/expected_conditions" >}})
{{< badge-code >}}
{{< gh-codeblock path="examples/javascript/test/waits/waits.spec.js#L47-L51" >}}
{{% /tab %}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
Expand Down
4 changes: 2 additions & 2 deletions website_and_docs/content/documentation/webdriver/waits.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Solving our example with an implicit wait looks like this:
{{< gh-codeblock path="examples/ruby/spec/waits/waits_spec.rb#L28-L32" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/javascript/test/waits/waits.spec.js#L37-L41" >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
Expand Down Expand Up @@ -115,7 +115,7 @@ This example shows the condition being waited for as a _lambda_. Python also sup
{{< /tab >}}
{{% tab header="JavaScript" %}}
JavaScript also supports [Expected Conditions]({{< ref "support_features/expected_conditions" >}})
{{< badge-code >}}
{{< gh-codeblock path="examples/javascript/test/waits/waits.spec.js#L47-L51" >}}
{{% /tab %}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Solving our example with an implicit wait looks like this:
{{< gh-codeblock path="examples/ruby/spec/waits/waits_spec.rb#L28-L32" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/javascript/test/waits/waits.spec.js#L37-L41" >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
Expand Down Expand Up @@ -115,7 +115,7 @@ This example shows the condition being waited for as a _lambda_. Python also sup
{{< /tab >}}
{{% tab header="JavaScript" %}}
JavaScript also supports [Expected Conditions]({{< ref "support_features/expected_conditions" >}})
{{< badge-code >}}
{{< gh-codeblock path="examples/javascript/test/waits/waits.spec.js#L47-L51" >}}
{{% /tab %}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Solving our example with an implicit wait looks like this:
{{< gh-codeblock path="examples/ruby/spec/waits/waits_spec.rb#L28-L32" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< badge-code >}}
{{< gh-codeblock path="examples/javascript/test/waits/waits.spec.js#L37-L41" >}}
{{< /tab >}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
Expand Down Expand Up @@ -115,7 +115,7 @@ This example shows the condition being waited for as a _lambda_. Python also sup
{{< /tab >}}
{{% tab header="JavaScript" %}}
JavaScript also supports [Expected Conditions]({{< ref "support_features/expected_conditions" >}})
{{< badge-code >}}
{{< gh-codeblock path="examples/javascript/test/waits/waits.spec.js#L47-L51" >}}
{{% /tab %}}
{{< tab header="Kotlin" >}}
{{< badge-code >}}
Expand Down

0 comments on commit 86a5047

Please sign in to comment.