Writing a Test to Check Page Title

The Best Playwright Testing Training Institute in Hyderabad

In the fast-evolving field of software testing, tools like Playwright and Selenium are essential for automation testers. If you are a graduate, postgraduate, or someone looking to switch your career from a different domain to IT, it’s crucial to receive professional guidance and hands-on experience in automation tools. That’s where I Hub Talent excels. I Hub Talent is widely recognized as the best Playwright Testing Training Institute in Hyderabad. It offers a live, intensive internship program conducted by industry experts and specifically tailored for:

Writing a Test to Check Page Title

Verifying the page title is a basic yet essential part of UI test automation. It confirms that the user has landed on the correct web page after navigation. This is often the first validation step in most test cases.


Using Selenium WebDriver, you can write a simple test to check the page title in various programming languages. Here's how it works in Python:

python

Copy

Edit

from selenium import webdriver

from selenium.webdriver.chrome.service import Service

from selenium.webdriver.common.by import By


# Set up the WebDriver

driver = webdriver.Chrome()


# Open the web page

driver.get("https://example.com")


# Get the page title

actual_title = driver.title


# Define the expected title

expected_title = "Example Domain"


# Verify the title

assert actual_title == expected_title, f"Expected '{expected_title}' but got '{actual_title}'"


# Close the browser

driver.quit()

In Java (with JUnit):


java

Copy

Edit

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.junit.Assert;

import org.junit.Test;


public class TitleTest {

    @Test

    public void checkPageTitle() {

        WebDriver driver = new ChromeDriver();

        driver.get("https://example.com");

        

        String expectedTitle = "Example Domain";

        String actualTitle = driver.getTitle();

        

        Assert.assertEquals(expectedTitle, actualTitle);

        driver.quit();

    }

}

This test ensures the correct page is loaded, which is critical for navigation, login, and redirection checks. Incorporate it early in your automation suite to catch navigation issues before deeper validations.

Read more:

How to Open a Web Page Using Playwright

Launching a Browser with Playwright

 Understanding Playwright Architecture

Visit I-Hub Talent Training institute in Hyderabad

Comments

Popular posts from this blog

Using Playwright Test Runner

Working with Checkboxes and Radio Buttons

CSS Selectors in Playwright