Have a question?
Message sent Close
View Categories

Handle Browser Navigation

πŸ“„
BrowserNavigation.spec.ts
import { test, expect } from '@playwright/test';

test('Handle Browser Navigation', async ({ page }) => {
  
  // Step 1: Navigate to first page
  await page.goto('https://vinothqaacademy.com/demo-site/');
  
  // Step 2: Navigate to another page
  await page.goto('https://vinothqaacademy.com/');
  
  // Step 3: Go back to the previous page
  await page.goBack();
  await expect(page).toHaveURL('https://vinothqaacademy.com/demo-site/'); // Assertion
  
  // Step 4: Go forward to the next page
  await page.goForward();
  await expect(page).toHaveURL('https://vinothqaacademy.com/'); // Assertion
  
  // Step 5: Reload the current page
  await page.reload();
  await expect(page).toHaveTitle(/Vinoth QA Academy/); // Regex validation for flexibility
});