forked from OpenLiberty/liberty-tools-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMavenTestDevModeActions.ts
More file actions
executable file
·511 lines (415 loc) · 24.2 KB
/
Copy pathMavenTestDevModeActions.ts
File metadata and controls
executable file
·511 lines (415 loc) · 24.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
/*
* IBM Confidential
* Copyright IBM Corp. 2023, 2026
*/
import { expect } from 'chai';
import { DefaultTreeItem, EditorView, SideBarView, ViewItem, ViewSection, VSBrowser, Workbench, WebDriver } from 'vscode-extension-tester';
import * as utils from './utils/testUtils';
import * as constants from './definitions/constants';
import { logger } from './utils/testLogger';
import path = require('path');
describe('Devmode action tests for Maven Project', () => {
let sidebar: SideBarView;
let section: ViewSection;
let menu: ViewItem[];
let item: DefaultTreeItem;
let tabs: string[];
let driver: WebDriver;
before(async function() {
this.timeout(30000);
driver = VSBrowser.instance.driver;
await VSBrowser.instance.openResources(utils.getMvnProjectPath());
await VSBrowser.instance.waitForWorkbench();
sidebar = new SideBarView();
});
afterEach(async function() {
this.timeout(10000); // Increase timeout for cleanup operations
// Close any open editors after each test
if (this.currentTest?.state === 'failed') {
const driver = VSBrowser.instance.driver;
const screenshot = await driver.takeScreenshot();
logger.error(`Test failed: ${this.currentTest.title}`);
}
try {
await new EditorView().closeAllEditors();
} catch (error) {
logger.error('Failed to close editors in afterEach', error);
}
// Clear terminal between tests to avoid confusion with old output
try {
const workbench = new Workbench();
await workbench.executeCommand('terminal clear');
} catch (error) {
logger.error('Failed to clear terminal in afterEach', error);
}
});
it('Find Liberty Tools in sidebar', async () => {
logger.testStart('Find Liberty Tools in sidebar');
try {
logger.step(1, 'Attempting to get Liberty Tools section');
section = await utils.getDashboardSection(sidebar);
logger.stepSuccess(1, 'Found Liberty Tools section');
logger.step(2, 'Validating sidebar is not undefined');
expect(section).not.undefined;
logger.testComplete('Find Liberty Tools in sidebar');
} catch (error) {
logger.testFailed('Find Liberty Tools in sidebar', error);
throw error;
}
}).timeout(60000);
it('Liberty Tools shows items - Maven', async () => {
logger.testStart('Liberty Tools shows items - Maven');
try {
logger.step(1, 'Getting dashboard section');
section = await utils.getDashboardSection(sidebar);
logger.stepSuccess(1, 'Dashboard section retrieved');
logger.step(2, 'Waiting for Liberty Tools to load');
await utils.waitForDashboardToLoad(section);
logger.stepSuccess(2, 'Liberty Tools loaded successfully');
logger.step(3, 'Getting visible items from section');
const menu = await utils.waitForCondition(async () => {
const items = await section.getVisibleItems();
if (items && items.length > 0) {
return items;
}
return;
}, 60);
logger.info(`Found ${menu.length} visible items in dashboard`);
expect(menu).not.empty;
logger.step(4, `Finding Maven project item: ${constants.MAVEN_PROJECT}`);
item = await utils.waitForCondition(async () => {
return await section.findItem(constants.MAVEN_PROJECT) as DefaultTreeItem;
}, 30);
logger.stepSuccess(4, 'Maven project item found');
expect(item).not.undefined;
logger.testComplete('Liberty Tools shows items - Maven');
} catch (error) {
logger.testFailed('Liberty Tools shows items - Maven', error);
throw error;
}
}).timeout(275000);
it('Start Maven project from Liberty Tools', async () => {
logger.testStart('Start Maven project from Liberty Tools');
try {
logger.step(1, 'Getting dashboard section and item');
section = await utils.getDashboardSection(sidebar);
item = await utils.getDashboardItem(section, constants.MAVEN_PROJECT);
logger.stepSuccess(1, 'Dashboard section and item retrieved');
logger.step(2, 'Launching dashboard start action');
await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION, constants.START_DASHBOARD_MAC_ACTION);
logger.step(3, 'Waiting for server to start');
const serverStartStatus = await utils.waitForServerStart(constants.SERVER_START_STRING);
if (!serverStartStatus) {
logger.error('Server started message not found in the terminal');
} else {
logger.stepSuccess(3, 'Server successfully started');
logger.step(4, 'Launching dashboard stop action');
await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
logger.step(5, 'Waiting for server to stop');
const serverStopStatus = await utils.waitForServerStop(constants.SERVER_STOP_STRING);
if (!serverStopStatus) {
logger.error('Server stopped message not found in the terminal');
} else {
logger.stepSuccess(5, 'Server stopped successfully');
}
expect(serverStopStatus).to.be.true;
}
expect(serverStartStatus).to.be.true;
logger.testComplete('Start Maven project from Liberty Tools');
} catch (error) {
logger.testFailed('Start Maven project from Liberty Tools', error);
throw error;
}
}).timeout(550000);
it('Start Maven with Docker from Liberty Tools', async () => {
logger.testStart('Start Maven with Docker from Liberty Tools');
if ((process.platform === 'darwin') || (process.platform === 'win32')) {
logger.skip(`Test skipped for platform: ${process.platform} (Docker test only runs on Linux)`);
return true;
}
try {
logger.step(1, 'Getting dashboard section and item');
section = await utils.getDashboardSection(sidebar);
item = await utils.getDashboardItem(section, constants.MAVEN_PROJECT);
logger.stepSuccess(1, 'Dashboard section and item retrieved');
logger.step(2, 'Launching dashboard start action with Docker');
await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION_WITHDOCKER, constants.START_DASHBOARD_MAC_ACTION_WITHDOCKER);
logger.step(3, 'Waiting for server to start in Docker container');
const serverStartStatus = await utils.waitForServerStart(constants.SERVER_START_STRING);
if (!serverStartStatus) {
logger.error('Server started message not found in the terminal');
} else {
logger.stepSuccess(3, 'Server successfully started in Docker container');
logger.step(4, 'Launching dashboard stop action');
await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
logger.step(5, 'Waiting for server to stop');
const serverStopStatus = await utils.waitForServerStop(constants.SERVER_STOP_STRING);
if (!serverStopStatus) {
logger.error('Server stopped message not found in the terminal');
} else {
logger.stepSuccess(5, 'Server stopped successfully');
}
expect(serverStopStatus).to.be.true;
}
expect(serverStartStatus).to.be.true;
logger.testComplete('Start Maven with Docker from Liberty Tools');
} catch (error) {
logger.testFailed('Start Maven with Docker from Liberty Tools', error);
throw error;
}
}).timeout(350000);
it('Run tests for Maven project', async () => {
logger.testStart('Run tests for Maven project');
try {
logger.step(1, 'Getting dashboard section and item');
section = await utils.getDashboardSection(sidebar);
item = await utils.getDashboardItem(section, constants.MAVEN_PROJECT);
logger.stepSuccess(1, 'Dashboard section and item retrieved');
logger.step(2, 'Launching dashboard start action');
await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION, constants.START_DASHBOARD_MAC_ACTION);
logger.step(3, 'Waiting for server to start');
const serverStartStatus = await utils.waitForServerStart(constants.SERVER_START_STRING);
if (!serverStartStatus) {
logger.error('Server started message not found in the terminal');
} else {
logger.stepSuccess(3, 'Server successfully started');
logger.step(4, 'Launching run tests dashboard action');
await utils.launchDashboardAction(item, constants.RUNTEST_DASHBOARD_ACTION, constants.RUNTEST_DASHBOARD_MAC_ACTION);
logger.step(5, 'Checking test execution status');
const testStatus = await utils.checkTestStatus(constants.MAVEN_RUN_TESTS_STRING);
logger.info(`Test status result: ${testStatus}`);
expect(testStatus).to.be.true;
logger.stepSuccess(5, 'Tests executed successfully');
logger.step(6, 'Launching dashboard stop action');
await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
logger.step(7, 'Waiting for server to stop');
const serverStopStatus = await utils.waitForServerStop(constants.SERVER_STOP_STRING);
if (!serverStopStatus) {
logger.error('Server stopped message not found in the terminal');
} else {
logger.stepSuccess(7, 'Server stopped successfully');
}
expect(serverStopStatus).to.be.true;
}
expect(serverStartStatus).to.be.true;
logger.testComplete('Run tests for Maven project');
} catch (error) {
logger.testFailed('Run tests for Maven project', error);
throw error;
}
}).timeout(350000);
it('Start Maven with options from Liberty Tools', async () => {
logger.testStart('Start Maven with options from Liberty Tools');
try {
logger.step(1, 'Getting dashboard section and item');
section = await utils.getDashboardSection(sidebar);
item = await utils.getDashboardItem(section, constants.MAVEN_PROJECT);
logger.stepSuccess(1, 'Dashboard section and item retrieved');
const reportPath = path.join(utils.getMvnProjectPath(), "target", "site", "failsafe-report.html");
const alternateReportPath = path.join(utils.getMvnProjectPath(), "target", "reports", "failsafe.html");
logger.info(`Primary report path: ${reportPath}`);
logger.info(`Alternate report path: ${alternateReportPath}`);
logger.step(2, 'Deleting existing test reports');
let deleteReport = await utils.deleteReports(reportPath);
let deleteAlternateReport = await utils.deleteReports(alternateReportPath);
logger.info(`Primary report deletion result: ${deleteReport}`);
logger.info(`Alternate report deletion result: ${deleteAlternateReport}`);
expect(deleteReport && deleteAlternateReport).to.be.true;
logger.step(3, 'Launching dashboard start action with custom parameters');
await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION_WITH_PARAM, constants.START_DASHBOARD_MAC_ACTION_WITH_PARAM);
logger.step(4, 'Setting custom parameter: -DhotTests=true');
await utils.setCustomParameter("-DhotTests=true");
logger.step(5, 'Waiting for server to start with parameters');
const serverStartStatus = await utils.waitForServerStart(constants.SERVER_START_STRING);
if (!serverStartStatus) {
logger.error('Server started with params message not found in terminal');
} else {
logger.stepSuccess(5, 'Server successfully started with custom parameters');
logger.step(6, 'Waiting for test report at primary or alternate location');
const checkFile = await utils.waitForTestReport(reportPath, alternateReportPath);
expect(checkFile).to.be.true;
logger.stepSuccess(6, 'Test report found');
logger.step(7, 'Launching dashboard stop action');
await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
logger.step(8, 'Waiting for server to stop');
const serverStopStatus = await utils.waitForServerStop(constants.SERVER_STOP_STRING);
if (!serverStopStatus) {
logger.error('Server stopped message not found in the terminal');
} else {
logger.stepSuccess(8, 'Server stopped successfully');
}
expect(serverStopStatus).to.be.true;
}
expect(serverStartStatus).to.be.true;
logger.testComplete('Start Maven with options from Liberty Tools');
} catch (error) {
logger.testFailed('Start Maven with options from Liberty Tools', error);
throw error;
}
}).timeout(350000);
it('Start Maven with history from Liberty Tools', async () => {
logger.testStart('Start Maven with history from Liberty Tools');
try {
logger.step(1, 'Getting dashboard section and item');
section = await utils.getDashboardSection(sidebar);
item = await utils.getDashboardItem(section, constants.MAVEN_PROJECT);
logger.stepSuccess(1, 'Dashboard section and item retrieved');
const reportPath = path.join(utils.getMvnProjectPath(), "target", "site", "failsafe-report.html");
const alternateReportPath = path.join(utils.getMvnProjectPath(), "target", "reports", "failsafe.html");
logger.info(`Primary report path: ${reportPath}`);
logger.info(`Alternate report path: ${alternateReportPath}`);
logger.step(2, 'Deleting existing test reports');
let deleteReport = await utils.deleteReports(reportPath);
let deleteAlternateReport = await utils.deleteReports(alternateReportPath);
logger.info(`Primary report deletion result: ${deleteReport}`);
logger.info(`Alternate report deletion result: ${deleteAlternateReport}`);
expect(deleteReport && deleteAlternateReport).to.be.true;
logger.step(3, 'Launching dashboard start action with parameters');
await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION_WITH_PARAM, constants.START_DASHBOARD_MAC_ACTION_WITH_PARAM);
logger.step(4, 'Choosing command from history: -DhotTests=true');
const foundCommand = await utils.chooseCmdFromHistory("-DhotTests=true");
logger.info(`Command found in history: ${foundCommand}`);
expect(foundCommand).to.be.true;
logger.step(5, 'Waiting for server to start with historical parameters');
const serverStartStatus = await utils.waitForServerStart(constants.SERVER_START_STRING);
if (!serverStartStatus) {
logger.error('Server started with params message not found in the terminal');
} else {
logger.stepSuccess(5, 'Server successfully started with historical parameters');
logger.step(6, 'Waiting for test report at primary or alternate location');
const checkFile = await utils.waitForTestReport(reportPath, alternateReportPath);
expect(checkFile).to.be.true;
logger.stepSuccess(6, 'Test report found');
logger.step(7, 'Launching dashboard stop action');
await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
logger.step(8, 'Waiting for server to stop');
const serverStopStatus = await utils.waitForServerStop(constants.SERVER_STOP_STRING);
if (!serverStopStatus) {
logger.error('Server stopped message not found in terminal');
} else {
logger.stepSuccess(8, 'Server stopped successfully');
}
expect(serverStopStatus).to.be.true;
}
expect(serverStartStatus).to.be.true;
logger.testComplete('Start Maven with history from Liberty Tools');
} catch (error) {
logger.testFailed('Start Maven with history from Liberty Tools', error);
throw error;
}
}).timeout(550000);
it('View unit test report for Maven project', async () => {
logger.testStart('View unit test report for Maven project');
try {
logger.step(1, 'Getting dashboard section and item');
section = await utils.getDashboardSection(sidebar);
item = await utils.getDashboardItem(section, constants.MAVEN_PROJECT);
logger.stepSuccess(1, 'Dashboard section and item retrieved');
logger.step(2, 'Launching view unit test report dashboard action');
await utils.launchDashboardAction(item, constants.UTR_DASHABOARD_ACTION, constants.UTR_DASHABOARD_MAC_ACTION);
logger.step(3, 'Waiting for unit test report tab to open');
tabs = await utils.waitForEditorTab(constants.SUREFIRE_REPORT_TITLE);
logger.info(`Open editor tabs: ${tabs.join(', ')}`);
logger.step(4, `Checking if unit test report tab is open: ${constants.SUREFIRE_REPORT_TITLE}`);
const reportFound = tabs.indexOf(constants.SUREFIRE_REPORT_TITLE) > -1;
logger.info(`Unit test report found: ${reportFound}`);
expect(reportFound, "Unit test report not found").to.equal(true);
logger.stepSuccess(4, 'Unit test report tab is open');
logger.step(5, 'Closing unit test report tab');
const editorView = new EditorView();
await editorView.closeEditor(constants.SUREFIRE_REPORT_TITLE);
logger.stepSuccess(5, 'Unit test report tab closed');
logger.testComplete('View unit test report for Maven project');
} catch (error) {
logger.testFailed('View unit test report for Maven project', error);
throw error;
}
}).timeout(10000);
it('View integration test report for Maven project', async () => {
logger.testStart('View integration test report for Maven project');
try {
logger.step(1, 'Getting dashboard section and item');
section = await utils.getDashboardSection(sidebar);
item = await utils.getDashboardItem(section, constants.MAVEN_PROJECT);
logger.stepSuccess(1, 'Dashboard section and item retrieved');
logger.step(2, 'Launching view integration test report dashboard action');
await utils.launchDashboardAction(item, constants.ITR_DASHBOARD_ACTION, constants.ITR_DASHBOARD_MAC_ACTION);
logger.step(3, 'Waiting for integration test report tab to open');
tabs = await utils.waitForEditorTab(constants.FAILSAFE_REPORT_TITLE);
logger.info(`Open editor tabs: ${tabs.join(', ')}`);
logger.step(4, `Checking if integration test report tab is open: ${constants.FAILSAFE_REPORT_TITLE}`);
const reportFound = tabs.indexOf(constants.FAILSAFE_REPORT_TITLE) > -1;
logger.info(`Integration test report found: ${reportFound}`);
expect(reportFound, "Integration test report not found").to.equal(true);
logger.stepSuccess(4, 'Integration test report tab is open');
logger.testComplete('View integration test report for Maven project');
} catch (error) {
logger.testFailed('View integration test report for Maven project', error);
throw error;
}
}).timeout(90000); // Increased to 90 seconds to allow time for report generation and tab opening
/**
* All future test cases should be written before the test that attaches the debugger, as this will switch the UI to the debugger view.
* If, for any reason, a test case needs to be written after the debugger test, ensure that the UI is switched back to the explorer view before executing the subsequent tests.
*/
it('Attach debugger for start with custom parameter event', async () => {
logger.testStart('Attach debugger for start with custom parameter event');
let isServerRunning: Boolean = true;
let attachStatus: Boolean = false;
try {
logger.step(1, 'Getting dashboard section and item');
section = await utils.getDashboardSection(sidebar);
item = await utils.getDashboardItem(section, constants.MAVEN_PROJECT);
logger.stepSuccess(1, 'Dashboard section and item retrieved');
logger.step(2, 'Launching dashboard start action with custom parameters');
await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION_WITH_PARAM, constants.START_DASHBOARD_MAC_ACTION_WITH_PARAM);
logger.step(3, 'Setting custom debug parameter: -DdebugPort=7777');
await utils.setCustomParameter("-DdebugPort=7777");
logger.step(4, 'Waiting for server to start in debug mode');
isServerRunning = await utils.waitForServerStart(constants.SERVER_START_STRING);
if (!isServerRunning) {
logger.error('Server started with params message not found in terminal');
} else {
logger.stepSuccess(4, 'Server successfully started in debug mode');
logger.step(5, 'Launching attach debugger dashboard action');
await utils.launchDashboardAction(item, constants.ATTACH_DEBUGGER_DASHBOARD_ACTION, constants.ATTACH_DEBUGGER_DASHBOARD_MAC_ACTION);
logger.info('Attach Debugger action completed');
logger.step(6, 'Waiting for debugger to attach');
attachStatus = await utils.waitForDebuggerAttach();
if (!attachStatus) {
logger.error('DebugToolbar not found - debugger may not have attached');
} else {
logger.stepSuccess(6, 'Debugger attached successfully');
}
logger.step(7, 'Stopping Liberty server');
await utils.stopLibertyserver(constants.MAVEN_PROJECT);
logger.step(8, 'Waiting for server to stop');
isServerRunning = !await utils.waitForServerStop(constants.SERVER_STOP_STRING);
if (!isServerRunning) {
logger.stepSuccess(8, 'Server stopped successfully');
} else {
logger.error('Server stop message not found in terminal');
}
}
} catch (e) {
logger.error('Exception occurred during attach debugger test', e);
throw e;
} finally {
logger.info(`Finally block - Server running status: ${isServerRunning}`);
if (isServerRunning) {
logger.info('Attempting to stop server in finally block');
await utils.stopLibertyserver(constants.MAVEN_PROJECT);
} else {
logger.info('Server already stopped, test cleanup complete');
}
}
expect(attachStatus).to.be.true;
logger.testComplete('Attach debugger for start with custom parameter event');
}).timeout(350000);
/**
* The following after hook copies the screenshot from the temporary folder in which it is saved to a known permanent location in the project folder.
*/
after(() => {
utils.copyScreenshotsToProjectFolder('maven');
});
});