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 c4c44f4

Browse files
authored
Merge pull request #3 from auto-qa-hub/DK_Utilities_and_InfoTests
Dk utilities and info tests
2 parents d1c5c25 + 647229b commit c4c44f4

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

tests/userTests.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { test, expect } from '@playwright/test';
2+
import { loginWithCredsFromEnv, CheckUserInformation, CreateTestUser } from './utilities';
3+
import { validUserName, validPassword } from '../playwright.config';
4+
5+
6+
test.describe('Login and UserInfo tests', () => {
7+
test('Create User', async () => {
8+
const responseStatus = await CreateTestUser({ username: validUserName, password: validPassword })
9+
expect(responseStatus.status()).toBe(200);
10+
});
11+
12+
test('Check Login', async () => {
13+
const responseStatus = await loginWithCredsFromEnv(validUserName, validPassword);
14+
expect(responseStatus.status()).toBe(200);
15+
});
16+
17+
test('Check User', async () => {
18+
const responseStatus = await CheckUserInformation(validUserName)
19+
expect(responseStatus.status()).toBe(200);
20+
});
21+
})

tests/utilities.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { test, expect, request } from '@playwright/test';
2+
3+
export async function CreateTestUser({id = 11225, username = "TestUser", firstName = "Auto", lastName = "Testing", email = "[email protected]", password = "12345678Aa!", phone = "0661112233", userStatus = 0} = {}) {
4+
const context = await request.newContext();
5+
const response = await context.post('https://petstore.swagger.io/v2/user', {
6+
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
15+
}
16+
})
17+
const responseBody = await response.json();
18+
console.log('Creation response:', responseBody);
19+
return response
20+
}
21+
22+
export async function loginWithCredsFromEnv(username: string | undefined, password: string | undefined) {
23+
const context = await request.newContext();
24+
if (!username || !password) {
25+
throw new Error('Username or password is undefined');
26+
}
27+
const response = await context.get('https://petstore.swagger.io/v2/user/login', {
28+
29+
params: {
30+
username: username,
31+
password: password,
32+
},
33+
});
34+
const responseBody = await response.json();
35+
console.log('Login response:', responseBody);
36+
return response
37+
}
38+
39+
export async function CheckUserInformation(username: string | undefined) {
40+
const context = await request.newContext();
41+
const response = await context.get(`https://petstore.swagger.io/v2/user/${username}`)
42+
const responseBody = await response.json();
43+
console.log(responseBody)
44+
45+
const userInfo = await response.json();
46+
console.log('User Information:', userInfo);
47+
return response
48+
}

0 commit comments

Comments
 (0)