diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 3eb1314..4cdcaed 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -8,6 +8,9 @@ jobs: test: timeout-minutes: 60 runs-on: ubuntu-latest + env: + VALID_USER_NAME: ${{ secrets.VALID_USER_NAME }} + VALID_PASSWORD: ${{ secrets.VALID_PASSWORD }} steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 diff --git a/playwright.config.ts b/playwright.config.ts index a05d8b5..3fb7057 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,5 +1,11 @@ import { defineConfig, devices } from '@playwright/test'; +import * as dotenv from 'dotenv'; +dotenv.config(); + +export const validUserName = process.env.VALID_USER_NAME; +export const validPassword = process.env.VALID_PASSWORD; + /** * Read environment variables from file. * https://github.com/motdotla/dotenv diff --git a/tests/example.spec.ts b/tests/example.spec.ts index 54a906a..0b5f90c 100644 --- a/tests/example.spec.ts +++ b/tests/example.spec.ts @@ -1,4 +1,5 @@ -import { test, expect } from '@playwright/test'; +import { test, expect, request } from '@playwright/test'; +import { validUserName, validPassword } from '../playwright.config'; test('has title', async ({ page }) => { await page.goto('https://playwright.dev/'); @@ -16,3 +17,24 @@ test('get started link', async ({ page }) => { // Expects page to have a heading with the name of Installation. await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible(); }); + +test.describe('Positive login test', () => { + test('Login', async ({ request }) => { + + if (!validUserName || !validPassword) { + throw new Error('Username or password is undefined'); + } + const response = await request.get('https://petstore.swagger.io/v2/user/login', { + + params: { + username: validUserName, + password: validPassword, + }, + }); + + expect(response.status()).toBe(200); + + const responseBody = await response.json(); + console.log('Login response:', responseBody); + }); +}); \ No newline at end of file