forked from OpenLiberty/liberty-tools-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevModeTestSuite.ts
More file actions
303 lines (249 loc) · 15 KB
/
Copy pathdevModeTestSuite.ts
File metadata and controls
303 lines (249 loc) · 15 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
/*
* IBM Confidential
* Copyright IBM Corp. 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');
import { DashboardPage } from '../pages/DashboardPage';
export interface DevModeConfig {
buildTool: 'maven' | 'gradle';
getProjectPath: () => string;
projectConstant: string;
testRunString: string;
}
export function runDevModeTestSuite(config: DevModeConfig): void {
let dashboard!: DashboardPage;
describe(`Devmode action tests for ${config.buildTool} Project`, () => {
before(async function() {
this.timeout(60000);
await VSBrowser.instance.openResources(config.getProjectPath());
await VSBrowser.instance.waitForWorkbench();
dashboard = new DashboardPage();
});
afterEach(async function() {
this.timeout(30000);
// Close any open editors after each test
if (this.currentTest?.state === 'failed') {
await VSBrowser.instance.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');
const section = await dashboard.getSection();
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 - ${config.buildTool}`, async () => {
logger.testStart('Liberty Tools shows items - Maven');
try {
logger.step(1, 'Getting dashboard section');
const section = await dashboard.getSection();
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: ${config.projectConstant}`);
const item = await dashboard.getProjectItem(config.projectConstant);
logger.stepSuccess(4, 'Maven project item found');
expect(item).not.undefined;
logger.testComplete(`Liberty Tools shows items - ${config.buildTool}`);
} catch (error) {
logger.testFailed(`Liberty Tools shows items - ${config.buildTool}`, error);
throw error;
}
}).timeout(275000);
it(`Start ${config.buildTool} project from Liberty Tools`, async () => {
logger.testStart('Start Maven project from Liberty Tools');
try {
logger.step(1, 'Getting dashboard section and item');
await dashboard.runAction(config.projectConstant, constants.START_DASHBOARD_ACTION, constants.START_DASHBOARD_MAC_ACTION);
logger.step(2, '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(2, 'Server successfully started');
logger.step(3, 'Launching dashboard stop action');
await dashboard.runAction(config.projectConstant, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
logger.step(4, '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(4, 'Server stopped successfully');
}
expect(serverStopStatus).to.be.true;
}
expect(serverStartStatus).to.be.true;
logger.testComplete(`Start ${config.buildTool} project from Liberty Tools`);
} catch (error) {
logger.testFailed(`Start ${config.buildTool} project from Liberty Tools`, error);
throw error;
}
}).timeout(550000);
it(`Start ${config.buildTool} 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, 'Launching dashboard start action with Docker');
await dashboard.runAction(config.projectConstant, constants.START_DASHBOARD_ACTION_WITHDOCKER, constants.START_DASHBOARD_MAC_ACTION_WITHDOCKER);
logger.step(2, '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(2, 'Server successfully started in Docker container');
logger.step(3, 'Launching dashboard stop action');
await dashboard.runAction(config.projectConstant, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
logger.step(4, '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(4, 'Server stopped successfully');
}
expect(serverStopStatus).to.be.true;
}
expect(serverStartStatus).to.be.true;
logger.testComplete(`Start ${config.buildTool} with Docker from Liberty Tools`);
} catch (error) {
logger.testFailed(`Start ${config.buildTool} with Docker from Liberty Tools`, error);
throw error;
}
}).timeout(350000);
it(`Run tests for ${config.buildTool} project`, async () => {
logger.testStart('Run tests for Maven project');
try {
logger.step(1, 'Launching dashboard start action');
await dashboard.runAction(config.projectConstant, constants.START_DASHBOARD_ACTION, constants.START_DASHBOARD_MAC_ACTION);
logger.step(2, '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(2, 'Server successfully started');
logger.step(3, 'Launching run tests dashboard action');
await dashboard.runAction(config.projectConstant, constants.RUNTEST_DASHBOARD_ACTION, constants.RUNTEST_DASHBOARD_MAC_ACTION);
logger.step(4, 'Checking test execution status');
const testStatus = await utils.checkTestStatus(config.testRunString);
logger.info(`Test status result: ${testStatus}`);
expect(testStatus).to.be.true;
logger.stepSuccess(4, 'Tests executed successfully');
logger.step(5, 'Launching dashboard stop action');
await dashboard.runAction(config.projectConstant, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
logger.step(6, '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(6, 'Server stopped successfully');
}
expect(serverStopStatus).to.be.true;
}
expect(serverStartStatus).to.be.true;
logger.testComplete(`Run tests for ${config.buildTool} project`);
} catch (error) {
logger.testFailed(`Run tests for ${config.buildTool} project`, error);
throw error;
}
}).timeout(350000);
/**
* 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 ${config.buildTool} 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, 'Launching dashboard start action with custom parameters');
await dashboard.runAction(config.projectConstant, constants.START_DASHBOARD_ACTION_WITH_PARAM, constants.START_DASHBOARD_MAC_ACTION_WITH_PARAM);
logger.step(2, 'Setting custom debug parameter: -DdebugPort=7777');
await utils.setCustomParameter("-DdebugPort=7777");
logger.step(3, '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(3, 'Server successfully started in debug mode');
logger.step(4, 'Launching attach debugger dashboard action');
await dashboard.runAction(config.projectConstant, constants.ATTACH_DEBUGGER_DASHBOARD_ACTION, constants.ATTACH_DEBUGGER_DASHBOARD_MAC_ACTION);
logger.info('Attach Debugger action completed');
logger.step(5, 'Waiting for debugger to attach');
attachStatus = await utils.waitForDebuggerAttach();
if (!attachStatus) {
logger.error('DebugToolbar not found - debugger may not have attached');
} else {
logger.stepSuccess(5, 'Debugger attached successfully');
}
logger.step(6, 'Stopping Liberty server');
await utils.stopLibertyserver(config.projectConstant);
logger.step(7, 'Waiting for server to stop');
isServerRunning = !await utils.waitForServerStop(constants.SERVER_STOP_STRING);
if (!isServerRunning) {
logger.stepSuccess(7, '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(config.projectConstant);
} else {
logger.info('Server already stopped, test cleanup complete');
}
}
expect(attachStatus).to.be.true;
logger.testComplete(`Attach debugger for ${config.buildTool} 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(config.buildTool);
});
});
}