Skip to content

Commit

Permalink
chore: update scripts and readme file
Browse files Browse the repository at this point in the history
  • Loading branch information
Romarionijim committed Dec 26, 2024
1 parent 7fc6e78 commit 531298d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
51 changes: 43 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
# TypeScript-Playwright-Api-Example
* This is an API automation infra mini project that covers 3 different entities/recources with different URLs and endpoints
In this project I'm using TypeScript with Playwright API request object for api automation development and testing => https://playwright.dev/docs/api-testing
* to navigate this infra - it goes as the following structure
* for the infra => infra folder => api => apiRequests - this contains the base api requests that has reusable functions that handle rest api CRUD operations including pagination
* entities => represents the infra and functions for the specific entities that are testes.
* test => tests folder - contains basic tests for those entities and endpoints
keep in mind that the gorestapi endpoint is not flexible and has a lot of bugs on their end.

## Project Description
* Developed an API automation framework from scratch to test multiple public APIs, including gorestapi, pokemonAPI, and PetAPI.
* Utilized TypeScript and Playwright’s request context for efficient and reliable API testing.
* Applied an Object-Oriented Programming (OOP) structure to ensure reusability, scalability, and maintainability of the framework.
* Integrated CI/CD pipelines with GitHub Actions for automated testing and deployment.
## Pre requisites
* Nodejs installed version 18 and above (you can use NVM)
* IDE (VScode, Webstorm)
## Getting started
* to get started with the project - first clone the repo by opening the terminal in your IDE and run:
* `git clone https://github.com/Romarionijim/TypeScript-Playwright-Api-Example.git`
## Installing dependencies and Playwright
* after cloning the repo - navigate to the root directory:
* `cd TypeScript-Playwright-Api-Example`
* `cd automation/`
* install dependencies by running the following commands in this order:
* `npm ci`
* `npx playwright install`
## Running tests
* To run all of the tests you can run the following command in the terminal:
* `npm run test`
* To run a specific test you can do it in two ways:
* run a specific test file e.g `npm run test tests/api_tests/pokemon/PokemonApiTests.spec.ts`
* or navigate to a specific test file and type `.only` on a specific `test` block example:
`test.only('test goes here') => {`
## Running tests in parallel
* To run a tests in parallel with multiple workers you can specify the number of workers:
* `npx playwright test --workers=4'`
* or override the current sciprt 1 worker: `npm run test -- --workers 4`
## Running only modified tests
* if you wanna only run tests that you have currently modified and changes are still uncommitted without having the need to specify a test file in the terminal or by passing `.only` to a specific test, you can run the following command - this will only run test files with uncommitted changes:
* `npm run test:changed`
* This will run when you have uncomitted changes on specific test files or class files related to specific test files so if you modify a class file that is used by a test and the change is uncommited it will only run the test related to the class - depends on what you have modified since the last git commit as long as it in the uncommited staging area.
## Reports
* The reports that are used in this project are playwright html reports.
* To generate a report after a test, run the following:
* `npx playwright show-report`
* The reports are also saved as artifact and saved for a limited time on github - which you can download as a zip file and extract them to view.

## CI/CD
* In this project I'm using GitHub Actions CI/CD - any code changes you'll push will trigger the github actions pipeline where tests will checkout the current branch, install dependencies and runs all of the tests, deploy and upload the playwright html report.
* Test results html report will be uploaded as an artifact as well after each run so you can download it if you prefer that way (the report is retained up to 30 days after test run)
4 changes: 2 additions & 2 deletions infra/api/apiClient/ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ApiClient {
* @param headers
*/
private async addAuthorizationHeader(headers: { [key: string]: string }) {
headers['Authorization'] = `Bearer ${process.env.API_TOKEN}`
headers['Authorization'] = `Bearer ${process.env.API_TOKEN}`;
}

/**
Expand Down Expand Up @@ -96,7 +96,7 @@ export class ApiClient {
response = await this.request.delete(url)
break;
}
return response
return response;
}


Expand Down
4 changes: 2 additions & 2 deletions infra/api/entities/petStore/PetStoreCrudActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export class PetStoreCrudActions extends ApiClient {

public async getPet(petId: number): Promise<APIResponse | undefined> {
let response = await this.get(`${this.petStorePetEndpoint}/${petId}`)
return response
return response;
}

public async createNewPet<T>(petData: { [key: string]: T }) {
let response = await this.post(this.petStorePetEndpoint, { requestData: petData })
return response;
return response;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"scripts": {
"test": "npx playwright test --workers 1"
},
"keywords": [],
"author": "",
"license": "ISC",
Expand Down

0 comments on commit 531298d

Please sign in to comment.