How to Run Only Smoke Tests in Playwright: Step-by-Step Guide


Imagine that your development team has released a new version of an e-commerce website.

Before allowing users to access the application, you need to check whether the most important features are working.

You want to verify:

  • Can users open the website?

  • Can users log in?

  • Can users search for products?

  • Can users add products to the cart?

  • Can users complete the checkout process?

You do not need to execute every automated test immediately.

You need to execute a small group of important tests that quickly checks whether the application is working.

This is called smoke testing.

Playwright provides simple ways to organise and execute smoke tests using test tags and the --grep command.

In this guide, you will learn how to create smoke tests, run only smoke tests, exclude unwanted tests, configure smoke execution, and use smoke tests in real-world projects.

What Is Smoke Testing?

Smoke testing is a basic level of software testing performed to check whether the most important features of an application are working.

Think of it like checking a vehicle before starting a long journey.

Before driving, you check:

  • Whether the engine starts.

  • Whether the brakes work.

  • Whether the lights are functioning.

You do not perform every possible mechanical inspection before moving the vehicle.

Similarly, smoke testing checks the most important application functions before spending time on detailed testing.

Example of Smoke Testing in an E-Commerce Application

Imagine an online shopping website.

A basic smoke test suite may contain:

Test Scenario

Expected Result

Open homepage

Homepage loads successfully

User login

User reaches the dashboard

Product search

Relevant products are displayed

Add to cart

Product appears in the cart

Checkout

Checkout page opens

If these important scenarios fail, the team should investigate before proceeding with deeper testing.

Why Should You Run Only Smoke Tests in Playwright?

Imagine your project contains 500 automated test cases.

Running all 500 tests after every small deployment may take considerable time.

But suppose you have selected 15 important smoke tests.

You can execute those 15 tests first to receive faster feedback.

Here are the main benefits.

1. Faster Feedback

Smoke tests help identify major application problems early.

If the login page is broken, the team can identify the issue before running hundreds of unrelated tests.

2. Early Detection of Deployment Issues

A successful deployment does not always mean the application is working correctly.

Smoke tests help verify important functionality after deployment.

3. Better CI/CD Automation

You can configure smoke tests to execute automatically after a new build is deployed to a testing environment.

4. Reduced Unnecessary Test Execution

You can select a small group of important scenarios instead of executing the complete regression suite every time.

5. Better Release Confidence

A passing smoke suite gives the team an initial indication that important application flows are working.

However, smoke testing does not replace complete regression testing.

Step 1: Create a Playwright Project

If you already have a Playwright project, skip this step.

Otherwise, create a new project using:

npm init playwright@latest

Follow the installation instructions.

After installation, your project may look similar to this:

playwright-project/

│

├── tests/

│   ├── example.spec.ts

│

├── playwright.config.ts

├── package.json

└── package-lock.json

The tests directory contains your automated test files.

The playwright.config.ts file contains the configuration for your Playwright project.

Step 2: Create a Smoke Test

Create a file named:

tests/smoke.spec.ts

Add the following code:

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


test('Verify homepage loads successfully @smoke', async ({ page }) => {


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


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


});

Let's understand the code.

import { test, expect }

Imports the Playwright test runner and assertion functions.

test()

Creates an automated test case.

page.goto()

Opens the given URL in the browser.

expect()

Checks whether the actual result matches the expected result.

@smoke

Labels the test as a smoke test.

This is a simple example. In a real project, replace the example URL and expected title with the actual application details.

Step 3: Create Multiple Smoke Tests

A useful smoke suite should verify more than just the homepage.

For example, create the following test file:

tests/ecommerce-smoke.spec.ts

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


test('Verify homepage loads @smoke', async ({ page }) => {


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


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


});


test('Verify login page opens @smoke', async ({ page }) => {


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


  await expect(page).toHaveURL(/login/);


});


test('Verify product page opens @smoke', async ({ page }) => {


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


  await expect(page).toHaveURL(/products/);


});

Now your project contains three smoke tests.

In a real application, use valid test URLs, test accounts, and meaningful assertions.

Step 4: Run Only Smoke Tests Using --grep

This is the most important step.

Open your terminal inside the Playwright project.

Execute:

npx playwright test --grep @smoke

What happens?

Playwright searches the collected test information for the @smoke pattern.

It then executes matching tests.

For example:

Test Name

Tag

Execution

Homepage loads

@smoke

Runs

Login page opens

@smoke

Runs

Product page opens

@smoke

Runs

Payment validation

@regression

Skipped

Order history

@regression

Skipped

This allows you to run only the selected smoke tests.

Step 5: Run Smoke Tests From a Specific File

Sometimes you may want to execute smoke tests from one particular test file.

For example:

npx playwright test tests/ecommerce-smoke.spec.ts --grep @smoke

This command:

  1. Selects the specified test file.

  2. Searches for tests matching @smoke.

  3. Executes the matching tests.

This is useful when your project contains multiple test files.

Step 6: Run Smoke Tests in a Specific Browser

Playwright supports multiple browsers.

You can execute your smoke tests in Chromium using:

npx playwright test --grep @smoke --project=chromium

Similarly, if your configuration contains Firefox and WebKit projects, you can run:

npx playwright test --grep @smoke --project=firefox


npx playwright test --grep @smoke --project=webkit

The project names must match the names configured in playwright.config.ts.

This helps you verify important application functionality in different browsers.

Step 7: Configure Smoke Test Execution in Playwright

You can also configure your Playwright project to execute smoke tests by default.

Open:

playwright.config.ts

Add:

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


