Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions tests/Assertions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {test, expect} from "@playwright/test";

test('Assertion Test', async({page}) =>{
await page.goto("https://demo.nopcommerce.com/register");

//.toHaveURL() checks whether Page has URL
await expect(page).toHaveURL("https://demo.nopcommerce.com/register");

//for negative testing
//await expect(page).not.toHaveURL("");

//.toHaveTitle() checks whether Page has title
await expect(page).toHaveTitle("nopCommerce demo store. Register");

//.toVisible() checks element is present or not
const logoElement = await page.locator("//img[@alt='nopCommerce demo store']");
await expect(logoElement).toBeVisible();

//.toEnabled() checks Control is enabled
//.toDisabled() checks control is disabled
const searchBox = await page.locator("//input[@id='small-searchterms']");
await expect(searchBox).toBeEnabled();

//.toBeChecked() checks the radio btn and checkbox
const maleRadioBtn = await page.locator("//input[@id='gender-male']");
await maleRadioBtn.click();
await expect(maleRadioBtn).toBeChecked();

const newsletterCheckbox = await page.locator("(//input[contains(@id, 'NewsLetterSubscriptions')])[2]");
await expect(newsletterCheckbox).toBeChecked();

//.toHaveAttribute checks whether we have that particular attribute or not for an element
const registerBtn = await page.locator("#register-button");
await expect(registerBtn).toHaveAttribute("type", "submit");

//.toHaveText checks Element matches text
const registerHeading = await page.locator("//div[@class='page-title']/child::h1");
await expect(registerHeading).toHaveText("Register");
//.toContainText checks the partial value of element
await expect(registerHeading).toContainText("Regis");

//.toHaveValue(value) Input has a value
const emailInputBox = await page.locator("#Email");
emailInputBox.fill("KunjMaheshwari@email.com");
await expect(emailInputBox).toHaveValue("KunjMaheshwari@email.com");

//.toHaveCount() List of element has given length
const options = await page.locator('select[name="DateofBirthMonth"] option');
await expect(options).toHaveCount(13);
})
14 changes: 14 additions & 0 deletions tests/Codegen_Sample_Test.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { test, expect } from '@playwright/test';

test('test', async ({ page }) => {
await page.goto('https://www.demoblaze.com/');
await page.getByRole('link', { name: 'Log in' }).click();
await page.locator('#loginusername').click();
await page.locator('#loginusername').press('CapsLock');
await page.locator('#loginusername').fill('Kunj');
await page.locator('#loginpassword').click();
await page.locator('#loginpassword').press('CapsLock');
await page.locator('#loginpassword').fill('Test@123');
await page.getByRole('button', { name: 'Log in' }).click();
await page.getByRole('link', { name: 'Log out' }).click();
});
21 changes: 21 additions & 0 deletions tests/SoftAssertions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {test, expect} from "@playwright/test";

test('Soft Assertions', async({page}) =>{
await page.goto("https://www.demoblaze.com/");

//Hard assertions examples
await expect(page).toHaveURL("https://www.demoblaze.com/");

await expect(page).toHaveTitle("STORE");

const logoUrl = await page.locator("//a[@class='navbar-brand']/child::img");
await expect(logoUrl).toBeVisible();

//Soft Assertions examples
await expect.soft(page).toHaveURL("https://www.demoblaze.com/");

await expect.soft(page).toHaveTitle("STORE123");

//const logoUrl = await page.locator("//a[@class='navbar-brand']/child::img");
await expect.soft(logoUrl).toBeVisible();
})
19 changes: 19 additions & 0 deletions tests/mytest.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { devices, test, expect } from '@playwright/test';

// test.use({
// ...devices['iPhone 13']
// });

test('test', async ({ page }) => {
await page.goto('https://opensource-demo.orangehrmlive.com/web/index.php/auth/login');
await page.getByRole('img', { name: 'company-branding' }).click();
await page.getByRole('textbox', { name: 'Username' }).click();
await page.getByRole('textbox', { name: 'Username' }).press('CapsLock');
await page.getByRole('textbox', { name: 'Username' }).fill('Admin');
await page.getByRole('textbox', { name: 'Password' }).click();
await page.getByRole('textbox', { name: 'Password' }).fill('admin123');
await page.getByRole('button', { name: 'Login' }).click();
await page.getByRole('link', { name: 'Admin' }).click();
await page.getByRole('link', { name: 'PIM' }).click();
await page.getByRole('link', { name: 'Leave' }).click();
});
Loading