-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathselenium.cjs
More file actions
36 lines (28 loc) · 1 KB
/
selenium.cjs
File metadata and controls
36 lines (28 loc) · 1 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
const { Builder, By, until } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const chromedriver = require('chromedriver');
// Configure Chrome options if needed
const options = new chrome.Options();
async function runSeleniumTest() {
const driver = new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
try {
// Open a webpage
await driver.get('http://localhost:8000/');
// Wait for the title to match the expected title
const expectedTitle = 'Hello world';
await driver.wait(until.elementLocated(By.xpath("//*[text()='Hello world']")), 5000); // Wait for the title to match
console.log('Test Passed! Title matches the expected value.');
} catch (error) {
console.error(`Test Failed! Error: ${error.message}`);
} finally {
// Close the browser window
await driver.quit();
// Stop the ChromeDriver server
chromedriver.stop();
}
}
// Call the function to run the Selenium test
runSeleniumTest();