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 e30eacd

Browse files
Test commit changes
1 parent 2721c71 commit e30eacd

File tree

4 files changed

+49
-28
lines changed

4 files changed

+49
-28
lines changed

playwright.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { defineConfig, devices } from '@playwright/test';
22
import dotenv from 'dotenv';
33
dotenv.config();
44

5-
// export const validUserName = process.env.VALID_USER_NAME;
6-
// export const validPassword = process.env.VALID_PASSWORD;
5+
export const validUserName = process.env.VALID_USER_NAME;
6+
export const validPassword = process.env.VALID_PASSWORD;
77

88
/**
99
* Read environment variables from file.
@@ -82,4 +82,4 @@ export default defineConfig({
8282
// url: 'http://127.0.0.1:3000',
8383
// reuseExistingServer: !process.env.CI,
8484
// },
85-
});
85+
});

tests/example.spec.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

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: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
import { test, expect, request } from '@playwright/test';
22

3-
export async function loginWithCredsFromEnv(username: string, password: string) {
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) {
423
const context = await request.newContext();
524
if (!username || !password) {
625
throw new Error('Username or password is undefined');
@@ -12,22 +31,18 @@ export async function loginWithCredsFromEnv(username: string, password: string)
1231
password: password,
1332
},
1433
});
15-
16-
expect(response.status()).toBe(200);
17-
1834
const responseBody = await response.json();
1935
console.log('Login response:', responseBody);
36+
return response
2037
}
2138

22-
export async function CheckUserInformation(username: string) {
39+
export async function CheckUserInformation(username: string | undefined) {
2340
const context = await request.newContext();
2441
const response = await context.get(`https://petstore.swagger.io/v2/user/${username}`)
2542
const responseBody = await response.json();
2643
console.log(responseBody)
2744

28-
expect(response.status()).toBe(200);
2945
const userInfo = await response.json();
30-
console.log('UserInformation:', userInfo);
31-
}
32-
33-
46+
console.log('User Information:', userInfo);
47+
return response
48+
}

0 commit comments

Comments
 (0)