Skip to content

Commit 587aba5

Browse files
committed
updated import and dot env
1 parent 22025f8 commit 587aba5

File tree

7 files changed

+29
-25
lines changed

7 files changed

+29
-25
lines changed

.github/workflows/playwright.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
name: Playwright Tests
22
on:
3-
push:
4-
branches: [ main ]
53
pull_request:
64
branches: [ main ]
75
jobs:

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"editor.formatOnSave": true,
3+
"editor.codeActionsOnSave": {
4+
"source.organizeImports": "always"
5+
},
36
"cSpell.words": [
47
"Ortoni"
58
]

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ check script section of package.json for more test commands
4141

4242

4343
TODO:
44-
- optimize reading env variables
4544
- add fixtures to optimize page imports
4645
- update readme file
46+
- optimize import path
4747

4848
## Sample Report:
4949
![Ortoni-Report](./samples/ortoni-report.png)

tests/helper/env.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { config } from 'dotenv';
2+
import { resolve } from 'path';
3+
4+
config({ path: resolve(process.cwd(), '.env') });
5+
6+
export default class ENV {
7+
public static readonly USERNAME = process.env.USERNAME as string;
8+
public static readonly PASSWORD = process.env.PASSWORD as string;
9+
}

tests/specs/admin/admin.spec.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import { test, expect } from 'playwright/test';
2-
import LandingPage from '../../pages/landing.page';
1+
import { expect, test } from 'playwright/test';
2+
import { userData } from '../../data/user';
3+
import ENV from '../../helper/env';
34
import AdminPage from '../../pages/admin.page';
4-
import LoginPage from '../../pages/login.page';
55
import { toastMessage } from '../../pages/component';
6-
import { userData } from '../../data/user';
7-
8-
import { config } from 'dotenv';
9-
config({ path: '.env' });
6+
import LandingPage from '../../pages/landing.page';
7+
import LoginPage from '../../pages/login.page';
108

119
test('validate admin page', async ({ page }) => {
1210
const loginPage = new LoginPage(page);
1311
await loginPage.open();
14-
await loginPage.login(process.env.USERNAME as string, process.env.PASSWORD as string);
12+
await loginPage.login(ENV.USERNAME, ENV.PASSWORD);
1513

1614
const landingPage = new LandingPage(page);
1715
await expect(landingPage.pageHeader).toBeVisible();

tests/specs/employee/addEmployee.spec.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import { test, expect } from 'playwright/test';
2-
import LandingPage from '../../pages/landing.page';
3-
import LoginPage from '../../pages/login.page';
4-
5-
import { config } from 'dotenv';
1+
import { expect, test } from 'playwright/test';
2+
import { createEmployeeData } from '../../data/employee';
3+
import ENV from '../../helper/env';
64
import { toastMessage } from '../../pages/component';
75
import EmployeePage from '../../pages/employee.page';
8-
import { createEmployeeData } from '../../data/employee';
9-
config({ path: '.env' });
6+
import LandingPage from '../../pages/landing.page';
7+
import LoginPage from '../../pages/login.page';
108

119
test('validate add employee', async ({ page }) => {
1210
const loginPage = new LoginPage(page);
1311
await loginPage.open();
14-
await loginPage.login(process.env.USERNAME as string, process.env.PASSWORD as string);
12+
await loginPage.login(ENV.USERNAME, ENV.PASSWORD);
1513

1614
const landingPage = new LandingPage(page);
1715
await expect(landingPage.pageHeader).toBeVisible();

tests/specs/login/login.spec.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { test, expect } from '@playwright/test';
2-
import LoginPage from '../../pages/login.page';
1+
import { expect, test } from '@playwright/test';
2+
import ENV from '../../helper/env';
33
import LandingPage from '../../pages/landing.page';
4-
5-
import { config } from 'dotenv';
6-
config({ path: '.env' });
4+
import LoginPage from '../../pages/login.page';
75

86
test.beforeEach('open app', async ({ page }) => {
97
const loginPage = new LoginPage(page);
@@ -18,7 +16,7 @@ test('company footer link', async ({ page }) => {
1816

1917
test('successful login', async ({ page }) => {
2018
const loginPage = new LoginPage(page);
21-
await loginPage.login(process.env.USERNAME as string, process.env.PASSWORD as string);
19+
await loginPage.login(ENV.USERNAME, ENV.PASSWORD);
2220

2321
const landingPage = new LandingPage(page);
2422
await expect(landingPage.pageHeader).toBeVisible();

0 commit comments

Comments
 (0)