- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.4k
/
Copy pathwaits.spec.js
56 lines (42 loc) · 1.78 KB
/
waits.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const { By, Browser, until, Builder} = require('selenium-webdriver');
const assert = require("node:assert");
describe('Waits', function () {
    let driver;
    before(async function () {
        driver = new Builder()
          .forBrowser(Browser.CHROME)
          .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")
    })
});