tm-playwright-framework
v2.2.0
Published
Playwright Cucumber TS framework - The easiest way to learn
Readme
Playwright (TS binding) + Cucumber (BDD)
Cucumber is a popular behavior-driven development (BDD) tool that allows developers and stakeholders to collaborate on defining and testing application requirements in a human-readable format. TypeScript is a powerful superset of JavaScript that adds optional static typing, making it easier to catch errors before runtime. By combining these two tools, we can create more reliable and maintainable tests.
Features
- Awesome report with screenshots, videos & logs
- Execute tests on multiple environments
- Parallel execution
- Rerun only failed features
- Retry failed tests on CI
- Github Actions integrated with downloadable report
- Page object model
Sample report
Project structure
- app -> Contains all the Cucumber features & Step Definitions and Playwriht Tests
- dist -> Contains all framework code output files
- tm-playwright-framework/dist -> Contains all framework code source files
- cucumber-results -> Contains all the Cucumber reports related file
- playwright-test-results -> Contains all the Playwright reports related file
Reports
- Mutilple Cucumber Report
- Default Cucumber report
- Logs
- Screenshots of failure
- Test videos of failure
- Trace of failure
Get Started
Setup:
- Clone or download the project
- Extract and open in the VS-Code
npm ito install the dependenciesnpx playwright installto install the browsersnpm run ccs_cucumber_testto execute the Cucumber tests ornpm run ccs_playwright_testto execute te Playwriht tests- To run a particular test pass FEATURES as a command line arument with required feature
- Use TAGS command line parameter to run a specific or collection of specs for Cucumber Tests
Browser launch environment variables
MAXIMIZED_BROWSER=true— launches supported browsers in maximized mode.DISABLE_WEB_AUTH=true— adds Chrome/Chromium/Firefox flags to disable WebAuthentication during the run.CHROME_ARGUMENTS=[]— additional Chrome/Chromium launch arguments. e.g.CHROME_ARGUMENTS=["--disable-features=WebAuthn","--disable-webauthn"]
These values are configured in app/env/.env.prod and are used by tm-playwright-framework/dist/browser/browserManager.ts.
Folder structure - May not be up to Date until folder structure is finalized.
.vscode-> Settings for feature and step definition mappingapp-> Folder for application related code and filesapp\env-> Multiple environments are handledapp\pom\objects-> Page Object Model classes to have Object Locatorsapp\pom\scripts-> Page Object Model classes to have custom methods related to the pagepom.ts-> Global Objects and Scriptsapp\test-data-> Folder to have test data and test upload filesapp\test\features\<folder>\-> write your features here (format: featureName.feature. You can have folders based on need)app\test\steps\<folder>\-> Step definitions can be under the Feature folder here (format: featureName.step.ts)app\test\playwright\-> Playwright tests can be under this folderdist-> Compiled application code files generated here. No need to update/change anything herenode_modules-> Dependency libraries are installed heretm-playwright-framework-> Framework code files. Development or changes should be made herecucumber-results-> Folder to have execution reports and logs of Cucumber Testscucumber-results\default-report-> Cucumber default reportcucumber-results\myltiple-cuucmber-report-> Multiple Cucumber reportcucumber-results\myltiple-cuucmber-report\assets-> CSS and font files for Multiple Cucumber reportplaywright-test-results\-> Folder to have execution reports of Playwright Testspackage.json-> Contains all the dependenciestsconfig.json-> TypeScript configurations
Core Framework
actions-> Keyboard, Mouse and other user Action's on elementscustom-> Custom action like Alert handling and etc.dropdown-> Dropdown actionselement-> Methods depends on Elements e.g. Wait till disappearance of some elementkeyboard-> Keyboard actionsmouse-> Mouse actionscheckbox-> Check box actionsdropdown-> Dropdown actionsradiobutton-> Option button actionsfileupload-> File Upload actions
assertion-> Collection of Assertionassertion-> Text and various Assertionsemail-> Read email and assert email content
browser-> Manage browser invoke and teardownbrowsermanager-> Manage browser items
config-> Configuration filescucumber.js-> Cucumber profile configuration for test runner
helper-> Cross ENV and DotEnv configurationsenv.ts-> Environment binding for Env variablestypes-> Type definition for Env variables
hooks-> Cucumber hooks- `hooks' -> Cucumber hooks implementation
- `pageFixture' -> Fixture and Page setup
report-> Report and logger configurations- 'custom_logger` -> Custom method for log generation
init.ts-> Report initializationlogger.ts-> Winston loggerreport.ts-> Cucumber Report Configuration
runner-> Runner configurationscucumber-runner.ts-> Receives command line arguments and execute Cucumber Tests as definedplyawright-runner.ts-> Receives command line arguments and execute Playwright Tests as defined
global.ts-> Global access variables and class members and scripts10.
Running Cucumber Test through Terminal (Command Prompt)
Syntax: npm run ccs_cucumber_test -- --ENV={Env} [--FEATURES={Feature}] [--TAGS={tags}] [--BROWSER={Chrome|Firefox|Webkit}] [--HEADLESS={true|false}] [--CLIENT={client}] [--REPORT_PATH={Report_Path}] [PARALLEL_WORKER={PARALLEL_WORKER_Count}]
- ENV is mandatory (required) argument. Value can be any one of the following: dev, test, qa, stage, ct, uat, prod
- If no FEATURES are specified then it will run all features
- If no TAGS are specified then it will run all scenarios of applicable features irrespective of tag
- If no BROWSER is specified then default would be Chrome. Value can be only Chrome or Firefox or Webkit
- If HEADLESS parameter is not specified then default would be Headless as false
- If CLIENT parameter is not specified then it will be ignored
- If REPORT_PATH parameter is not specified then report will be generated at folder test-results/default-report. Otherwise Cucumber default report HTML and JSON files will b generated at the specified location
- If PARALLEL_WORKER parameter is not specified then default would be 1. If specified then given number of parallel execution will occur
- The following will not work as ENV variable is mandatory
npm run ccs_cucumber_test - To execute all of the features with PROD environment variables with Chrome
npm run ccs_cucumber_test -- --ENV=PROD - To execute all of the features with PROD environment variables with Chrome for a specific client
npm run ccs_cucumber_test -- --ENV=PROD --CLIENT=TransAmerica - To execute all of the features under loginPage folder with PROD environment variables with Chrome
npm run ccs_cucumber_test -- --ENV=PROD --FEATURES=app/test/features/loginPage - To execute all of the features under loginPage and booksPage folder with PROD environment variables with Chrome
npm run ccs_cucumber_test -- --ENV=PROD --FEATURES=app/test/features/loginPage,app/test/features/booksPage - To execute all of the features under loginPage folder which are tagged as @auth with PROD environment variables with Chrome
npm run ccs_cucumber_test -- --ENV=PROD --FEATURES=app/test/features/loginPage --TAGS="@auth" - To execute all of the features which are tagged as @auth with PROD environment variables with Chrome
npm run ccs_cucumber_test -- --ENV=PROD --TAGS="@auth" - To execute all of the features which are tagged as @auth or @add with PROD environment variables with Chrome
npm run ccs_cucumber_test -- --ENV=PROD --TAGS="@auth or @add" - To execute all of the features which are not tagged as @auth with PROD environment variables with Chrome
npm run ccs_cucumber_test -- --ENV=PROD --FEATURES=app/test/features/loginPage --TAGS="not @auth" - To execute all of the features with PROD environment variables with Firefox
npm run ccs_cucumber_test -- --ENV=PROD --BROWSER=Firefox - To execute all of the features with PROD environment variables with Webkit
npm run ccs_cucumber_test -- --ENV=PROD --BROWSER=Webkit - To execute all of the features with PROD environment variables with browser as Headless
npm run ccs_cucumber_test -- --ENV=PROD --BROWSER=Webkit --HEADLESS=true - To execute all of the features with PROD environment variables with browser as Headless and to generate the Report at downloads folder
npm run ccs_cucumber_test -- --ENV=PROD --BROWSER=Webkit --HEADLESS=true --REPORT_PATH=C:/users/Test/Downloads - To execute all of the features with PROD environment variables with browser as Headless in Parallel mode
npm run ccs_cucumber_test -- --ENV=PROD --BROWSER=Webkit --HEADLESS=true --PARALLEL_WORKER=2
TAGS can be passed in different ways
| Input Tag | Converted as |
| ------------------------- | --------------------------- |
| @HORIZON or @HORIZONSTG | @HORIZON or @HORIZONSTG |
| HORIZON or HORIZONSTG | @HORIZON or @HORIZONSTG |
| HORIZON and HORIZONSTG | @HORIZON and @HORIZONSTG |
| HORIZON, HORIZONSTG | @HORIZON or @HORIZONSTG |
| ORACLE and DB | @ORACLE and @DB |
| ANDROID | @ANDROID |
| not HORIZON | not @HORIZON |
Running Playwright Test through Terminal (Command Prompt)
Syntax: npm run ccs_playwrigt_test -- --ENV={Env} [--TEST_DIR={Test_Dir}] [--TAGS={tags}] [--BROWSER={Chrome|Firefox|Webkit}] [--HEADLESS={true|false}] [--CLIENT={client}] [--REPORT_PATH={Report_Path}] [PARALLEL_WORKER={PARALLEL_WORKER_Count}] [RETRY_COUNT={retry_count}] [REPEAT_EACH={repeat_each}] [REPORTER={reporter}] [TIME_OUT={timetout}]
- ENV is mandatory (required) argument. Value can be any one of the following: dev, test, qa, stage, ct, uat, prod
- If no TEST_DIR are specified then it will run all playwright tests
- If no TAGS are specified then it will run all scenarios of applicable features irrespective of tag
- If no BROWSER is specified then default would be Chrome. Value can be only Chrome or Firefox or Webkit
- If HEADLESS parameter is not specified then default would be Headless as false
- If CLIENT parameter is not specified then it will be ignored
- If REPORT_PATH parameter is not specified then report will be generated at folder playwright-test-results. Otherwise Playwright HTML report and JSON file will be generated at the specified location
- If PARALLEL_WORKER parameter is not specified then default would be 1. If specified then given number of parallel execution will occur
- If REPEAT_EACH parameter is not specified then default would be 1. If specified then every tests will run given no. of times
- If RETRY_COUNT parameter is not specified then default would be 1. If specified then given number of times failed tests will be re-executed
- If TIME_OUT parameter is not specified then default would be 1. If specified then given timetout value is utilized for each tests
- The following will not work as ENV variable is mandatory
npm run ccs_playwrigt_test - To execute all of the features with PROD environment variables with Chrome
npm run ccs_playwrigt_test -- --ENV=PROD - To execute all of the Tests with PROD environment variables with Chrome for a specific client
npm run ccs_playwrigt_test -- --ENV=PROD --CLIENT=TransAmerica - To execute all of the Tests under loginPage folder with PROD environment variables with Chrome
npm run ccs_playwrigt_test -- --ENV=PROD --TEST_DIR=app/test/playwright/loginPage - To execute all of the Tests under loginPage and booksPage folder with PROD environment variables with Chrome
npm run ccs_playwrigt_test -- --ENV=PROD --TEST_DIR=app/test/playwright/loginPage,app/test/playwright/booksPage - To execute all of the Tests under loginPage folder which are tagged as @auth with PROD environment variables with Chrome
npm run ccs_playwrigt_test -- --ENV=PROD --TEST_DIR=app/test/playwright/loginPage --TAGS="@auth" - To execute all of the Tests which are tagged as @auth with PROD environment variables with Chrome
npm run ccs_playwrigt_test -- --ENV=PROD --TAGS="@auth" - To execute all of the Tests which are tagged as @auth or @add with PROD environment variables with Chrome
npm run ccs_playwrigt_test -- --ENV=PROD --TAGS="@auth or @add" - To execute all of the Tests which are not tagged as @auth with PROD environment variables with Chrome
npm run ccs_playwrigt_test -- --ENV=PROD --TES_DIR=app/test/playwright/loginPage --TAGS="not @auth" - To execute all of the features with PROD environment variables with Firefox
npm run ccs_playwrigt_test -- --ENV=PROD --BROWSER=Firefox - To execute all of the features with PROD environment variables with Webkit
npm run ccs_playwrigt_test -- --ENV=PROD --BROWSER=Webkit - To execute all of the features with PROD environment variables with browser as Headless
npm run ccs_playwrigt_test -- --ENV=PROD --BROWSER=Webkit --HEADLESS=true - To execute all of the features with PROD environment variables with browser as Headless and to generate the Report at downloads folder
npm run ccs_playwrigt_test -- --ENV=PROD --BROWSER=Webkit --HEADLESS=true --REPORT_PATH=C:/users/Test/Downloads - To execute all of the features with PROD environment variables with browser as Headless in Parallel mode
npm run ccs_playwrigt_test -- --ENV=PROD --BROWSER=Webkit --HEADLESS=true --PARALLEL_WORKER=2
Tutorials
- To know more about Framework - [tm-playwright-framework] (https://toppanmerrill.atlassian.net/wiki/spaces/MCSAUT/pages/4084924498/PLAYWRIGHT+FRAMEWORK+ARCHITECTURE)
- Learn Playwright - Playwright - TS
- BDD in detail - TS binding
