Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothrwins@gmail.com
Vinoth Tech Solutions
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • E-Commerce Demo Application
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • E-Commerce Demo Application
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I

Playwright

  • Handle Browser Navigation
  • Playwright Core Concepts
  • First Playwright Program
  • Step-by-Step Node.js Installation on Windows
  • Step-by-Step VS Code Installation on Windows
  • Step-by-Step Playwright Installation on Windows
  • Playwright VS Code extension Installation and Execution
  • Playwright Folder Structure
View Categories
  • Home
  • Tutorials
  • Playwright
  • Playwright
  • Handle Browser Navigation

Handle Browser Navigation

Handle Browser Navigation

In this example, we will learn how to handle back, forward, and reload browser actions using Playwright.

Code Example

📄
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
});

Explanation

- import { test } from '@playwright/test' → imports Playwright’s built-in test runner.

– test('Launch Application', async ({ page }) => { ... }) → defines a test case with the name Launch Application.

– page.goto(URL) → opens the browser and navigates to the given application URL.

– page.waitForTimeout(3000) → makes the browser wait for 3 seconds (just for demo purposes).

– Browser context and page auto-close after the test run, no need to close manually.

Behind the Scenes

– Playwright automatically launches a browser context for each test.

– All Playwright functions are asynchronous, which is why we use async/await to run steps in order.

– waitForTimeout() is used here only for demo. In real automation, prefer auto-waiting or waitForSelector() for stability.

What You’ll See

– A browser window opens.

– The demo site loads.

– The page stays open for 3 seconds.

– The browser closes automatically.

Try It Yourself

– Change the URL to https://playwright.dev/ and rerun the test.

– Modify the timeout value (e.g., 1000 ms = 1 second).

– Remove waitForTimeout() and notice how quickly the test finishes

Playwright Tutorials
What are your Feelings

Share This Article :

  • Facebook
  • X
  • LinkedIn
Playwright Core Concepts
© 2018 – 2025 Vinoth Tech Solutions Ltd (UK), Reg. No: 16489105