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

Commit 326d6cc

Browse files
authored
Merge pull request #14 from auto-qa-hub/add-test-data-for-pets
add_test_data_for_pets
2 parents 5058b57 + 9e398f2 commit 326d6cc

File tree

4 files changed

+86
-73
lines changed

4 files changed

+86
-73
lines changed

test-data/pets.Data.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"order1": {
3+
"id": 1,
4+
"petId": 0,
5+
"quantity": 0,
6+
"shipDate": "2025-01-01T17:00:00.000Z",
7+
"status": "placed",
8+
"complete": true
9+
},
10+
"pet2": {
11+
"id": 2,
12+
"category": {
13+
"id": 0,
14+
"name": "string"
15+
},
16+
"name": "doggie",
17+
"photoUrls": ["string"],
18+
"tags": [
19+
{
20+
"id": 0,
21+
"name": "string"
22+
}
23+
],
24+
"status": ["available", "pending", "sold"]
25+
},
26+
27+
"pet2update": {
28+
"id": 2,
29+
"category": {
30+
"id": 0,
31+
"name": "string",
32+
"updatedName": "Updated Pet Name"
33+
},
34+
"name": "kitty",
35+
"photoUrls": ["string"],
36+
"tags": [
37+
{
38+
"id": 0,
39+
"name": "string"
40+
}
41+
],
42+
"status": ["available", "pending", "sold"]
43+
},
44+
45+
"pet4": {
46+
"id": 4,
47+
"status": ["available", "pending", "sold"]
48+
},
49+
50+
"pet6": {
51+
"id": 6,
52+
"category": {
53+
"id": 0,
54+
"name": "string"
55+
},
56+
"name": "doggie",
57+
"photoUrls": ["string"],
58+
"tags": [
59+
{
60+
"id": 0,
61+
"name": "string"
62+
}
63+
],
64+
"status": "available"
65+
}
66+
}

tests/petTests.spec.ts

Lines changed: 19 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { test, expect, request } from "@playwright/test";
22
import * as fs from "fs";
33
import * as path from "path";
4+
import pets from "../test-data/pets.Data.json"
45

56
const backendURL: string = "https://petstore.swagger.io/v2/pet";
67

