Skip to content

JarDeVSon/PlaywrightTypeScript

Repository files navigation

Playwright Framework with TypeScript/Nodejs

Sample project to demonstrate Web & API tests written with Playwright with TypeScript running on GitHub Actions.

Pre-requirements

To clone and run this project, you will need:

  • Git(I've used version 2.34.1 while writing this doc)
  • Node.js (I've used version v18.15.0 while writing this doc)
  • Visual Studio Code(I've used version Stable Build while writing this doc)
  • Playwright Extension(Install the official extension in the Visual Studio Code)

Installation

Install the Following Libraries using the command Line:

  • npm init playwright@latest

  • Choose between TypeScript or JavaScript (default is TypeScript)

  • Name of your Tests folder (default is tests or e2e if you already have a tests folder in your project)

  • Add a GitHub Actions workflow to easily run tests on CI

  • Install Playwright browsers (default is true)

Install system dependencies, browsers, and OS dependencies with a single command:

  • npx playwright install --with-deps

Project Structure: Page Object Model and Single Responsability Principle Pattern:

And check out the following files:

  • .\tests\example.spec.ts - Example end-to-end test
  • .\tests-examples\demo-todo-app.spec.ts - Demo Todo App end-to-end tests
  • .\playwright.config.ts - Playwright Test configuration

In my case, check out the following files:

  • .\tests\api_test.spec.ts - API test
  • .\tests\web_test.spec.ts - Web test using page objects model pattern (POM), check it out below:
Package Responsibility
fixtures responsible for managing test data
locators responsible for identifying web elements
pages responsible for page actions (navigation, (fills, types), clicks, etc.)
tests responsible for executing the test suite

Running the tests

Inside that directory, you can run several commands:

npx playwright test
    Runs the end-to-end tests.

npx playwright test --ui
    Starts the interactive UI mode.

npx playwright test --project=chromium
    Runs the tests only on Desktop Chrome.

npx playwright test example
    Runs the tests in a specific file.

npx playwright test --debug
    Runs the tests in debug mode.

npx playwright codegen
    Auto generate tests with Codegen.
We suggest that you begin by typing:
npx playwright test

Show Status Report

To see the status report, you can run the command:

npx playwright show-report

Made with ❤️ by Jardeson Santos. Meu Linkedin.

About

Playwright Web & API Automation in Nodejs/TypeScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published