-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathalert.spec.js
50 lines (41 loc) · 1.8 KB
/
alert.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
const { By, Builder, until } = require('selenium-webdriver');
const assert = require("node:assert");
describe('Interactions - Alerts', function () {
let driver;
before(async function () {
driver = await new Builder().forBrowser('chrome').build();
});
after(async () => await driver.quit());
it('Should be able to getText from alert and accept', async function () {
await driver.get('https://www.selenium.dev/selenium/web/alerts.html');
await driver.findElement(By.id("alert")).click();
await driver.wait(until.alertIsPresent());
let alert = await driver.switchTo().alert();
let alertText = await alert.getText();
await alert.accept();
// Verify
assert.equal(alertText, "cheese");
});
it('Should be able to getText from alert and dismiss', async function () {
await driver.get('https://www.selenium.dev/selenium/web/alerts.html');
await driver.findElement(By.id("confirm")).click();
await driver.wait(until.alertIsPresent());
let alert = await driver.switchTo().alert();
let alertText = await alert.getText();
await alert.dismiss();
// Verify
assert.equal(alertText, "Are you sure?");
});
it('Should be able to enter text in alert prompt', async function () {
let text = 'Selenium';
await driver.get('https://www.selenium.dev/selenium/web/alerts.html');
await driver.findElement(By.id("prompt")).click();
await driver.wait(until.alertIsPresent());
let alert = await driver.switchTo().alert();
//Type your message
await alert.sendKeys(text);
await alert.accept();
let enteredText = await driver.findElement(By.id('text'));
assert.equal(await enteredText.getText(), text);
});
});