File tree Expand file tree Collapse file tree 3 files changed +41
-18
lines changed
Expand file tree Collapse file tree 3 files changed +41
-18
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import { Browser , Page , BrowserContext } from "@playwright/test" ;
2+ import * as fs from "node:fs" ;
3+
4+ export async function loginToWordPress ( browser : Browser , storagePath = "tests-browser-state.json" ) {
5+ // Skip login if state already exists
6+ if ( fs . existsSync ( storagePath ) ) return ;
7+
8+ const context = await browser . newContext ( ) ;
9+ const page = await context . newPage ( ) ;
10+
11+ await page . goto ( "/wp-login.php" ) ;
12+ await page . fill ( "#user_login" , "your-username" ) ;
13+ await page . fill ( "#user_pass" , "your-password" ) ;
14+ await page . click ( "#wp-submit" ) ;
15+
16+ await page . waitForURL ( "**/wp-admin/**" ) ;
17+
18+ await context . storageState ( { path : storagePath } ) ;
19+ await context . close ( ) ;
20+ }
21+
22+ export async function createLoggedInPage (
23+ browser : Browser ,
24+ storagePath = "storage/wordpress-auth.json"
25+ ) : Promise < { context : BrowserContext ; page : Page } > {
26+ const context = await browser . newContext ( { storageState : storagePath } ) ;
27+ const page = await context . newPage ( ) ;
28+ return { context, page } ;
29+ }
Original file line number Diff line number Diff line change 1+ import { test , expect } from "@playwright/test" ;
2+
3+ test . beforeAll ( async ( { browser } ) => {
4+ await loginToWordPress ( browser ) ;
5+ } ) ;
6+
7+ test ( "Access dashboard" , async ( { browser } ) => {
8+ const { page } = await createLoggedInPage ( browser ) ;
9+
10+ await page . goto ( "/wp-admin/" ) ;
11+ await expect ( page ) . toHaveURL ( / w p - a d m i n / ) ;
12+ } ) ;
You can’t perform that action at this time.
0 commit comments