Skip to content

Commit 63d88b3

Browse files
committed
Day1 Locators and assertions
1 parent 9f84d99 commit 63d88b3

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

playwright.config.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ module.exports = defineConfig({
1414
testDir: './tests',
1515
// Maximum time one test can run for.
1616
timeout: 30 * 1000,
17+
//Maximum time to wait for any expect(assertion)
18+
expect: {
19+
timeout: 5000
20+
},
1721
/* Run tests in files in parallel */
1822
fullyParallel: false,
1923
/* Fail the build on CI if you accidentally left test.only in the source code. */
@@ -31,7 +35,7 @@ module.exports = defineConfig({
3135

3236
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3337
browserName: 'chromium',
34-
trace: 'on-first-retry',
38+
headless: false
3539
},
3640

3741
/* Configure projects for major browsers */

tests/uibasics.spec.js

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
1-
const {test} = require('@playwright/test');
1+
const {test, expect} = require('@playwright/test');
2+
const exp = require('constants');
23

3-
test('Browser Context Playwright Test', async({browser})=>{
4+
test.only('Success Login Playwright Test', async({browser})=>{
45
const context = await browser.newContext();
56
const page = await context.newPage();
6-
await page.goto("https://www.google.com");
7+
await page.goto("https://www.saucedemo.com/");
8+
console.log("title is: "+ await page.title());
9+
const usernameField = page.locator("#user-name");
10+
const passwordField = page.locator("#password");
11+
const loginBtn = page.locator("#login-button");
12+
await usernameField.fill("standard_user");
13+
await passwordField.fill("secret_sauce");
14+
await loginBtn.click();
15+
await expect(page).toHaveURL("https://www.saucedemo.com/inventory.html");
16+
console.log(await page.locator("div[data-test='inventory-item-name']").nth(0).textContent());
17+
});
18+
19+
test('Unsuccessful Login Playwright Test', async({browser})=>{
20+
const context = await browser.newContext();
21+
const page = await context.newPage();
22+
await page.goto("https://www.saucedemo.com/");
23+
console.log("title is: "+ await page.title());
24+
const usernameField = page.locator("#user-name");
25+
const passwordField = page.locator("#password");
26+
const loginBtn = page.locator("#login-button");
27+
await usernameField.fill("standard_user");
28+
await passwordField.fill("sadadad");
29+
await loginBtn.click();
30+
console.log(await page.locator("h3[data-test='error']").textContent());
31+
await expect(page.locator("h3[data-test='error']")).toContainText("do not match");
732
});
833

934
test('Page Playwright Test', async({page})=>{
10-
await page.goto("https://www.google.com");
35+
await page.goto("https://www.facebook.com");
36+
await expect(page).toHaveTitle("Facebook – log in or sign up");
37+
1138
});

0 commit comments

Comments
 (0)