@@ -37,22 +38,7 @@ test.describe("Testing uploading image for pet and pets creation/updating", () =
3738
test("Add a new pet to the store", async () => {
3839
const context = await request.newContext();
3940
const response = await context.post(`${backendURL}`, {
40-
data: {
41-
id: 2,
42-
category: {
43-
id: 0,
44-
name: "string",
45-
},
46-
name: "doggie",
47-
photoUrls: ["string"],
48-
tags: [
49-
{
50-
id: 0,
51-
name: "string",
52-
},
53-
],
54-
status: "available",
55-
},
41+
data:pets.pet2,
5642
});
5743
expect(response.status()).toBe(200);
5844
const responseBody = await response.json();
@@ -62,22 +48,7 @@ test.describe("Testing uploading image for pet and pets creation/updating", () =
6248
test("Update an existing pet", async () => {
6349
const context = await request.newContext();
6450
const response = await context.post(`${backendURL}`, {
65-
data: {
66-
id: 2,
67-
category: {
68-
id: 0,
69-
name: "string",
70-
},
71-
name: "kitty",
72-
photoUrls: ["string"],
73-
tags: [
74-
{
75-
id: 0,
76-
name: "string",
77-
},
78-
],
79-
status: "available",
80-
},
51+
data: pets.pet2update
8152
});
8253
expect(response.status()).toBe(200);
8354
const responseBody = await response.json();
@@ -87,55 +58,51 @@ test.describe("Testing uploading image for pet and pets creation/updating", () =
8758

8859
test.describe("Find pet by status: available, pending, sold", () => {
8960
test('Should return pets with status "pending"', async ({ request }) => {
90-
const status = "pending";
9161
const response = await request.get(`${backendURL}/findByStatus`, {
92-
params: { status },
62+
params: pets.pet2.status[1],
9363
});
9464

9565
expect(response.status()).toBe(200);
9666

9767
const responseBody = await response.json();
9868
expect(Array.isArray(responseBody)).toBeTruthy();
9969
responseBody.forEach((pet) => {
100-
expect(pet.status).toBe("pending");
70+
expect(pet.status).toBe(pets.pet2.status[1]);
10171
});
10272
});
10373
});
10474

10575
test('Should return pets with status "available"', async ({ request }) => {
106-
const status = "available";
10776
const response = await request.get(`${backendURL}/findByStatus`, {
108-
params: { status },
77+
params: pets.pet2.status[0],
10978
});
11079

11180
expect(response.status()).toBe(200);
11281

11382
const responseBody = await response.json();
11483
expect(Array.isArray(responseBody)).toBeTruthy();
11584
responseBody.forEach((pet) => {
116-
expect(pet.status).toBe("available");
85+
expect(pet.status).toBe(pets.pet2.status[0]);
11786
});
11887
});
11988

12089
test('Should return pets with status "sold"', async ({ request }) => {
121-
const status = "sold";
12290
const response = await request.get(`${backendURL}/findByStatus`, {
123-
params: { status },
91+
params: pets.pet2.status[2],
12492
});
12593

12694
expect(response.status()).toBe(200);
12795
const responseBody = await response.json();
12896
expect(Array.isArray(responseBody)).toBeTruthy();
12997
responseBody.forEach((pet) => {
130-
expect(pet.status).toBe("sold");
98+
expect(pet.status).toBe(pets.pet2.status[2]);
13199
});
132100
});
133101

134102
test.describe("Find pet by ID, update pet in the store", async () => {
135103
test("Find pet", async () => {
136-
const petId = 4;
137104
const context = await request.newContext();
138-
const response = await context.get(`${backendURL}/${petId}`);
105+
const response = await context.get(`${backendURL}/${pets.pet4.id}`);
139106
expect(response.status()).toBe(200);
140107

141108
const responseBody = await response.json();
@@ -144,44 +111,25 @@ test.describe("Find pet by ID, update pet in the store", async () => {
144111
});
145112

146113
test("Update pet information", async () => {
147-
const petId = 2;
148-
const updatedName = "Updated Pet Name";
149-
const updatedStatus = "sold";
150114
const context = await request.newContext();
151-
const response = await context.post(`${backendURL}/${petId}`, {
115+
const response = await context.post(`${backendURL}/${pets.pet2update.id}`, {
152116
form: {
153-
name: updatedName,
154-
status: updatedStatus,
117+
name: pets.pet2update.name,
118+
status: pets.pet2update.status[2]
155119
},
156120
});
157121
expect(response.status()).toBe(200);
158122

159123
const responseBody = await response.json();
160124
console.log(responseBody);
161-
expect(responseBody.message).toBe(petId.toString());
125+
expect(responseBody.message).toBe(pets.pet2update.id.toString());
162126
});
163127

164128
test.describe("Delete pet by ID", async () => {
165-
const petId = 6;
166129
test.beforeAll(async () => {
167130
const context = await request.newContext();
168131
const response = await context.post(`${backendURL}`, {
169-
data: {
170-
id: petId,
171-
category: {
172-
id: 0,
173-
name: "string",
174-
},
175-
name: "doggie",
176-
photoUrls: ["string"],
177-
tags: [
178-
{
179-
id: 0,
180-
name: "string",
181-
},
182-
],
183-
status: "available",
184-
},
132+
data: pets.pet6
185133
});
186134
expect(response.status()).toBe(200);
187135
const responseBody = await response.json();
@@ -191,7 +139,7 @@ test.describe("Delete pet by ID", async () => {
191139
test("Delete pet", async () => {
192140
const context = await request.newContext();
193141
const apiKey = "your_actual_api_key";
194-
const response = await context.delete(`${backendURL}/${petId}`, {
142+
const response = await context.delete(`${backendURL}/${pets.pet6.id}`, {
195143
headers: {
196144
api_key: apiKey,
197145
},
@@ -203,10 +151,9 @@ test.describe("Delete pet by ID", async () => {
203151
});
204152

205153
test.afterAll(async () => {
206-
const petId = 6;
207154
const context = await request.newContext();
208-
const response = await context.delete(`${backendURL}/${petId}`);
155+
const response = await context.delete(`${backendURL}/${pets.pet6.id}`);
209156

210-
expect(response.status()).toBe(404);
157+
expect(response.status()).toBe(404);
211158
});
212-
});
159+
});

tests/userTests.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test, expect } from '@playwright/test';
22
import * as utilities from './utilities';
33
import { validUserName, validPassword } from '../playwright.config';
4-
import testData from "../test-data/test.data.json"
4+
import testData from "../test-data/users.data.json";
55

66
test.describe('User part tests', () => {
77
test('Create User', async () => {

0 commit comments

Comments
 (0)