Skip to content

TestCases for Playwright (Automation Tools)

Kenish14 edited this page Aug 1, 2023 · 1 revision

PlayWright Test Cases

const { chromium } = require('playwright');

describe('Login Function', () => { let browser; let page;

beforeAll(async () => { browser = await chromium.launch(); page = await browser.newPage(); await page.goto('http://localhost:8080/'); });

afterAll(async () => { await browser.close(); });

it('should login successfully with valid credentials', async () => { await page.fill('#usernameInput', '<valid_username>'); await page.fill('#passwordInput', '<valid_password>'); await page.click('#loginButton'); await page.waitForNavigation();

const pageTitle = await page.title();
expect(pageTitle).toContain('Home Page'); 

}); });

describe('Home Page Features', () => {

it('should display the user's name on the home page after login', async () => { await page.fill('#usernameInput', '<valid_username>'); await page.fill('#passwordInput', '<valid_password>'); await page.click('#loginButton'); await page.waitForNavigation();

const userNameElement = await page.$('#userNameElement'); 
expect(userNameElement).not.toBeNull();

});

it('should display a navigation menu with multiple options', async () => { await page.fill('#usernameInput', '<valid_username>'); await page.fill('#passwordInput', '<valid_password>'); await page.click('#loginButton'); await page.waitForNavigation();

const navigationMenu = await page.$$('[data-testid="navigation-option"]');
expect(navigationMenu.length).toBeGreaterThan(1);

});

it('should allow the user to logout and redirect to the login page', async () => { await page.fill('#usernameInput', '<valid_username>'); await page.fill('#passwordInput', '<valid_password>'); await page.click('#loginButton'); await page.waitForNavigation();

await page.click('#logoutButton'); 
await page.waitForNavigation();

const pageTitle = await page.title();
expect(pageTitle).toContain('Login'); 

}); }); Some of the sample test cases we used for automation testing using Playwright Tool and the system was manually tested as well.