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 d1c5c25

Browse files
Merge pull request #2 from auto-qa-hub/configure_dotenv
configured dotenv and added example test for login
2 parents 5d83151 + 6360770 commit d1c5c25

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

.github/workflows/playwright.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ jobs:
88
test:
99
timeout-minutes: 60
1010
runs-on: ubuntu-latest
11+
env:
12+
VALID_USER_NAME: ${{ secrets.VALID_USER_NAME }}
13+
VALID_PASSWORD: ${{ secrets.VALID_PASSWORD }}
1114
steps:
1215
- uses: actions/checkout@v4
1316
- uses: actions/setup-node@v4

playwright.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { defineConfig, devices } from '@playwright/test';
22

3+
import * as dotenv from 'dotenv';
4+
dotenv.config();
5+
6+
export const validUserName = process.env.VALID_USER_NAME;
7+
export const validPassword = process.env.VALID_PASSWORD;
8+
39
/**
410
* Read environment variables from file.
511
* https://github.com/motdotla/dotenv

tests/example.spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { test, expect } from '@playwright/test';
1+
import { test, expect, request } from '@playwright/test';
2+
import { validUserName, validPassword } from '../playwright.config';
23

34
test('has title', async ({ page }) => {
45
await page.goto('https://playwright.dev/');
@@ -16,3 +17,24 @@ test('get started link', async ({ page }) => {
1617
// Expects page to have a heading with the name of Installation.
1718
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
1819
});
20+
21+
test.describe('Positive login test', () => {
22+
test('Login', async ({ request }) => {
23+
24+
if (!validUserName || !validPassword) {
25+
throw new Error('Username or password is undefined');
26+
}
27+
const response = await request.get('https://petstore.swagger.io/v2/user/login', {
28+
29+
params: {
30+
username: validUserName,
31+
password: validPassword,
32+
},
33+
});
34+
35+
expect(response.status()).toBe(200);
36+
37+
const responseBody = await response.json();
38+
console.log('Login response:', responseBody);
39+
});
40+
});

0 commit comments

Comments
 (0)