Code Monkey home page Code Monkey logo

playwright_automation_framework's Introduction

Test Automation Framework using Playwright & Typescript

The goal is to showcase various user interactions on the "https://the-internet.herokuapp.com/" web application by creating automated tests that cover specific user flows. These tests will be implemented using Playwright and TypeScript. The tests will simulate how users navigate and interact with the web application, verifying that it functions correctly and meets the desired expectations.

Table of contents

  • [Prerequisits]
  • [Clone Private Project]
  • [Install Dependencies]
  • [Run Test]
  • [Page Object Model(POM)]
  • [Folder Structure]
  • [Dotenv Module (.env)]
  • [Specs]
  • [Pages]
  • [Test Execution Methods]
  • [Reporting]
  • [Release Notes]

Prerequisits

 NodeJs - version 18.12.0

 playwright - version 1.36

Clone Private Project

Run the below command to clone the project

git clone https://github.com/hasithawaruna/WebAutomator_Playwrite

Install Dependencies

Follow the root directory of the cloned project and execute the below command to install node modules

npm i

Run Test

Use the below command to run the Playwrite test

npm test

Page Object Model(POM)

The Page Object Model (POM) in Playwright is a design pattern used to organize web automation code. It abstracts web pages into classes, encapsulating their elements and actions. This approach enhances code maintainability, reusability, and readability, enabling efficient interaction with web elements while creating automated tests.

Folder Structure

├── ...
│
├── pages/                                     # Generic functionality for tests
│   |
│   ├── add-remove-elements-page.ts           # Specific Locators & Functions of The Page                
│   ├── checkbox-page.ts                      # Specific Locators & Functions of The Page    
│   ├── drag-and-drop-page.ts                 # Specific Locators & Functions of The Page         
│   ├── dropdown-select-page.ts               # Specific Locators & Functions of The Page    
│   ├── nestedFrame-and-iFrame-page.ts        # Specific Locators & Functions of The Page    
│
├── tests/                                    # Test cases
│    ├── add-remove-elements-test.spec.ts     # Automated Test Script               
│    ├── checkbox-test.spec.ts                # Automated Test Script
│    ├── drag-and-drop-test.spec.ts           # Automated Test Script
│    ├── dropdown-select-test.spec.ts         # Automated Test Script
│    ├── nestedFrame-and-iFrame-test.spec.ts  # Automated Test Script        
│   
├── playwright-report/   
│         ├──index.html                       #  Test report of the tests executed 
│
│── .env.test                                 # Confiugurations used in the test environment
│
├── playwright.config.ts                      # Confiugurations of Playwright
│  
├── node_modules/                             # Storing installed project dependencies
│ 
├── release_notes/                            # Maintain all release notes for each version
│ 
├── package.json                              # Dependency and script management     
│ 
└── package-lock.json                         # Dependency version locking

Dotenv Module (.env)

The '.env.test' file in Playwright TypeScript web automation allows setting environment-specific variables (e.g., base URLs, credentials) for easier configuration and testing across different test environments. More information about Dotenv can be found in official documentation here.

Specs

In Playwright's Page Object Model (POM, ".spec.ts" files are utilized for organizing automated test code separately from the application code. These files contain test specifications and scenarios written in TypeScript. Playwright recognizes ".spec.ts" files as test files and executes them using testing frameworks built on Playwright.

Specs are written under the /tests folder. Check the above Folder structure for a better understanding.

Pages

In Playwright's Page Object Model (POM), "Pages" refer to the representation of web pages as classes. Each web page is abstracted into a separate class, encapsulating its elements, actions, and related methods. This approach allows testers to interact with the web elements and perform actions on the page without directly dealing with the underlying HTML or implementation details. It promotes code modularity and makes test code more organized and maintainable.

Page files are written under the /pages folder. Check the above Folder structure for a better understanding.

Test Execution Methods

Tests can be executed either via the command line or from the Playwright test runner plugin in VS code. By following the below commands you can execute tests with different settings.

Run all test cases :

To run all the test cases available under /test directory without visual (headless)

npx playwright test

To run all the test cases available under /test directory with visual (headed)

npx playwright test --headed

To run all the test cases available under /test directory with Trace Viewer UI

npx playwright test --ui
To run all the test cases available under /test directory with a specific browser

 Chrome :
   ```
   npx playwright test --project=chromium
   ```
Firefox :
   ```
   npx playwright test --project=firefox
   ```
Webkit :
   ```
   npx playwright test --project=webkit
   ```

Run specific test cases :

To run specific test cases available under /test directory without visual (headless)

npx playwright test <testcasename.spec.ts>

To run specific test cases available under /test directory with visual (headed)

npx playwright test <testcasename.spec.ts> --headed

To run specific test cases available under /test directory with Trace Viewer UI

npx playwright test <testcasename.spec.ts> --ui
To run specific test cases available under /test directory with a specific browser

Chrome :
   ```
   npx playwright test <testcasename.spec.ts> --project=chromium
   ```
Firefox :
   ```
   npx playwright test <testcasename.spec.ts> --project=firefox
   ```
Webkit :
   ```
   npx playwright test <testcasename.spec.ts> --project=webkit
   ```

Reporting

Once the execution is done you can open the playwright report by running the command

  npx playwright show-report

To View HTML Report

├── playwright-report/   
│         ├──index.html - Right Click and Navigate to the directory to open the .HTML file via the browser    

Release Notes

https://github.com/hasithawaruna/WebAutomator_Playwrite/releases

playwright_automation_framework's People

Contributors

hasithawaruna avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.