export default defineConfig({


  testDir: './tests',


  grep: /@smoke/,


  timeout: 30000,


  retries: 1,


  reporter: 'html'


});

Now the default test run selects tests matching @smoke.

Execute:

npx playwright test

Playwright will apply the configured filter.

Important: This configuration restricts the default run to smoke tests. If you need a full regression run, remove the global filter or use a separate configuration designed for regression execution.

For teams that regularly switch between test groups, command-line filtering is often more flexible.

Step 8: Exclude Smoke Tests When Running Regression Tests

Sometimes you want to execute all tests except smoke tests.

You can use:

npx playwright test --grep-invert @smoke

This excludes tests matching the smoke tag.

However, in a well-organised project, it is usually better to give regression tests their own @regression tag.

Then execute:

npx playwright test --grep @regression

This gives you more control over test selection.

Step 9: Run Smoke Tests After Deployment

Imagine your team deploys a new application build to a testing environment.

After deployment, you want Playwright to verify the most important features.

A simple CI/CD command is:

npx playwright test --grep @smoke

You can add this command as a pipeline step after the deployment step.

A typical workflow looks like this:

Developer pushes code

        |

        v

Application build starts

        |

        v

Application is deployed

        |

        v

Playwright smoke tests execute

        |

        v

Results are generated

        |

        v

Team reviews the result

If smoke tests fail, the team should investigate the failure before treating the deployment as successful.

The exact pipeline configuration depends on the CI/CD platform being used.

Real-Time Example: Smoke Testing a Login Flow

Consider a banking application.

A login smoke test should verify that a user can access the application with valid test credentials.

Example:

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


test('Verify user can log in @smoke', async ({ page }) => {


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


  await page.getByLabel('Username').fill('testuser');


  await page.getByLabel('Password').fill('TestPassword123');


  await page.getByRole('button', { name: 'Login' }).click();


  await expect(page.getByText('Welcome')).toBeVisible();


});

This test checks the main login flow.

In a real banking project:

  • Use approved test accounts.

  • Do not hardcode production credentials.

  • Keep sensitive test data in environment variables or a secure secret store.

  • Make sure the expected dashboard state is clearly defined.

A smoke test should be simple, stable, and focused on a critical user journey.

How to Check Smoke Test Results

After executing smoke tests, Playwright generates a test result.

If you configure the HTML reporter, open the report using:

npx playwright show-report

The report helps you understand:

  • Which tests passed.

  • Which tests failed.

  • Which tests were skipped.

  • How long each test took.

  • Where failures occurred.

You can use screenshots, traces, and other configured test artifacts to investigate failures.

Common Mistakes When Running Smoke Tests

1. Adding Every Test to the Smoke Suite

If every test is marked as smoke, the smoke suite becomes too large.

Solution: Include only important application flows that provide fast feedback.

2. Using Unstable Test Data

A smoke test may fail because another test changed the account or data it depends on.

Solution: Use controlled test data and avoid unnecessary dependencies between tests.

3. Checking Only Whether a Page Opens

A page may open successfully while its main functionality is broken.

Solution: Add meaningful assertions for the important user action.

For example, after login, verify that the dashboard is visible.

4. Ignoring Smoke Test Failures

A failed smoke test should not be ignored simply because the application deployment completed.

Solution: Investigate whether the failure is caused by an application defect, environment problem, or test issue.

5. Depending on Smoke Tests Alone

Smoke tests provide an initial health check, not complete application coverage.

Solution: Combine smoke testing with regression, integration, and other relevant testing activities.

Best Practices for Running Smoke Tests in Playwright

  • Keep smoke tests small and focused.

  • Use the @smoke tag consistently.

  • Prioritise important user journeys.

  • Avoid unnecessary test dependencies.

  • Use reliable test data.

  • Add meaningful assertions.

  • Run smoke tests after deployment.

  • Review failed tests using reports and traces.

  • Keep regression tests separate.

  • Review the smoke suite whenever application functionality changes.

Frequently Asked Questions

1. How do I run only smoke tests in Playwright?

Use:

npx playwright test --grep @smoke

This executes tests matching the @smoke pattern.

2. What is the difference between smoke testing and regression testing?

Smoke testing checks whether the most important application features work.

Regression testing checks whether existing functionality continues to work after application changes.

3. Can I run smoke tests in Chromium only?

Yes.

npx playwright test --grep @smoke --project=chromium

Make sure chromium is the correct project name in your configuration.

4. Can smoke tests run automatically after deployment?

Yes. Add the Playwright smoke test command as a pipeline step after deploying the application to the target environment.

5. How many tests should a smoke suite contain?

There is no fixed number. Include the smallest set of reliable tests that checks the application's most important functionality.

6. Does a passing smoke test mean the application has no bugs?

No. A passing smoke suite only indicates that the selected critical scenarios passed. Other defects may still exist.

7. Can I run smoke tests from a specific file?

Yes.

npx playwright test tests/ecommerce-smoke.spec.ts --grep @smoke

Conclusion

Running only smoke tests in Playwright helps teams identify major application problems quickly.

By using tags and the --grep command, you can execute important test scenarios without running the complete automation suite.

Start by identifying your application's most important user journeys. Add the @smoke tag to those tests and execute them after every important deployment.

To develop practical skills in test tagging, smoke testing, browser automation, debugging, and real-world automation workflows, explore the Playwright Training in Hyderabad offered by PlaywrightMasters.

Learn how to build and execute automation tests that solve real project problems.



Comments

Popular posts from this blog

How to Test REST APIs Using Playwright

Playwright Multiple Tabs and Windows Explained: A Practical Guide