File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { expect } from '@playwright/test' ;
22import type { Page } from '@playwright/test' ;
33
4+ import type { NavigateArgs , RouteTo } from '../helpers/types' ;
5+
46export abstract class RootPage {
57 readonly $ref : Page ;
6- protected abstract readonly defaultUrl : string ;
78
89 constructor ( page : Page ) {
910 this . $ref = page ;
@@ -13,8 +14,17 @@ export abstract class RootPage {
1314 return expect ( this . $ref ) ;
1415 }
1516
16- async goto ( ) {
17- await this . $ref . goto ( this . defaultUrl ) ;
18- await this . $ref . waitForURL ( this . defaultUrl ) ;
17+ protected getUrlWithParams < TPath extends RouteTo > ( ...args : NavigateArgs < TPath > ) {
18+ let url : string = args [ 0 ] ;
19+ if ( args [ 1 ] ) {
20+ Object . entries ( args [ 1 ] ) . forEach ( ( [ key , value ] ) => {
21+ url = url . replace ( '$' + key , String ( value ) ) ;
22+ } ) ;
23+ }
24+ return url ;
25+ }
26+
27+ async goto < TPath extends RouteTo > ( ...args : NavigateArgs < TPath > ) : Promise < void > {
28+ await this . $ref . goto ( this . getUrlWithParams ( ...args ) ) ;
1929 }
2030}
Original file line number Diff line number Diff line change 1+ import type { Locator , Page } from '@playwright/test' ;
2+
3+ import { RootPage } from './__root.page' ;
4+
5+ export abstract class AppPage extends RootPage {
6+ readonly sidebar : Locator ;
7+
8+ constructor ( page : Page ) {
9+ super ( page ) ;
10+ this . sidebar = page . getByTestId ( 'sidebar' ) ;
11+ }
12+ }
You can’t perform that action at this time.
0 commit comments