Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

playwright-typescript-playwright-test

> 数据库
Open source

This is a boilerplate/template for a Playwright-Typescript framework for web UI, API, mobile emulation, DB, and visual testing. Docker image, SonarQube, Lighth

716 stars0 likes0 views
WebsiteGitHub

About

This is a boilerplate/template for a Playwright-Typescript framework for web UI, API, mobile emulation, DB, and visual testing. Docker image, SonarQube, Lighth

Table of Contents

          About the Project

Youtube Video Tutorial

Built With

          Getting Started

Prerequisites

Installation

Usage

Reports

SonarQube

Docker

Lighthouse

About the Project

Playwright Demo - This project is based on Microsoft Playwright which enables reliable end-to-end testing for modern web apps.

Top Features:

  • Easy to Configure.
  • Auto-waits for all the relevant checks to pass and only then performs the requested action.
  • Records videos for Test Cases.
  • Records the test script and every action on the target page is turned into generated script.
  • Generates trace file, which gives in-depth details of Test Case execution.
  • Execution of test case is faster when compared with other competitive framework in market.
  • Supports Headful/Headless mode execution for Firefox/Webkit/Google Chrome/Chromium/MS Edge on Windows/Linux/Mac machines.
  • It supports API testing (From Playwright version 1.16 onwards)
  • It can be used to simulate browser behaviour on mobile devices, and supports over 100+ devices.
  • It has ability to produce and visually compare screenshots.
  • To slow down execution slowMo option is available.
  • Supports 'download' event monitoring, so there is no need for user to actually wait for downloads to finish.
  • Supports Serial and Parallel execution.
  • Allure/HTML/Ortoni HTML Reports are generated after execution with an option to capture screenshot/video/trace file on failure.
  • Nonetheless Support from Microsoft so FREQUENT RELEASES and turn arounf time for any queries is 48 hours.

Bonus:

  • Supports PostgresSQL using 'pg' module.
  • Supports Excel File Read/Write using 'excel-js' module.
  • Converts HTML Reports to Zip format which can shared across.
  • Extracts Text from PDF files.
  • Shows Page performance using Lighthouse Library.
  • Docker Image is created with node:20.5.1-bookworm-slim
  • Configured GitHub Actions to get triggered on pull/push actions
  • Slack Notifications with html-report url once Github Actions is completed.

Youtube Video Tutorial

