Skip to content

Commit 2904791

Browse files
committed
Loading baseURL from your .env files for consistency.
1 parent 4d6ba2d commit 2904791

File tree

9 files changed

+32
-10
lines changed

9 files changed

+32
-10
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,20 @@ e2e-playwright-framework/
9696
├── DockerFile.playwright # Dockerfile for CI/CD
9797
├── .github/workflows/ # GitHub Actions workflows
9898
```
99+
## 🌐 Overriding baseURL
99100

101+
- By default, `baseURL` is loaded from your environment file (e.g., `env/.env.dev1`).
102+
- To override for a specific run, set the `BASE_URL` variable:
103+
104+
```sh
105+
BASE_URL=https://another-url.com npm test
106+
```
107+
108+
- Or use a different environment:
109+
110+
```sh
111+
TEST_ENV=dev1 npm test
112+
```
100113
---
101114

102115
## ✅ GitHub Actions CI/CD
@@ -148,6 +161,8 @@ This project uses **GitHub Actions** to automate test execution and reporting.
148161

149162
---
150163

164+
165+
151166
## 📄 License
152167

153168
MIT © 2025 Ramakrishna Jangatisetty

env/.env.dev1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
URL=https://saucedemo.com
1+
BASE_URL=https://saucedemo.com
22
USERNAME=standard_user
33
PASSWORD=secret_sauce

env/.env.dev2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
URL=https://saucedemo.com
1+
BASE_URL=https://saucedemo.com
22
USERNAME=standard_user
33
PASSWORD=secret_sauce

env/.env.qa1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
URL=https://saucedemo.com
1+
BASE_URL=https://saucedemo.com
22
USERNAME=standard_user
33
PASSWORD=secret_sauce

env/.env.qa2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
URL=https://saucedemo.com
1+
BASE_URL=https://saucedemo.com
22
USERNAME=standard_user
33
PASSWORD=secret_sauce

global/test-run-context.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"testRunId": "run_20250628182021939",
3-
"startTime": "2025-06-28T18:20:21.939Z",
2+
"testRunId": "run_20250628215003653",
3+
"startTime": "2025-06-28T21:50:03.653Z",
44
"environment": "qa1",
55
"project": "e2e-playwright-typescript-framework",
66
"status": "in-progress"

pages/LoginPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class LoginPage extends BasePage {
2121
}
2222

2323
async goto() {
24-
await this.page.goto(config.url)
24+
await this.page.goto(config.baseUrl)
2525
}
2626

2727
constructor(page: Page) {

playwright.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { defineConfig } from '@playwright/test';
2+
import * as dotenvFlow from 'dotenv-flow';
23
import path from 'path';
34

5+
// Load env variables before config is defined
6+
dotenvFlow.config({
7+
path: path.resolve(__dirname, 'env'),
8+
node_env: process.env.TEST_ENV || 'local'
9+
});
10+
411
export default defineConfig({
512
testDir: './tests',
613
workers: 2,
@@ -24,4 +31,4 @@ export default defineConfig({
2431

2532
globalSetup: require.resolve('./global/setup.ts'),
2633
globalTeardown: require.resolve('./global/teardown.ts'),
27-
});
34+
});

utils/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dotenvFlow.config({
1010
});
1111

1212
interface TestConfig {
13-
url: string;
13+
baseUrl: string;
1414
username: string;
1515
password: string;
1616
}
@@ -23,7 +23,7 @@ function assertEnvVar(name: string, value: string | undefined): string {
2323
}
2424

2525
export const config: TestConfig = {
26-
url: assertEnvVar('URL', process.env.URL),
26+
baseUrl: assertEnvVar('URL', process.env.BASE_URL),
2727
username: assertEnvVar('USERNAME', process.env.USERNAME),
2828
password: assertEnvVar('PASSWORD', process.env.PASSWORD),
2929
};

0 commit comments

Comments
 (0)