14
14
* limitations under the License.
15
15
*/
16
16
17
- const { USES_HOOKS } = require ( './utils' ) . testOptions ( browserType ) ;
17
+ const { FFOX , CHROMIUM , WEBKIT , USES_HOOKS } = require ( './utils' ) . testOptions ( browserType ) ;
18
18
19
19
class WritableBuffer {
20
20
constructor ( ) {
@@ -56,16 +56,41 @@ describe.skip(USES_HOOKS)('Recorder', function() {
56
56
state . context = await state . browser . newContext ( ) ;
57
57
state . output = new WritableBuffer ( ) ;
58
58
const debugController = state . context . _initDebugModeForTest ( { recorderOutput : state . output } ) ;
59
+ state . page = await state . context . newPage ( ) ;
60
+ state . setContent = async ( content ) => {
61
+ await state . page . setContent ( content ) ;
62
+ await debugController . ensureInstalledInFrameForTest ( state . page . mainFrame ( ) ) ;
63
+ } ;
59
64
} ) ;
60
-
65
+
61
66
afterEach ( async state => {
62
67
await state . context . close ( ) ;
63
68
} ) ;
64
-
65
- it ( 'should click' , async function ( { context, output, server} ) {
66
- const page = await context . newPage ( ) ;
69
+
70
+ it ( 'should click' , async function ( { page, output, setContent, server} ) {
71
+ await page . goto ( server . EMPTY_PAGE ) ;
72
+ await setContent ( `<button onclick="console.log('click')">Submit</button>` ) ;
73
+ const [ message ] = await Promise . all ( [
74
+ page . waitForEvent ( 'console' ) ,
75
+ output . waitFor ( 'click' ) ,
76
+ page . dispatchEvent ( 'button' , 'click' , { detail : 1 } )
77
+ ] ) ;
78
+ expect ( output . text ( ) ) . toContain ( `
79
+ // Click text="Submit"
80
+ await page.click('text="Submit"');` ) ;
81
+ expect ( message . text ( ) ) . toBe ( 'click' ) ;
82
+ } ) ;
83
+
84
+ it ( 'should click after document.open' , async function ( { page, output, setContent, server} ) {
67
85
await page . goto ( server . EMPTY_PAGE ) ;
68
- await page . setContent ( `<button onclick="console.log('click')">Submit</button>` ) ;
86
+ await setContent ( `` ) ;
87
+ await page . evaluate ( ( ) => {
88
+ document . open ( ) ;
89
+ document . write ( `<button onclick="console.log('click')">Submit</button>` ) ;
90
+ document . close ( ) ;
91
+ // Give it time to refresh. See Recorder for details.
92
+ return new Promise ( f => setTimeout ( f , 1000 ) ) ;
93
+ } ) ;
69
94
const [ message ] = await Promise . all ( [
70
95
page . waitForEvent ( 'console' ) ,
71
96
output . waitFor ( 'click' ) ,
@@ -77,10 +102,9 @@ describe.skip(USES_HOOKS)('Recorder', function() {
77
102
expect ( message . text ( ) ) . toBe ( 'click' ) ;
78
103
} ) ;
79
104
80
- it ( 'should fill' , async function ( { context, output, server} ) {
81
- const page = await context . newPage ( ) ;
105
+ it ( 'should fill' , async function ( { page, output, setContent, server} ) {
82
106
await page . goto ( server . EMPTY_PAGE ) ;
83
- await page . setContent ( `<input id="input" name="name" oninput="console.log(input.value)"></input>` ) ;
107
+ await setContent ( `<input id="input" name="name" oninput="console.log(input.value)"></input>` ) ;
84
108
const [ message ] = await Promise . all ( [
85
109
page . waitForEvent ( 'console' ) ,
86
110
output . waitFor ( 'fill' ) ,
@@ -92,10 +116,9 @@ describe.skip(USES_HOOKS)('Recorder', function() {
92
116
expect ( message . text ( ) ) . toBe ( 'John' ) ;
93
117
} ) ;
94
118
95
- it ( 'should press' , async function ( { context, output, server} ) {
96
- const page = await context . newPage ( ) ;
119
+ it ( 'should press' , async function ( { page, output, setContent, server} ) {
97
120
await page . goto ( server . EMPTY_PAGE ) ;
98
- await page . setContent ( `<input name="name" onkeypress="console.log('press')"></input>` ) ;
121
+ await setContent ( `<input name="name" onkeypress="console.log('press')"></input>` ) ;
99
122
const [ message ] = await Promise . all ( [
100
123
page . waitForEvent ( 'console' ) ,
101
124
output . waitFor ( 'press' ) ,
@@ -107,10 +130,9 @@ describe.skip(USES_HOOKS)('Recorder', function() {
107
130
expect ( message . text ( ) ) . toBe ( 'press' ) ;
108
131
} ) ;
109
132
110
- it ( 'should check' , async function ( { context, output, server} ) {
111
- const page = await context . newPage ( ) ;
133
+ it ( 'should check' , async function ( { page, output, setContent, server} ) {
112
134
await page . goto ( server . EMPTY_PAGE ) ;
113
- await page . setContent ( `<input id="checkbox" type="checkbox" name="accept" onchange="console.log(checkbox.checked)"></input>` ) ;
135
+ await setContent ( `<input id="checkbox" type="checkbox" name="accept" onchange="console.log(checkbox.checked)"></input>` ) ;
114
136
const [ message ] = await Promise . all ( [
115
137
page . waitForEvent ( 'console' ) ,
116
138
output . waitFor ( 'check' ) ,
@@ -123,10 +145,9 @@ describe.skip(USES_HOOKS)('Recorder', function() {
123
145
expect ( message . text ( ) ) . toBe ( "true" ) ;
124
146
} ) ;
125
147
126
- it ( 'should uncheck' , async function ( { context, output, server} ) {
127
- const page = await context . newPage ( ) ;
148
+ it ( 'should uncheck' , async function ( { page, output, setContent, server} ) {
128
149
await page . goto ( server . EMPTY_PAGE ) ;
129
- await page . setContent ( `<input id="checkbox" type="checkbox" checked name="accept" onchange="console.log(checkbox.checked)"></input>` ) ;
150
+ await setContent ( `<input id="checkbox" type="checkbox" checked name="accept" onchange="console.log(checkbox.checked)"></input>` ) ;
130
151
const [ message ] = await Promise . all ( [
131
152
page . waitForEvent ( 'console' ) ,
132
153
output . waitFor ( 'uncheck' ) ,
@@ -138,10 +159,9 @@ describe.skip(USES_HOOKS)('Recorder', function() {
138
159
expect ( message . text ( ) ) . toBe ( "false" ) ;
139
160
} ) ;
140
161
141
- it ( 'should select' , async function ( { context, output, server} ) {
142
- const page = await context . newPage ( ) ;
162
+ it ( 'should select' , async function ( { page, output, setContent, server} ) {
143
163
await page . goto ( server . EMPTY_PAGE ) ;
144
- await page . setContent ( '<select id="age" onchange="console.log(age.selectedOptions[0].value)"><option value="1"><option value="2"></select>' ) ;
164
+ await setContent ( '<select id="age" onchange="console.log(age.selectedOptions[0].value)"><option value="1"><option value="2"></select>' ) ;
145
165
const [ message ] = await Promise . all ( [
146
166
page . waitForEvent ( 'console' ) ,
147
167
output . waitFor ( 'select' ) ,
@@ -153,10 +173,9 @@ describe.skip(USES_HOOKS)('Recorder', function() {
153
173
expect ( message . text ( ) ) . toBe ( "2" ) ;
154
174
} ) ;
155
175
156
- it ( 'should await popup' , async function ( { context, output, server} ) {
157
- const page = await context . newPage ( ) ;
176
+ it ( 'should await popup' , async function ( { context, page, output, setContent, server} ) {
158
177
await page . goto ( server . EMPTY_PAGE ) ;
159
- await page . setContent ( '<a target=_blank rel=noopener href="/popup/popup.html">link</a>' ) ;
178
+ await setContent ( '<a target=_blank rel=noopener href="/popup/popup.html">link</a>' ) ;
160
179
const [ popup ] = await Promise . all ( [
161
180
context . waitForEvent ( 'page' ) ,
162
181
output . waitFor ( 'waitForEvent' ) ,
@@ -171,10 +190,9 @@ describe.skip(USES_HOOKS)('Recorder', function() {
171
190
expect ( popup . url ( ) ) . toBe ( `${ server . PREFIX } /popup/popup.html` ) ;
172
191
} ) ;
173
192
174
- it ( 'should await navigation' , async function ( { context, output, server} ) {
175
- const page = await context . newPage ( ) ;
193
+ it ( 'should await navigation' , async function ( { page, output, setContent, server} ) {
176
194
await page . goto ( server . EMPTY_PAGE ) ;
177
- await page . setContent ( `<a onclick="setTimeout(() => window.location.href='${ server . PREFIX } /popup/popup.html', 1000)">link</a>` ) ;
195
+ await setContent ( `<a onclick="setTimeout(() => window.location.href='${ server . PREFIX } /popup/popup.html', 1000)">link</a>` ) ;
178
196
await Promise . all ( [
179
197
page . waitForNavigation ( ) ,
180
198
output . waitFor ( 'waitForNavigation' ) ,
0 commit comments