Built With

  • Playwright
  • Typescript
  • node-postgres
  • excel-js
  • ESLint
  • SonarQube
  • Lighthouse
  • pdfjs-dist-es5
  • [ortoni-report] (https://github.com/ortoniKC/ortoni-report)

Getting Started

Prerequisites

The following software are required:

  • nodejs : Download and Install Node JS from
    https://nodejs.org/en/download/
    
  • Install Java 8 or above, Allure Reports require Java 8 or higher.
  • Install Java 11 instead of Java 8 if you intend to use Sonar Qube.
  • allure commandline : Install allure command line for generating Allure Reports using
    npm ci -g allure-commandline
    
  • If you wish to include SonarQube follow the below steps:
    • Install Java 11 and add java path to "PATH" environment variable.
    • Download SonarQube community server from the below url and unzip it to desired location.
    https://www.sonarqube.org/downloads/
    
    • Download Sonar Scanner for your desired OS (Windows in my case) from below location and unzip it to desired location. Then navigate to bin location once unzipped and provide the path to "PATH" environment variable.
    https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
    

Installation

  1. Clone the repo using below URL
https://github.com/akshayp7/playwright-typescipt-playwright-test.git
  1. Navigate to folder and install npm packages using:
npm install
  1. For first time installation run below command to download required browsers
npx playwright install

Usage

  1. For Browser Configuration, change required parameters in playwright.config.ts.
  2. For execution entire test suite on all available browsers simultaneously execute below command where "ENV" can be "qa" or "dev", Test Cases are present in "tests" folder. You must provide the ENV variable:

Windows CMD:

set ENV=qa && npm run test

Windows PowerShell:

$env:ENV="qa"; npm run test

Mac/Linux/WSL:

ENV=qa npm run test
  1. For executing single test case on Chrome browser execute the below command, you can change the browser for execution e.g. if you want to run test cases on Firefox, you can change --project=Firefox against test:single in package.json, just make sure the browser name given matches the name given in playwright.config.ts.

Windows CMD:

set ENV=qa && npm run test:single

Windows PowerShell:

$env:ENV="qa"; npm run test:single

Mac/Linux/WSL:

ENV=qa npm run test:single
  1. For executing test cases in parallel, provide a suitable tag @SmokeTest at the start of your test case name, then in package.json against test:parallel give the tag value and execute :

Windows CMD:

set ENV=qa && npm run test:parallel

Windows PowerShell:

$env:ENV="qa"; npm run test:parallel

Mac/Linux/WSL:

ENV=qa npm run test:parallel
  1. For executing test cases in sequence, provide a suitable tag @SmokeTest at the start of your test case name, then in package.json against test:serial give the tag value and execute, workers parameter correspond to test cases you want to execute simultaneously e.g. --workers=3, executes 3 test cases simultaneously :

Windows CMD:

set ENV=qa && npm run test:serial

Windows PowerShell:

$env:ENV="qa"; npm run test:serial

Mac/Linux/WSL:

ENV=qa npm run test:serial
  1. For executing API test cases, please provide "ENV" value as "qaApi" or "devApi". ReqRes API tests also require REQRES_API_KEY, because ReqRes expects the x-api-key request header:

Windows CMD:

set "ENV=qaApi" && set "REQRES_API_KEY=your_reqres_key" && npm run test:api

Windows PowerShell:

$env:ENV="qaApi"; $env:REQRES_API_KEY="your_reqres_key"; npm run test:api

Mac/Linux/WSL:

ENV=qaApi REQRES_API_KEY=your_reqres_key npm run test:api
  1. For recording test scripts :
npm run test:record
  1. To produce and visually compare screenshots execute below command. On first execution reference screenshot will be generated for comparision with subsequent runs.

Windows CMD:

set ENV=qa && npm run test:visual

Windows PowerShell:

$env:ENV="qa"; npm run test:visual

Mac/Linux/WSL:

ENV=qa npm run test:visual
  1. For emulating test cases on any device, in playwright.config.ts, under device section provide desired device name and execute :

Windows CMD:

set ENV=qa && npm run test:device

Windows PowerShell:

$env:ENV="qa"; npm run test:device

Mac/Linux/WSL:

ENV=qa npm run test:device
  1. For Allure Report generation execute :
npm run allureReport
  1. For HTML Report generation execute below command , single static HTML report(index.html) which can be sent via email is generated in "html-report" folder:
  2. For debugging test cases add debug points, the press CNTRL+SHIFT+P and type "debug:debug npm script", on the edit box select desired script.
  3. Screenshots, Videos and Trace files will be generated in test-results folder.
  4. To change your username go to testConfig.ts and provide value against username
  5. To change password, go to lib/WebActions in decipherPassword() uncomment ENCRYPT code block and replace password with your password, execute the test case, Encrypted password will be printed on your console . Copy Encrypted password in testConfig.ts against password field. You can comment Encrypt bloack ater this.
  6. For executing Postgres DB test case, navigate to testConfig.ts and provide values for dbUsername, dbPassword, dbServerName, dbPort, dbName. Refer to tests/DB.test.ts for connecting to DB and Firing a Query.
  7. For viewing trace files, go to folder where trace.zip is generated and execute :
npx playwright show-trace trace.zip
  1. You can change the Logging Message at Test Case/Test Step Level in CustomReporterConfig.ts file
  2. In tsconfig.json file in paths section we can re-assign the long path imports like '../../' to a variable which starts with '@' and then we can use it to shorten our import statements in respective file. In the below example wherever '../../pageFactory/pageRepository/' import statement is used we can replace it with '@pages'
"@pages/*":["pageFactory/pageRepository/*"]
  1. Network Replay : For using this featre in Playwright we use HAR file. HAR (HTTP Archive) is a file format used by several HTTP session tools to export the captured data. This can be highly useful in troubleshooting complex issues by obtaining additional information about the network requests that are generated in the browser while an issue occurs.

To generate HAR file navigate to HAR.test.ts inside functional folder, in that use the below line

await page.routeFromHAR('har/personalInfo.har',{update:true});

where update:true means to record a new har file and store it in the location provided by first parameter har/personalInfo.har, this generates and links all the required subfiles for personalInfor.har and stores it in har directory

Once HAR file is recorded comment the line await page.routeFromHAR('har/personalInfo.har',{update:true}); and uncomment below line

await page.routeFromHAR('har/personalInfo.har',{update:false});

where update:false means to use the existing HAR from from the path given in first paraeter har/personalInfo.har, to see this in action you can turn off your internet and run the script, complete webpage is mocked up along with assertions on the browser of your choice this is done using the Network Replay feature and by using our recorded HAR file. We can use this feature when webpage is down for some reason and we want to test some scenarios.

  1. Logging is implemented in CustomReporterConfig.ts using winston logger.

First we have to create a logger object using winston.createLogger and then provid the configuration you need. First argument is "level" for which i have provided value as "info", in winston logger every logging level is provided with a numeric value, for info the numeric value is 2, so if we provide level as info then all the logs which are equal to or less than info level will be displayed. In our case logs with error(0) and warn(1) wil also be logged. For more info on logging refer below link https://github.com/winstonjs/winston#logging

Second we have to provide format for the log file generate I have provided format as json using winston.format.json() because JSON is widely used. There are various levels like printf, simple, colorize which you can refer in below link https://github.com/winstonjs/logform#formats

Third part is transports which defines where the log file will be written. I have provided the location as logs/info.log in my case

Once logger object is created I have provided logger.add(console); which instructs logger to write the log files in console as well.

Once logger object is created you can use this instead of console.log in your framework and these logs will be written both in your console and log file.

  1. UI mode in Playwright is lets you explore, run and debug tests, it comes with a built-in watch mode. I

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptallureallure-reportapitestingautomation-testing

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库