8
8
Page
9
9
} from "@playwright/test"
10
10
import { AdminPage } from "./page_objects/adminPage"
11
+ require ( "dotenv" ) . config ( )
11
12
12
13
test . describe . serial ( "Admin Page" , ( ) => {
13
14
let browser : Browser
@@ -20,27 +21,43 @@ test.describe.serial("Admin Page", () => {
20
21
context = await browser . newContext ( )
21
22
page = await context . newPage ( )
22
23
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
27
28
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 )
29
44
await page . getByRole ( "button" , { name : "Log in / Sign up" } ) . click ( )
30
45
await page . getByRole ( "button" , { name : "Sign In" , exact : true } ) . click ( )
31
46
await page . fill ( 'input[name="email"]' , adminEmail )
32
47
await page . fill ( 'input[name="password"]' , adminPassword )
33
48
await page . click ( 'button[type="submit"]' )
34
49
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" )
36
53
} )
54
+
37
55
test . afterAll ( async ( ) => {
38
56
// Close the browser instance after all tests
39
57
await browser . close ( )
40
58
} )
41
59
42
60
test ( "should allow adding a report" , async ( ) => {
43
- // Create a report
44
61
const adminPage = new AdminPage ( page )
45
62
adminPage . gotoUserReportPage ( )
46
63
0 commit comments