Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothtechsolutions@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
  • Python JS Online Compiler
  • 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
  • Python JS Online Compiler

Playwright

  • 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
  • Playwright Core Concepts
  • First Playwright Program
  • Validate Page Title and URL
  • Handle Browser Navigation
  • Playwright Built-in Locators
  • Locators in Playwright CSS Selector vs XPath
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

page.goto(url) β†’ navigates to a given URL.

page.goBack() β†’ simulates clicking the browser Back button.

page.goForward() β†’ simulates clicking the browser Forward button.

page.reload() β†’ reloads the current page.

Assertions (toHaveURL, toHaveTitle) β†’ verify correct navigation.

Behind the Scenes

  • When you run page.goto(), Playwright waits for the page to finish loading before moving forward.
  • When using page.goBack() and page.goForward(), Playwright works with the browser’s history stack β€” exactly like when you press back/forward in Chrome/Firefox.
  • page.reload() clears the page state and reloads everything from the server.
  • The expect assertions confirm that navigation was successful and correct.

What You’ll See

1. Browser opens and loads πŸ‘‰ https://vinothqaacademy.com/demo-site/

2. Browser navigates to πŸ‘‰ https://vinothqaacademy.com/

3. Browser goes back πŸ‘‰ returns to demo-site page

Test asserts URL matches the expected demo-site URL.

      4. Browser goes forward πŸ‘‰ returns to vinothqaacademy.com homepage

      Test asserts URL matches the homepage.

        5. Browser reloads the page

        Page refreshes and the title is validated with regex (Vinoth QA Academy).

          Playwright Tutorials
          What are your Feelings

          Share This Article :

          • Facebook
          • X
          • LinkedIn
          Validate Page Title and URLPlaywright Built-in Locators
          Β© 2018 – 2025 V-Tech Solutions Ltd (UK), Reg. No: 16489105