@@ -15,13 +15,13 @@ export default class Page {
15
15
private constructor ( private webdriver : WebDriver ) { }
16
16
17
17
static async currentContext ( webdriver : WebDriver ) : Promise < Page > {
18
- await Page . waitForConsoleLoaded ( webdriver ) ;
18
+ await Page . waitForPageCompleted ( webdriver ) ;
19
19
return new Page ( webdriver ) ;
20
20
}
21
21
22
22
static async navigateTo ( webdriver : WebDriver , url : string ) : Promise < Page > {
23
23
await webdriver . navigate ( ) . to ( url ) ;
24
- await Page . waitForConsoleLoaded ( webdriver ) ;
24
+ await Page . waitForPageCompleted ( webdriver ) ;
25
25
return new Page ( webdriver ) ;
26
26
}
27
27
@@ -34,18 +34,19 @@ export default class Page {
34
34
35
35
async navigateTo ( url : string ) : Promise < Page > {
36
36
await this . webdriver . navigate ( ) . to ( url ) ;
37
- await Page . waitForConsoleLoaded ( this . webdriver ) ;
37
+ await Page . waitForPageCompleted ( this . webdriver ) ;
38
+
39
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 200 ) ) ;
40
+
38
41
return new Page ( this . webdriver ) ;
39
42
}
40
43
41
44
async showConsole ( ) : Promise < Console > {
42
- const iframe = this . webdriver . findElement (
43
- By . css ( "#vimvixen-console-frame" )
44
- ) ;
45
-
46
45
await this . sendKeys ( ":" ) ;
46
+ const iframe = this . webdriver . findElement ( By . id ( "vimvixen-console-frame" ) ) ;
47
47
await this . webdriver . wait ( until . elementIsVisible ( iframe ) ) ;
48
- await this . webdriver . switchTo ( ) . frame ( 0 ) ;
48
+
49
+ await this . webdriver . switchTo ( ) . frame ( iframe ) ;
49
50
await this . webdriver . wait ( until . elementLocated ( By . css ( "input" ) ) ) ;
50
51
return new Console ( this . webdriver ) ;
51
52
}
@@ -54,9 +55,8 @@ export default class Page {
54
55
const iframe = this . webdriver . findElement (
55
56
By . css ( "#vimvixen-console-frame" )
56
57
) ;
57
-
58
58
await this . webdriver . wait ( until . elementIsVisible ( iframe ) ) ;
59
- await this . webdriver . switchTo ( ) . frame ( 0 ) ;
59
+ await this . webdriver . switchTo ( ) . frame ( iframe ) ;
60
60
return new Console ( this . webdriver ) ;
61
61
}
62
62
@@ -113,14 +113,35 @@ export default class Page {
113
113
return hints ;
114
114
}
115
115
116
- private static async waitForConsoleLoaded ( webdriver : WebDriver ) {
116
+ private static async waitForPageCompleted (
117
+ webdriver : WebDriver
118
+ ) : Promise < void > {
119
+ this . waitForDocumentCompleted ( webdriver ) ;
120
+
117
121
const topFrame = await webdriver . executeScript ( ( ) => window . top === window ) ;
118
122
if ( ! topFrame ) {
119
123
return ;
120
124
}
125
+ // style tag is injected at end of add-on loading
126
+ await webdriver . wait ( until . elementLocated ( By . tagName ( "style" ) ) ) ;
127
+
128
+ const iframe = await webdriver . findElements (
129
+ By . id ( "vimvixen-console-frame" )
130
+ ) ;
131
+ if ( iframe . length === 0 ) {
132
+ return ;
133
+ }
134
+
135
+ await webdriver . switchTo ( ) . frame ( iframe [ 0 ] ) ;
136
+ await Page . waitForDocumentCompleted ( webdriver ) ;
137
+ await webdriver . switchTo ( ) . parentFrame ( ) ;
138
+ }
139
+
140
+ private static async waitForDocumentCompleted ( webdriver : WebDriver ) {
121
141
await webdriver . wait (
122
- until . elementLocated ( By . css ( "iframe.vimvixen-console-frame" ) )
142
+ async ( ) =>
143
+ ( await webdriver . executeScript ( "return document.readyState" ) ) ===
144
+ "complete"
123
145
) ;
124
- await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
125
146
}
126
147
}
0 commit comments