This is a boilerplate/template for a Playwright-Typescript framework for web UI, API, mobile emulation, DB, and visual testing. Docker image, SonarQube, Lighth
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
Playwright Demo - This project is based on Microsoft Playwright which enables reliable end-to-end testing for modern web apps.
Top Features:
Bonus:
The following software are required:
https://nodejs.org/en/download/
npm ci -g allure-commandline
https://www.sonarqube.org/downloads/
https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
https://github.com/akshayp7/playwright-typescipt-playwright-test.git
npm install
npx playwright install
playwright.config.ts.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
--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
@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
@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
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
npm run test:record
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
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
npm run allureReport
testConfig.ts and provide value against usernamelib/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.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.trace.zip is generated and execute :npx playwright show-trace trace.zip
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/*"]
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.
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.
No open issues yet, or sync has not completed.