@@ -17,7 +17,8 @@ export interface TestPageType<T> {
17
17
waitForResponse : ( ) => Promise < void > ;
18
18
waitForNavigation : ( ) => Promise < void > ;
19
19
waitFor : ( milliseconds : number ) => Promise < void > ;
20
- pageObjects : PageObjects < T > ;
20
+
21
+ pageObjects ?: PageObjects < T > ;
21
22
}
22
23
23
24
type PageObjects < T > = { [ P in keyof T ] : T [ P ] } ;
@@ -28,17 +29,15 @@ export interface TestPageConfig<T> {
28
29
}
29
30
30
31
export class TestPage < T > implements TestPageType < T > {
31
- pageObjects : PageObjects < T > = null ;
32
- private page : Page = null ;
33
- private pageUrl : string = null ;
32
+ pageObjects ? : PageObjects < T > ;
33
+ private page ? : Page ;
34
+ private pageUrl ? : string ;
34
35
35
36
constructor ( config : TestPageConfig < T > ) {
36
37
if ( config . url ) {
37
38
this . pageUrl = `${ constants . baseUrl } ${ config . url } ` ;
38
39
}
39
- if ( config . pageObjects ) {
40
- this . pageObjects = config . pageObjects ;
41
- }
40
+ this . pageObjects = config . pageObjects ;
42
41
}
43
42
44
43
init = async ( page : Page ) : Promise < void > => {
@@ -59,7 +58,7 @@ export class TestPage<T> implements TestPageType<T> {
59
58
this . throwIfNotInitialized ( ) ;
60
59
61
60
console . log ( 'Trying to navigate to:' , this . pageUrl ) ;
62
- await this . page . goto ( this . pageUrl ) ;
61
+ await this . page ! . goto ( this . pageUrl ! ) ;
63
62
} ;
64
63
65
64
expectSelector = async ( config : ExpectSelectorConfig ) : Promise < void > => {
@@ -75,19 +74,19 @@ export class TestPage<T> implements TestPageType<T> {
75
74
waitForResponse = async ( ) : Promise < void > => {
76
75
this . throwIfNotInitialized ( ) ;
77
76
78
- await this . page . waitForResponse ( response => response . url ( ) === this . pageUrl && response . status ( ) === 200 ) ;
77
+ await this . page ! . waitForResponse ( response => response . url ( ) === this . pageUrl && response . status ( ) === 200 ) ;
79
78
} ;
80
79
81
80
waitForNavigation = async ( ) : Promise < void > => {
82
81
this . throwIfNotInitialized ( ) ;
83
82
84
- await this . page . waitForNavigation ( ) ;
83
+ await this . page ! . waitForNavigation ( ) ;
85
84
} ;
86
85
87
86
getUrl = async ( ) : Promise < string > => {
88
87
this . throwIfNotInitialized ( ) ;
89
88
90
- return await this . page . url ( ) ;
89
+ return await this . page ! . url ( ) ;
91
90
} ;
92
91
93
92
getUrlWithoutBaseUrl = async ( ) : Promise < string > => {
@@ -101,7 +100,7 @@ export class TestPage<T> implements TestPageType<T> {
101
100
waitFor = async ( milliseconds : number ) => {
102
101
this . throwIfNotInitialized ( ) ;
103
102
104
- await this . page . waitFor ( milliseconds ) ;
103
+ await this . page ! . waitFor ( milliseconds ) ;
105
104
} ;
106
105
107
106
private throwIfNotInitialized = ( ) => {
0 commit comments