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 cd489ca

Browse files
authored
Merge pull request #6 from auto-qa-hub/DK_userTests_completed
User Tests Complited
2 parents 47e2a63 + 15caeb1 commit cd489ca

File tree

3 files changed

+151
-21
lines changed

3 files changed

+151
-21
lines changed

test-data/test.data.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"id": 11229,
3+
"username": "DKTestUpdateUser",
4+
"firstName": "TestAuto",
5+
"lastName": "DKTesting",
6+
"email": "[email protected]",
7+
"password": "12345678919Aa!",
8+
"phone": "069911122",
9+
"userStatus": 0
10+
}

tests/userTests.spec.ts

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,82 @@
11
import { test, expect } from '@playwright/test';
2-
import { loginWithCredsFromEnv, CheckUserInformation, CreateTestUser } from './utilities';
2+
import * as utilities from './utilities';
33
import { validUserName, validPassword } from '../playwright.config';
4+
import testData from "../test-data/test.data.json"
45

5-
6-
test.describe('Login and UserInfo tests', () => {
6+
test.describe('User part tests', () => {
77
test('Create User', async () => {
8-
const responseStatus = await CreateTestUser({ username: validUserName, password: validPassword })
8+
const responseStatus = await utilities.CreateTestUser({ username: validUserName, password: validPassword })
99
expect(responseStatus.status()).toBe(200);
1010
});
1111

1212
test('Check Login', async () => {
13-
const responseStatus = await loginWithCredsFromEnv(validUserName, validPassword);
13+
const responseStatus = await utilities.loginWithCredsFromEnv(validUserName, validPassword);
14+
const responseBody = await responseStatus.json()
1415
expect(responseStatus.status()).toBe(200);
16+
expect(responseBody.message).toContain('logged in user session')
1517
});
1618

17-
test('Check User', async () => {
18-
const responseStatus = await CheckUserInformation(validUserName)
19+
test('Check Created User Info', async () => {
20+
const responseStatus = await utilities.CheckUserInformation(validUserName)
1921
expect(responseStatus.status()).toBe(200);
22+
const responseBody = await responseStatus.json()
23+
expect(responseBody.username).toBe(validUserName)
24+
expect(responseBody.password).toBe(validPassword)
2025
});
21-
})
26+
27+
test('Check Update User Name', async () => {
28+
const responseStatus = await utilities.UpdateUserName({ username: validUserName, newusername: testData.username })
29+
expect(responseStatus.status()).toBe(200);
30+
31+
const checkNewUserName = await utilities.CheckUserInformation(testData.username)
32+
const responseBody = await checkNewUserName.json()
33+
expect(checkNewUserName.status()).toBe(200);
34+
expect(responseBody.username).toContain(testData.username)
35+
})
36+
37+
test('Check User Deleting', async () => {
38+
const responseStatus = await utilities.DeleteUser(testData.username)
39+
expect(responseStatus.status()).toBe(200);
40+
});
41+
42+
test('Check User Logout', async () => {
43+
const responseStatusLogin = await utilities.loginWithCredsFromEnv(validUserName, validPassword);
44+
const responseStatusLogout = await utilities.LogoutUser()
45+
expect(responseStatusLogout.status()).toBe(200);
46+
const responseBody = await responseStatusLogout.json()
47+
expect(responseBody.message).toBe('ok')
48+
})
49+
50+
test('Check Creation With List', async () => {
51+
const response = await utilities.CreateUserWithList([{
52+
id: testData.id,
53+
username: testData.username,
54+
firstName: testData.firstName,
55+
lastName: testData.lastName,
56+
email: testData.email,
57+
password: testData.password,
58+
phone: testData.phone,
59+
userStatus: testData.userStatus
60+
}]);
61+
expect(response.status()).toBe(200);
62+
const responseBody = await response.json();
63+
expect(responseBody.message).toBe('ok');
64+
});
65+
66+
67+
test('Check User With Array', async () => {
68+
const response = await utilities.CreateUserWithList([{
69+
id: testData.id,
70+
username: testData.username,
71+
firstName: testData.firstName,
72+
lastName: testData.lastName,
73+
email: testData.email,
74+
password: testData.password,
75+
phone: testData.phone,
76+
userStatus: testData.userStatus
77+
}]);
78+
expect(response.status()).toBe(200);
79+
const responseBody = await response.json()
80+
expect(responseBody.message).toBe('ok')
81+
})
82+
})

tests/utilities.ts

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
import { test, expect, request } from '@playwright/test';
2+
import testData from "../test-data/test.data.json"
23

3-
export async function CreateTestUser({id = 11225, username = "TestUser", firstName = "Auto", lastName = "Testing", email = "[email protected]", password = "12345678Aa!", phone = "0661112233", userStatus = 0} = {}) {
4+
interface UserData {
5+
id: number;
6+
username: string;
7+
firstName: string;
8+
lastName: string;
9+
email: string;
10+
password: string;
11+
phone: string;
12+
userStatus: number;
13+
}
14+
15+
export async function CreateTestUser({ id = 11225, username = "TestUser", firstName = "Auto", lastName = "Testing", email = "[email protected]", password = "12345678Aa!", phone = "0661112233", userStatus = 0 } = {}) {
416
const context = await request.newContext();
517
const response = await context.post('https://petstore.swagger.io/v2/user', {
618
data: {
7-
"id": id,
8-
"username": username,
9-
"firstName": firstName,
10-
"lastName": lastName,
11-
"email": email,
12-
"password": password,
13-
"phone": phone,
14-
"userStatus": userStatus
19+
"id": id,
20+
"username": username,
21+
"firstName": firstName,
22+
"lastName": lastName,
23+
"email": email,
24+
"password": password,
25+
"phone": phone,
26+
"userStatus": userStatus
1527
}
1628
})
1729
const responseBody = await response.json();
18-
console.log('Creation response:', responseBody);
1930
return response
2031
}
2132

@@ -32,17 +43,65 @@ export async function loginWithCredsFromEnv(username: string | undefined, passwo
3243
},
3344
});
3445
const responseBody = await response.json();
35-
console.log('Login response:', responseBody);
3646
return response
3747
}
3848

