@@ -15,19 +15,9 @@ import {
15
15
import * as path from 'path' ;
16
16
import { LeftBarItems } from '../enums/left-bar-items.enum' ;
17
17
import { expect } from '@playwright/test' ;
18
+ import { Application } from './application.pages' ;
18
19
19
- export class VSCode {
20
- // TODO (@abrugaro) find a better place for constants
21
- public static SCREENSHOTS_FOLDER = 'tests-output/screenshots' ;
22
-
23
- private readonly vscodeApp ?: ElectronApplication ;
24
- private readonly window ?: Page ;
25
-
26
- private constructor ( vscodeApp : ElectronApplication , window : Page ) {
27
- this . vscodeApp = vscodeApp ;
28
- this . window = window ;
29
- }
30
-
20
+ export class VSCode extends Application {
31
21
public static async open ( workspaceDir : string ) {
32
22
const vscodeExecutablePath = getVscodeExecutablePath ( ) ;
33
23
const vscodeApp = await electron . launch ( {
@@ -113,25 +103,15 @@ export class VSCode {
113
103
*/
114
104
public async closeVSCode ( ) : Promise < void > {
115
105
try {
116
- if ( this . vscodeApp ) {
117
- await this . vscodeApp . close ( ) ;
106
+ if ( this . app ) {
107
+ await this . app . close ( ) ;
118
108
console . log ( 'VSCode closed successfully.' ) ;
119
109
}
120
110
} catch ( error ) {
121
111
console . error ( 'Error closing VSCode:' , error ) ;
122
112
}
123
113
}
124
114
125
- /**
126
- * Returns the main window for further interactions.
127
- */
128
- public getWindow ( ) : Page {
129
- if ( ! this . window ) {
130
- throw new Error ( 'VSCode window is not initialized.' ) ;
131
- }
132
- return this . window ;
133
- }
134
-
135
115
/**
136
116
* Iterates through all frames and returns the
137
117
* server status panel frame .
@@ -177,12 +157,8 @@ export class VSCode {
177
157
const window = this . window ;
178
158
await this . executeQuickCommand ( 'sources and targets' ) ;
179
159
await this . waitDefault ( ) ;
180
- await window . screenshot ( {
181
- path : `${ VSCode . SCREENSHOTS_FOLDER } /debug-target.png` ,
182
- } ) ;
183
160
const targetInput = window . getByPlaceholder ( 'Choose one or more target' ) ;
184
- await this . waitDefault ( ) ;
185
- await expect ( targetInput ) . toBeVisible ( ) ;
161
+ await expect ( targetInput ) . toBeVisible ( { timeout : 30000 } ) ;
186
162
for ( const target of targets ) {
187
163
await targetInput . fill ( target ) ;
188
164
await this . waitDefault ( ) ;
@@ -192,7 +168,6 @@ export class VSCode {
192
168
. click ( ) ;
193
169
await this . waitDefault ( ) ;
194
170
}
195
-
196
171
await this . waitDefault ( ) ;
197
172
await targetInput . press ( 'Enter' ) ;
198
173
await this . waitDefault ( ) ;
@@ -231,7 +206,7 @@ export class VSCode {
231
206
const window = this . getWindow ( ) ;
232
207
233
208
const navLi = window . locator ( `a[aria-label^="${ name } "]` ) . locator ( '..' ) ;
234
-
209
+ await expect ( navLi ) . toBeVisible ( ) ;
235
210
if ( ( await navLi . getAttribute ( 'aria-expanded' ) ) === 'false' ) {
236
211
await navLi . click ( ) ;
237
212
}
@@ -250,10 +225,10 @@ export class VSCode {
250
225
public async startServer ( ) : Promise < void > {
251
226
await this . openAnalysisView ( ) ;
252
227
const analysisView = await this . getAnalysisIframe ( ) ;
253
- await this . waitDefault ( ) ;
254
228
if (
255
229
! ( await analysisView . getByRole ( 'button' , { name : 'Stop' } ) . isVisible ( ) )
256
230
) {
231
+ await analysisView . getByRole ( 'button' , { name : 'Start' } ) . isVisible ( ) ;
257
232
await analysisView . getByRole ( 'button' , { name : 'Start' } ) . click ( ) ;
258
233
await analysisView . getByRole ( 'button' , { name : 'Stop' } ) . isVisible ( ) ;
259
234
}
@@ -314,20 +289,4 @@ export class VSCode {
314
289
. getByTitle ( 'Resolution Details' )
315
290
. contentFrame ( ) ;
316
291
}
317
-
318
- // TODO create parent class and move generic functions there
319
- public async pasteContent ( content : string ) {
320
- await this . vscodeApp . evaluate ( ( { clipboard } , content ) => {
321
- clipboard . writeText ( content ) ;
322
- } , content ) ;
323
- await this . window . keyboard . press ( 'Control+v' ) ;
324
- }
325
-
326
- /**
327
- * Even with Playwright default waiting for actionability, in Electron,
328
- * Playwright tries to perform some actions before the elements are ready to handle those actions
329
- */
330
- public async waitDefault ( ) {
331
- await this . window . waitForTimeout ( process . env . CI ? 5000 : 500 ) ;
332
- }
333
292
}
0 commit comments