-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
78 lines (69 loc) · 2.53 KB
/
Copy pathtest.js
File metadata and controls
78 lines (69 loc) · 2.53 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* Self-Heal Demo
* ==============================
* The test toggles the 🛡️ Self-Heal switch on the page first.
* This swaps all element IDs to -action- variants.
* The test then tries to find elements by their ORIGINAL IDs → fails.
* BrowserStack Self-Heal catches the broken selectors and fixes them.
*
* Run: npm test
*/
const { Builder, By, until } = require('selenium-webdriver');
const PAGE_URL = 'http://127.0.0.1:5500/'; // OR https://bstack_self-heal.site.drasticcoder.in/
const WAIT = 10000;
describe('Sweet Crumbs Bakery', () => {
let driver;
beforeAll(async () => {
driver = await new Builder().forBrowser('chrome').build();
await driver.get(PAGE_URL);
// Toggle Self-Heal → all IDs swap to -action- variants (breaks selectors below)
const toggle = await driver.findElement(By.id('healCheck'));
// await driver.executeScript('arguments[0].click();', toggle); //TODO: Uncomment this line to trigger self heal
});
afterAll(async () => {
if (driver) await driver.quit();
});
test('Click Explore Menu', async () => {
const btn = await driver.wait(
until.elementLocated(By.id('explore-menu-btn')),
WAIT,
);
await btn.click();
});
test('Open Contact Us modal', async () => {
const btn = await driver.wait(
until.elementLocated(By.id('contact-us-btn')),
WAIT,
);
await driver.executeScript(
'arguments[0].scrollIntoView({block:"center"});',
btn,
);
await driver.executeScript('arguments[0].click();', btn);
const form = await driver.wait(
until.elementLocated(By.id('contact-form')),
WAIT,
);
await driver.wait(until.elementIsVisible(form), WAIT);
});
test('Fill and submit contact form', async () => {
const nameInput = await driver.wait(
until.elementLocated(By.css('.contact-name-input')),
WAIT,
);
await driver.wait(until.elementIsVisible(nameInput), WAIT);
await driver.wait(until.elementIsEnabled(nameInput), WAIT);
await nameInput.sendKeys('BrowserStack Demo');
await driver
.findElement(By.css('.contact-email-input'))
.sendKeys('demo@browserstack.com');
await driver
.findElement(By.css('.contact-message-input'))
.sendKeys('Testing self-heal!');
await driver.findElement(By.id('send-message-btn')).click();
const toast = await driver.wait(until.elementLocated(By.id('toast')), WAIT);
await driver.wait(until.elementIsVisible(toast), WAIT);
const text = await toast.getText();
expect(text).toContain('Message sent');
});
});