Skip to content

Commit 9f97a4e

Browse files
author
huanfeng
committed
Move the credentials to .env
1 parent c1860de commit 9f97a4e

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/playwright-report/
1515
/blob-report/
1616
/playwright/.cache/
17+
.env
1718

1819
.next/
1920
.eslintcache

playwright.config.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,21 @@ export default defineConfig({
3737
{
3838
name: "chromium",
3939
use: {
40-
...devices["Desktop Chrome"],
41-
// Use prepared auth state.
42-
storageState: "playwright/.auth/user.json"
40+
...devices["Desktop Chrome"]
4341
}
4442
},
4543

4644
{
4745
name: "firefox",
4846
use: {
49-
...devices["Desktop Firefox"],
50-
// Use prepared auth state.
51-
storageState: "playwright/.auth/user.json"
47+
...devices["Desktop Firefox"]
5248
}
5349
},
5450

5551
{
5652
name: "webkit",
5753
use: {
58-
...devices["Desktop Safari"],
59-
// Use prepared auth state.
60-
storageState: "playwright/.auth/user.json"
54+
...devices["Desktop Safari"]
6155
}
6256
}
6357

tests/e2e/adminPage.spec.ts

+24-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Page
99
} from "@playwright/test"
1010
import { AdminPage } from "./page_objects/adminPage"
11+
require("dotenv").config()
1112

1213
test.describe.serial("Admin Page", () => {
1314
let browser: Browser
@@ -20,27 +21,43 @@ test.describe.serial("Admin Page", () => {
2021
context = await browser.newContext()
2122
page = await context.newPage()
2223

23-
// Emulator admin account or Dev admin account
24-
const adminEmail =
25-
process.env.TEST_ADMIN_USERNAME ?? "[email protected]"
26-
const adminPassword = process.env.TEST_ADMIN_PASSWORD ?? "password"
24+
// Fetch the admin credentials and application URL from the environment variables
25+
const adminEmail = process.env.TEST_ADMIN_USERNAME
26+
const adminPassword = process.env.TEST_ADMIN_PASSWORD
27+
const url = process.env.APP_API_URL
2728

28-
await page.goto("http://localhost:3000")
29+
// Ensure admin credentials and URL are set, otherwise throw an error
30+
if (!adminEmail || !adminPassword) {
31+
throw new Error(
32+
"Admin credentials are not defined in the environment variables."
33+
)
34+
}
35+
36+
if (!url) {
37+
throw new Error(
38+
"URL credentials are not defined in the environment variables."
39+
)
40+
}
41+
42+
// Navigate to the application URL, perform login, and verify successful login
43+
await page.goto(url)
2944
await page.getByRole("button", { name: "Log in / Sign up" }).click()
3045
await page.getByRole("button", { name: "Sign In", exact: true }).click()
3146
await page.fill('input[name="email"]', adminEmail)
3247
await page.fill('input[name="password"]', adminPassword)
3348
await page.click('button[type="submit"]')
3449
await expect(page.getByAltText("profileMenu")).toBeVisible()
35-
await page.goto("http://localhost:3000/admin")
50+
51+
// Navigate to the admin page
52+
await page.goto(url + "/admin")
3653
})
54+
3755
test.afterAll(async () => {
3856
// Close the browser instance after all tests
3957
await browser.close()
4058
})
4159

4260
test("should allow adding a report", async () => {
43-
// Create a report
4461
const adminPage = new AdminPage(page)
4562
adminPage.gotoUserReportPage()
4663

0 commit comments

Comments
 (0)