Using Playwright Test Runner

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: 

What is Playwright Test Runner?

Playwright comes with its own built-in test runner (@playwright/test) that is designed for end-to-end testing.

It provides:

Parallel execution of tests

Cross-browser testing (Chromium, Firefox, WebKit)

Auto-waiting for elements

Screenshots & video recording

Test fixtures & hooks (beforeEach, afterEach, etc.)

Assertions (expect API)

1. Install Playwright Test Runner

# Install Playwright with test runner

npm init playwright@latest

This command sets up:

Playwright test runner

Browser binaries

Example tests

2. Writing a Simple Test

Create a file: example.spec.ts

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

test('homepage has title', async ({ page }) => {

  // Navigate to page

  await page.goto('https://playwright.dev/');

  // Assertion

  await expect(page).toHaveTitle(/Playwright/);

});

3. Running Tests

Run all tests:

npx playwright test

Run a specific test file:

npx playwright test example.spec.ts

Run in headed mode (see the browser):

npx playwright test --headed

Run in debug mode:

npx playwright test --debug

4. Playwright Test Fixtures

Playwright provides built-in fixtures like page, browser, context.

Example with beforeEach:

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

test.beforeEach(async ({ page }) => {

  await page.goto('https://example.com');

});

test('check title', async ({ page }) => {

  await expect(page).toHaveTitle('Example Domain');

});

5. Parallel & Cross-Browser Testing

playwright.config.ts can be used to configure browsers and parallel execution:

import { defineConfig } from '@playwright/test';

export default defineConfig({

  projects: [

    { name: 'chromium', use: { browserName: 'chromium' } },

    { name: 'firefox', use: { browserName: 'firefox' } },

    { name: 'webkit', use: { browserName: 'webkit' } },

  ],

  reporter: 'html',

});

Run:

npx playwright test --project=firefox

6. Generating Reports

Playwright has built-in reporters:

npx playwright test --reporter=html

Read more:

Headless vs Headed Browsers in Playwright

Testing Links and Navigation

Automating Form Submission

Simulating Keyboard Events

What browsers does Playwright support?

Visit I-Hub Talent Training institute in Hyderabad

Comments

Popular posts from this blog

Working with Checkboxes and Radio Buttons

Taking Screenshots with Playwright

Extracting Text from Web Pages