3949
export async function CheckUserInformation(username: string | undefined) {
4050
const context = await request.newContext();
4151
const response = await context.get(`https://petstore.swagger.io/v2/user/${username}`)
4252
const responseBody = await response.json();
43-
console.log(responseBody)
4453

4554
const userInfo = await response.json();
46-
console.log('User Information:', userInfo);
55+
return response
56+
}
57+
58+
export async function UpdateUserName({ id = 11225, username = "TestUser", firstName = "Auto", lastName = "Testing", email = "[email protected]", password = "12345678Aa!", phone = "0661112233", userStatus = 0, newusername = "UpdatedTestUser" } = {}) {
59+
const context = await request.newContext()
60+
const response = await context.put(`https://petstore.swagger.io/v2/user/${username}`, {
61+
data: {
62+
"id": id,
63+
"username": newusername,
64+
"firstName": firstName,
65+
"lastName": lastName,
66+
"email": email,
67+
"password": password,
68+
"phone": phone,
69+
"userStatus": userStatus,
70+
}
71+
})
72+
73+
const userUpdatedInfo = await response.json();
74+
return response
75+
}
76+
77+
export async function DeleteUser(username: string) {
78+
const context = await request.newContext()
79+
const response = await context.delete(`https://petstore.swagger.io/v2/user/${username}`)
80+
return response
81+
}
82+
83+
export async function LogoutUser() {
84+
const context = await request.newContext();
85+
const response = await context.get(`https://petstore.swagger.io/v2/user/logout`, {
86+
headers: {
87+
"accept": "application/json"
88+
}
89+
});
90+
return response
91+
}
92+
93+
export async function CreateUserWithList(options: UserData[] = []): Promise<any> {
94+
const context = await request.newContext();
95+
const response = await context.post(`https://petstore.swagger.io/v2/user/createWithList`, {
96+
data: options
97+
});
98+
return response;
99+
}
100+
101+
export async function CreateUserWithArray(options: UserData[] = []): Promise<any> {
102+
const context = await request.newContext();
103+
const response = await context.post(`https://petstore.swagger.io/v2/user/createWithArray`, {
104+
data: options
105+
})
47106
return response
48107
}

0 commit comments

Comments
 (0)