How to Rerun Last Failed Playwright TypeScript Tests

HOME

npx playwright test --project webkit

import { test, expect } from '@playwright/test';

test('has title', async ({ page, browserName }) => {
  await page.goto('https://opensource-demo.orangehrmlive.com/');

  console.log(`Running test on browser: ${browserName}`);  // Print the browser name

  await page.waitForTimeout(3000); // Wait for 3 seconds

  // Expect a title "to contain" a substring.
  await expect(page).toHaveTitle(/OrangeHRM/);
});


test('login', async ({ page, browserName }) => {

  const username = 'Admin';
  const password = 'admin123'

  await page.goto('https://opensource-demo.orangehrmlive.com/');

  console.log(`Running test on browser: ${browserName}`);  // Print the browser name

  // Fill in the username
   await page.fill('input[name="username"]', username);
  
   // Print the username
  console.log(`Logging in with username: ${username}`);

  // Fill in the password
    await page.fill('input[name="password"]', password);

  // Print the password
  console.log(`Logging in with password: ${password}`);

  // Click the login button - Use XPath to locate and click the login button
  const loginButton = page.locator('//button[@type="submit" and contains(@class, "orangehrm-login-button")]');
  await loginButton.click();

  // Check if the page contains text Dashboard - Locate the element using XPath
  const dashboardElement = await page.locator('//h6[contains(@class, "oxd-topbar-header-breadcrumb-module")]');

  // Get the text content from the element
  const dashboardText = await dashboardElement.textContent();
  
  // Print the text
  console.log(`Dashboard text: ${dashboardText}`);
  
  expect(dashboardText).toContain('Dashboard1');
});

npx playwright test --last-failed

Leave a comment