Skip to content

Commit 98d1526

Browse files
committed
Added new tests
1 parent 53db7d2 commit 98d1526

9 files changed

+209
-0
lines changed

playwright.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module.exports = defineConfig({
3737
actionTimeout: 0,
3838
/* Base URL to use in actions like `await page.goto('/')`. */
3939
baseURL: 'https://restful-booker.herokuapp.com',
40+
// baseURL: 'https://petstore.swagger.io/v2',
4041

4142
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
4243
trace: 'on-first-retry',
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @ts-check
2+
const { test, expect } = require('@playwright/test');
3+
4+
test('should be get all the booking details', async ({ request }) => {
5+
const response = await request.get(`/booking`);
6+
console.log(await response.json());
7+
expect(response.ok()).toBeTruthy();
8+
expect(response.status()).toBe(200);
9+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @ts-check
2+
const { test, expect } = require('@playwright/test');
3+
4+
test('should be get specific booking details', async ({ request }) => {
5+
const response = await request.get(`/booking/1`);
6+
console.log(await response.json());
7+
expect(response.ok()).toBeTruthy();
8+
expect(response.status()).toBe(200);
9+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @ts-check
2+
const { test, expect } = require('@playwright/test');
3+
4+
test('should be able to get subset of booking details using query parameters', async ({ request }) => {
5+
const response = await request.get(`/booking`, {
6+
params: {
7+
firstname: "Susan",
8+
lastname: "Jackson"
9+
},
10+
});
11+
console.log(await response.json());
12+
expect(response.ok()).toBeTruthy();
13+
expect(response.status()).toBe(200);
14+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @ts-check
2+
const { test, expect } = require('@playwright/test');
3+
4+
test('should be able to get subset of booking details using query parameters - checkin date example', async ({ request }) => {
5+
const response = await request.get(`/booking`, {
6+
params: {
7+
checkin: "2021-01-15",
8+
checkout: "2023-03-25"
9+
},
10+
});
11+
console.log(await response.json());
12+
expect(response.ok()).toBeTruthy();
13+
expect(response.status()).toBe(200);
14+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// @ts-check
2+
const { test, expect } = require('@playwright/test');
3+
4+
var token
5+
6+
test('should be able to update the booking details', async ({ request }) => {
7+
8+
// Create a Token which will be used in PUT request
9+
10+
const response = await request.post(`/auth`, {
11+
data: {
12+
"username": "admin",
13+
"password": "password123"
14+
}
15+
});
16+
console.log(await response.json());
17+
expect(response.ok()).toBeTruthy();
18+
expect(response.status()).toBe(200);
19+
const responseBody = await response.json();
20+
token = responseBody.token;
21+
console.log("New Token is: " + token);
22+
23+
// PUT
24+
const updateRequest = await request.put(`/booking/1`, {
25+
headers: {
26+
'Content-Type': 'application/json',
27+
'Accept': 'application/json',
28+
'Cookie': `token=${token}`,
29+
},
30+
data: {
31+
"firstname": "Jim",
32+
"lastname": "Brown",
33+
"totalprice": 111,
34+
"depositpaid": true,
35+
"bookingdates": {
36+
"checkin": "2023-06-01",
37+
"checkout": "2023-06-15"
38+
},
39+
"additionalneeds": "Breakfast"
40+
}
41+
});
42+
console.log(await updateRequest.json());
43+
expect(updateRequest.ok()).toBeTruthy();
44+
expect(updateRequest.status()).toBe(200);
45+
const updatedResponseBody = await updateRequest.json()
46+
expect(updatedResponseBody).toHaveProperty("firstname", "Jim");
47+
expect(updatedResponseBody).toHaveProperty("lastname", "Brown");
48+
expect(updatedResponseBody).toHaveProperty("totalprice", 111);
49+
expect(updatedResponseBody).toHaveProperty("depositpaid", true);
50+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// @ts-check
2+
const { test, expect } = require('@playwright/test');
3+
4+
var token
5+
6+
test('should be able to partial update the booking details', async ({ request }) => {
7+
8+
// Create a Token which will be used in PATCH request
9+
10+
const response = await request.post(`/auth`, {
11+
data: {
12+
"username": "admin",
13+
"password": "password123"
14+
}
15+
});
16+
console.log(await response.json());
17+
expect(response.ok()).toBeTruthy();
18+
expect(response.status()).toBe(200);
19+
const responseBody = await response.json();
20+
token = responseBody.token;
21+
console.log("New Token is: " + token);
22+
23+
// PATCH
24+
25+
const partialUpdateRequest = await request.patch(`/booking/1`, {
26+
headers: {
27+
'Content-Type': 'application/json',
28+
'Accept': 'application/json',
29+
'Cookie': `token=${token}`
30+
},
31+
data: {
32+
"firstname": "Sim",
33+
"lastname": "Son",
34+
"totalprice": 333,
35+
"depositpaid": false
36+
}
37+
});
38+
console.log(await partialUpdateRequest.json());
39+
expect(partialUpdateRequest.ok()).toBeTruthy();
40+
expect(partialUpdateRequest.status()).toBe(200);
41+
const partialUpdatedResponseBody = await partialUpdateRequest.json()
42+
expect(partialUpdatedResponseBody).toHaveProperty("firstname", "Sim");
43+
expect(partialUpdatedResponseBody).toHaveProperty("lastname", "Son");
44+
expect(partialUpdatedResponseBody).toHaveProperty("totalprice", 333);
45+
expect(partialUpdatedResponseBody).toHaveProperty("depositpaid", false);
46+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// @ts-check
2+
const { test, expect } = require('@playwright/test');
3+
4+
var token
5+
6+
test('should be able to delete the booking details', async ({ request }) => {
7+
8+
// Create a Token which will be used in DELETE request
9+
10+
const response = await request.post(`/auth`, {
11+
data: {
12+
"username": "admin",
13+
"password": "password123"
14+
}
15+
});
16+
console.log(await response.json());
17+
expect(response.ok()).toBeTruthy();
18+
expect(response.status()).toBe(200);
19+
const responseBody = await response.json();
20+
token = responseBody.token;
21+
console.log("New Token is: " + token);
22+
23+
// DELETE
24+
25+
const deleteRequest = await request.delete(`/booking/1`, {
26+
headers: {
27+
'Content-Type': 'application/json',
28+
'Cookie': `token=${token}`
29+
}
30+
});
31+
expect(deleteRequest.status()).toEqual(201);
32+
expect(deleteRequest.statusText()).toBe('Created');
33+
});

tests/sample.spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// @ts-check
2+
const { test, expect } = require('@playwright/test');
3+
4+
test('should be able to create a booking', async ({ request }) => {
5+
const response = await request.put(`https://petstore.swagger.io/v2/pet`, {
6+
data: {
7+
"id": 0,
8+
"category": {
9+
"id": 0,
10+
"name": "string"
11+
},
12+
"name": "doggie",
13+
"photoUrls": [
14+
"string"
15+
],
16+
"tags": [
17+
{
18+
"id": 0,
19+
"name": "string"
20+
}
21+
],
22+
"status": "available"
23+
}
24+
});
25+
console.log(await response.json());
26+
expect(response.ok()).toBeTruthy();
27+
expect(response.status()).toBe(200);
28+
const responseBody = await response.json();
29+
expect(responseBody.category).toHaveProperty("id", 0);
30+
expect(responseBody.category).toHaveProperty("name", "string");
31+
expect(responseBody).toHaveProperty("name", "doggie");
32+
expect(responseBody).toHaveProperty("status", "available");
33+
});

0 commit comments

Comments
 (0)