1
- import { expect , test , chromium } from '@playwright/test' ;
2
-
3
- const chromium_flags = [ '--enable-features=SharedArrayBuffer' ] ;
1
+ import { expect , test } from '@playwright/test' ;
4
2
5
3
const editor_selector = 'div.monaco-scrollable-element.editor-scrollable' ;
6
4
const editor_focus_selector = 'textarea.inputarea.monaco-mouse-cursor-text' ;
7
5
const iframe_selector = 'iframe[src*="webcontainer.io/"]' ;
8
6
9
- test ( 'focus management: the editor keeps focus when iframe is loaded' , async ( ) => {
10
- const context = await chromium . launchPersistentContext ( '' , { args : chromium_flags } ) ;
11
- const page = context . pages ( ) [ 0 ] ;
7
+ test ( 'focus management: the editor keeps focus when iframe is loaded' , async ( { page } ) => {
12
8
await page . bringToFront ( ) ;
13
9
14
10
await page . goto ( '/tutorial/your-first-component' ) ;
@@ -27,13 +23,9 @@ test('focus management: the editor keeps focus when iframe is loaded', async ()
27
23
28
24
// expect focus to be on the editor
29
25
await expect ( page . locator ( editor_focus_selector ) ) . toBeFocused ( ) ;
30
-
31
- await context . close ( ) ;
32
26
} ) ;
33
27
34
- test ( 'focus management: input inside the iframe gets focus when clicking it' , async ( ) => {
35
- const context = await chromium . launchPersistentContext ( '' , { args : chromium_flags } ) ;
36
- const page = context . pages ( ) [ 0 ] ;
28
+ test ( 'focus management: input inside the iframe gets focus when clicking it' , async ( { page } ) => {
37
29
await page . bringToFront ( ) ;
38
30
39
31
await page . goto ( '/tutorial/named-form-actions' ) ;
@@ -49,21 +41,19 @@ test('focus management: input inside the iframe gets focus when clicking it', as
49
41
50
42
// then, click a input in the iframe
51
43
const input = iframe . locator ( 'input[name="description"]' ) ;
52
- await input . click ( { delay : 500 } ) ;
44
+ await input . click ( { delay : 1000 } ) ;
53
45
54
46
// wait a little, because there may be a script that manipulates focus
55
47
await page . waitForTimeout ( 1000 ) ;
56
48
57
49
// expect focus to be on the input in the iframe, not the editor.
58
50
await expect ( input ) . toBeFocused ( ) ;
59
51
await expect ( page . locator ( editor_focus_selector ) ) . not . toBeFocused ( ) ;
60
-
61
- await context . close ( ) ;
62
52
} ) ;
63
53
64
- test ( 'focus management: body inside the iframe gets focus when clicking a link inside the iframe' , async ( ) => {
65
- const context = await chromium . launchPersistentContext ( '' , { args : chromium_flags } ) ;
66
- const page = context . pages ( ) [ 0 ] ;
54
+ test ( 'focus management: body inside the iframe gets focus when clicking a link inside the iframe' , async ( {
55
+ page
56
+ } ) => {
67
57
await page . bringToFront ( ) ;
68
58
69
59
await page . goto ( '/tutorial/layouts' ) ;
@@ -88,13 +78,9 @@ test('focus management: body inside the iframe gets focus when clicking a link i
88
78
89
79
// expect focus to be on body in the iframe, not the editor.
90
80
await expect ( iframe . locator ( 'body' ) ) . toBeFocused ( ) ;
91
-
92
- await context . close ( ) ;
93
81
} ) ;
94
82
95
- test ( 'focus management: the editor keeps focus while typing' , async ( ) => {
96
- const context = await chromium . launchPersistentContext ( '' , { args : chromium_flags } ) ;
97
- const page = context . pages ( ) [ 0 ] ;
83
+ test ( 'focus management: The editor keeps focus while typing' , async ( { page } ) => {
98
84
await page . bringToFront ( ) ;
99
85
100
86
await page . goto ( '/tutorial/your-first-component' ) ;
@@ -114,7 +100,7 @@ test('focus management: the editor keeps focus while typing', async () => {
114
100
await page . waitForTimeout ( 500 ) ;
115
101
116
102
// type the code as a person would do it manually
117
- await page . keyboard . type ( ` export let data;` , { delay : 100 } ) ;
103
+ await page . keyboard . type ( ` export let data;` , { delay : 150 } ) ;
118
104
119
105
// wait a little, because there may be a script that manipulates focus
120
106
await page . waitForTimeout ( 1000 ) ;
@@ -125,6 +111,4 @@ test('focus management: the editor keeps focus while typing', async () => {
125
111
const expected = '<script>\n export let data;\n</script>\n<h1>Hello world!</h1>' ;
126
112
127
113
expect ( received ) . toBe ( expected ) ;
128
-
129
- await context . close ( ) ;
130
114
} ) ;
0 commit comments