Skip to content

Commit 5c1e400

Browse files
committed
playwright automation tutorial
1 parent 8ced2ab commit 5c1e400

File tree

6 files changed

+31
-24
lines changed

6 files changed

+31
-24
lines changed

playwright.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = defineConfig({
1111
// test timeout
1212
timeout: 7 * 60 * 1000,
1313
expect: {
14-
timeout: 5 * 60 * 1000
14+
timeout: 3 * 60 * 1000
1515
},
1616

1717
testDir: './tests',

screenshots/element.png

258 KB
Loading

screenshots/fullpage.png

-174 KB
Loading

screenshots/page.png

-97.1 KB
Loading

tests/dropdownlist.spec.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
// Include playwright module
2-
const {test, expect} = require('@playwright/test');
2+
const { test, expect } = require('@playwright/test');
33

44
// Write a testa
5-
test('Handle dropdown list in playwright', async({page}) =>{
5+
test('Handle dropdown list in playwright', async ({ page }) => {
66
// Go to URL
77
await page.goto('https://www.facebook.com/')
8-
98
await page.getByText('Create new account').click();
109

10+
// Identify select tag
1111
const dropDownList = page.locator('#month');
1212

13-
await expect(dropDownList).toHaveValue('2');
13+
// Validating default selected value
14+
await expect(dropDownList).toHaveValue('8');
15+
16+
// Drop down list all the options
17+
const dropDownListOptions = page.locator('#month > option');
18+
await expect(dropDownListOptions).toHaveText(['Jan', 'Feb', 'Mar',
19+
'Apr', 'May', 'Jun', 'Jul',
20+
'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
21+
])
1422

23+
// Select by value
1524
dropDownList.selectOption('5');
1625
dropDownList.selectOption('6');
1726

27+
// Select by visible text
1828
dropDownList.selectOption('Aug');
19-
2029
await page.waitForTimeout(5000);
21-
22-
2330
})
2431

25-

tests/screenshots.spec.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
// Include playwright module
2-
const {test, expect} = require('@playwright/test');
2+
const { test, expect } = require('@playwright/test');
33

44
// Write a testa
5-
test('Take screenshot in playwright', async({page}) =>{
6-
// Go to URL
7-
await page.goto('https://www.youtube.com/@testerstalk')
5+
test('Take screenshot in playwright', async ({ page }) => {
86

9-
// element screenshot
10-
await page.locator('#channel-header-container').screenshot({path:'./screenshots/element.png'})
7+
await test.step('Go to URL', async () => {
8+
await page.goto('https://www.youtube.com/@testerstalk')
9+
});
1110

12-
// page screenshot
13-
await page.screenshot({path:'./screenshots/page.png'});
11+
await test.step('Take a element screenshot', async () => {
12+
await page.locator('#page-header-banner').screenshot({ path: './screenshots/element.png' })
13+
});
1414

15-
// full page screenshot
16-
await page.screenshot({path:'./screenshots/fullpage.png',fullPage : true});
15+
await test.step('Capture a page screenshot', async () => {
16+
await page.screenshot({ path: './screenshots/page.png' });
17+
});
1718

18-
await page.waitForTimeout(5000);
19-
20-
})
21-
22-
19+
await test.step('Take a full page screenshot', async () => {
20+
await page.screenshot({ path: './screenshots/fullpage.png', fullPage: true });
21+
await page.waitForTimeout(5000);
22+
});
23+
})

0 commit comments

Comments
 (0)