-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
44 lines (34 loc) · 1.41 KB
/
test.js
File metadata and controls
44 lines (34 loc) · 1.41 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
const puppeteer = require('puppeteer');
async function runTests() {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
// Navigate to the application
await page.goto('file:///F:/Development%2001/JavaScript%2001/docs/index.html');
// Test adding a user
await page.type('#firstNameInput', 'John');
await page.type('#middleNameInput', 'A');
await page.type('#lastNameInput', 'Doe');
await page.type('#birthdateInput', '01/01/1990');
await page.click('button[onclick="storeUserInfo()"]');
// Show info to verify the user is added
await page.click('button[onclick="displayUserInfo()"]');
await page.waitForSelector('ul#userInfoList li');
// Test user display
const userList = await page.$eval('ul#userInfoList', ul => ul.innerText);
if (!userList.includes('John A Doe')) {
console.error('Test failed: User was not added correctly.');
} else {
console.log('User added successfully.');
}
// Test saving to server
page.on('dialog', async dialog => {
console.log('Server response:', dialog.message());
await dialog.dismiss();
});
await page.click('button[onclick="saveToServer()"]');
// Further testing logic for delete, edit, filtering can be added here
await browser.close();
}
runTests().catch(error => {
console.error('Error while testing:', error);
});