WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions TEST_PLAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Test Plan for Swagger Petstore API

## Introduction
This document describes the test plan for automated testing of the PetStore API. The goal of testing is to verify
the correctness of the main endpoints and their compliance with the documentation.
The tests will be implemented using Playwright.

## Test Approach
The testing approach for the PetStore API focuses on verifying that the API aligns with its documented specifications and consistently performs as expected under different conditions.

## Test Types
Functional Testing: Verify that each API endpoint works as expected, including correct CRUD operations (Create, Read, Update, Delete).
Boundary Testing: Test edge cases to ensure the API handles inputs at the extremes (e.g., large data sets, maximum and minimum field values).
Error Handling: Test both positive and negative scenarios, in case the server is designed to handle negative scenarios.

## Risk & Mitigation
- **API Instability**
**Risk**: The Pet Store API may experience downtime or unexpected behavior during testing, leading to test failures or delays.
**Mitigation**: Monitor the API's status and schedule tests during off-peak hours.

- **Incomplete Test Data**
**Risk**: Insufficient test data may result in incomplete test coverage. Without proper data, some scenarios, especially edge cases, may be missed.
**Mitigation**: Develop a well-rounded dataset that includes both positive and negative test cases. This should cover normal use cases and edge conditions.

## Entry Criteria
- API documentation is available and up-to-date.
- Test environment is set up and accessible.
- Test data is prepared and covers key scenarios.
- Playwright is configured.
- API is stable for testing.

## Exit Criteria
- All planned test cases have been executed.
- Test results have been reviewed.
100 changes: 100 additions & 0 deletions tests/storeTests.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import {test, expect, request} from '@playwright/test';
const backendURL: string = 'https://petstore.swagger.io/v2/store'

test.describe ('Testing access to orders in the pet store', () => {
test('Return pet inventory by status', async () => {
const context = await request.newContext();
const response = await context.get(`${backendURL}/inventory`)
expect(response.status()).toBe(200);

const responseBody = await response.json();
console.log(responseBody);
});

test('Place an order for a pet', async () => {
const context = await request.newContext();
const response = await context.post(`${backendURL}/order`, {
data: {
"id": 1,
"petId": 0,
"quantity": 0,
"shipDate": "2025-01-01T17:00:00.000Z",
"status": "placed",
"complete": true
},
});
expect(response.status()).toBe(200);

const responseBody = await response.json();
console.log(responseBody);
});
});

test.describe('Find purchase order by ID', async () => {
const orderId = 2;
test.beforeAll(async () => {
const context = await request.newContext();
const response = await context.post(`${backendURL}/order`, {
data: {
"id": orderId,
"petId": 0,
"quantity": 0,
"shipDate": "2025-06-01T17:12:00.000Z",
"status": "placed",
"complete": true
},
});
expect(response.status()).toBe(200);

const responseBody = await response.json();
console.log(responseBody);
});

test('Find order', async () => {
const context = await request.newContext();
const response = await context.get(`${backendURL}/order/${orderId}`);
expect(response.status()).toBe(200);

const responseBody = await response.json();
console.log(responseBody);
});
});

test.describe('Delete order by ID', () => {
const orderId = 3;
test.beforeAll(async () => {
const context = await request.newContext();
const response = await context.post(`${backendURL}/order`, {
data: {
"id": orderId,
"petId": 0,
"quantity": 0,
"shipDate": "2025-06-01T17:12:00.000Z",
"status": "placed",
"complete": true
},
});
expect(response.status()).toBe(200);

const responseBody = await response.json();
console.log(responseBody);
});

test('Delete order', async () => {
const context = await request.newContext();
const response = await context.delete(`${backendURL}/order/${orderId}`);
expect(response.status()).toBe(200);

const responseBody = await response.json();
console.log(responseBody);
});

test.afterAll(async () => {
const context = await request.newContext();
const response = await context.delete(`${backendURL}/order/${orderId}`);
expect(response.status()).toBe(404);

const responseBody = await response.json();
console.log(responseBody);
});
});