33 * Copyright IBM Corp. 2023, 2026
44 */
55import { expect } from 'chai' ;
6- import { DefaultTreeItem , EditorView , SideBarView , ViewItem , ViewSection , VSBrowser , Workbench , WebDriver } from 'vscode-extension-tester' ;
6+ import { EditorView , VSBrowser } from 'vscode-extension-tester' ;
7+ import { runDevModeTestSuite } from "./shared/devModeTestSuite" ;
78import * as utils from './utils/testUtils' ;
89import * as constants from './definitions/constants' ;
910import { logger } from './utils/testLogger' ;
1011import path = require( 'path' ) ;
1112import { DashboardPage } from './pages/DashboardPage' ;
1213
13- describe ( 'Devmode action tests for Gradle Project' , ( ) => {
14+ // Run shared dev mode tests
15+ runDevModeTestSuite ( {
16+ buildTool : 'gradle' ,
17+ getProjectPath : utils . getGradleProjectPath ,
18+ projectConstant : constants . GRADLE_PROJECT ,
19+ testRunString : constants . GRADLE_TEST_RUN_STRING
20+ } ) ;
21+
22+ // Gradle-specific tests in their own describe block
23+ describe ( 'Gradle-specific devmode action tests' , ( ) => {
1424 let dashboard : DashboardPage ;
1525
1626 before ( async function ( ) {
1727 this . timeout ( 30000 ) ;
18-
19- await VSBrowser . instance . openResources ( utils . getGradleProjectPath ( ) ) ;
20- await VSBrowser . instance . waitForWorkbench ( ) ;
21-
2228 dashboard = new DashboardPage ( ) ;
2329 } ) ;
2430
25- afterEach ( async function ( ) {
26- this . timeout ( 10000 ) ; // Increase timeout for cleanup operations
27- // Close any open editors after each test
28- if ( this . currentTest ?. state === 'failed' ) {
29- const driver = VSBrowser . instance . driver ;
30- const screenshot = await driver . takeScreenshot ( ) ;
31- logger . error ( `Test failed: ${ this . currentTest . title } ` ) ;
32- }
33-
34- try {
35- await new EditorView ( ) . closeAllEditors ( ) ;
36- } catch ( error ) {
37- logger . error ( 'Failed to close editors in afterEach' , error ) ;
38- }
39-
40- // Clear terminal between tests to avoid confusion with old output
41- try {
42- const workbench = new Workbench ( ) ;
43- await workbench . executeCommand ( 'terminal clear' ) ;
44- } catch ( error ) {
45- logger . error ( 'Failed to clear terminal in afterEach' , error ) ;
46- }
47- } ) ;
48-
49- it ( 'Find Liberty Tools in sidebar' , async ( ) => {
50- logger . testStart ( 'Find Liberty Tools in sidebar' ) ;
51- try {
52- logger . step ( 1 , 'Attempting to get Liberty Tools section' ) ;
53- const section = await dashboard . getSection ( ) ;
54- logger . stepSuccess ( 1 , 'Found Liberty Tools section' ) ;
55-
56- logger . step ( 2 , 'Validating sidebar is not undefined' ) ;
57- expect ( section ) . not . undefined ;
58- logger . testComplete ( 'Find Liberty Tools in sidebar' ) ;
59- } catch ( error ) {
60- logger . testFailed ( 'Find Liberty Tools in sidebar' , error ) ;
61- throw error ;
62- }
63- } ) . timeout ( 60000 ) ;
64-
65- it ( 'Liberty Tools shows items - Gradle' , async ( ) => {
66- logger . testStart ( 'Liberty Tools shows items - Gradle' ) ;
67- try {
68- logger . step ( 1 , 'Getting dashboard section' ) ;
69- const section = await dashboard . getSection ( ) ;
70- logger . stepSuccess ( 1 , 'Dashboard section retrieved' ) ;
71-
72- logger . step ( 2 , 'Waiting for Liberty Tools to load' ) ;
73- await utils . waitForDashboardToLoad ( section ) ;
74- logger . stepSuccess ( 2 , 'Liberty Tools loaded successfully' ) ;
75-
76- logger . step ( 3 , 'Getting visible items from section' ) ;
77- const menu = await utils . waitForCondition ( async ( ) => {
78- const items = await section . getVisibleItems ( ) ;
79- if ( items && items . length > 0 ) {
80- return items ;
81- }
82- return ;
83- } , 60 ) ;
84- logger . info ( `Found ${ menu . length } visible items in dashboard` ) ;
85- expect ( menu ) . not . empty ;
86-
87- logger . step ( 4 , `Finding Gradle project item: ${ constants . GRADLE_PROJECT } ` ) ;
88- const item = await dashboard . getProjectItem ( constants . GRADLE_PROJECT ) ;
89- logger . stepSuccess ( 4 , 'Gradle project item found' ) ;
90- expect ( item ) . not . undefined ;
91-
92- logger . testComplete ( 'Liberty Tools shows items - Gradle' ) ;
93- } catch ( error ) {
94- logger . testFailed ( 'Liberty Tools shows items - Gradle' , error ) ;
95- throw error ;
96- }
97- } ) . timeout ( 275000 ) ;
98-
99- it ( 'Start Gradle project from Liberty Tools' , async ( ) => {
100- logger . testStart ( 'Start Gradle project from Liberty Tools' ) ;
101- try {
102- logger . step ( 1 , 'Getting dashboard section and item' ) ;
103- await dashboard . runAction ( constants . GRADLE_PROJECT , constants . START_DASHBOARD_ACTION , constants . START_DASHBOARD_MAC_ACTION ) ;
104-
105- logger . step ( 2 , 'Waiting for server to start' ) ;
106- const serverStartStatus = await utils . waitForServerStart ( constants . SERVER_START_STRING ) ;
107-
108- if ( ! serverStartStatus ) {
109- logger . error ( 'Server started message not found in the terminal' ) ;
110- } else {
111- logger . stepSuccess ( 2 , 'Server successfully started' ) ;
112-
113- logger . step ( 3 , 'Launching dashboard stop action' ) ;
114- await dashboard . runAction ( constants . GRADLE_PROJECT , constants . STOP_DASHBOARD_ACTION , constants . STOP_DASHBOARD_MAC_ACTION ) ;
115-
116- logger . step ( 4 , 'Waiting for server to stop' ) ;
117- const serverStopStatus = await utils . waitForServerStop ( constants . SERVER_STOP_STRING ) ;
118-
119- if ( ! serverStopStatus ) {
120- logger . error ( 'Server stopped message not found in the terminal' ) ;
121- } else {
122- logger . stepSuccess ( 4 , 'Server stopped successfully' ) ;
123- }
124- expect ( serverStopStatus ) . to . be . true ;
125- }
126-
127- expect ( serverStartStatus ) . to . be . true ;
128- logger . testComplete ( 'Start Gradle project from Liberty Tools' ) ;
129- } catch ( error ) {
130- logger . testFailed ( 'Start Gradle project from Liberty Tools' , error ) ;
131- throw error ;
132- }
133- } ) . timeout ( 350000 ) ;
134-
135- it ( 'Start Gradle with Docker from Liberty Tools' , async ( ) => {
136- logger . testStart ( 'Start Gradle with Docker from Liberty Tools' ) ;
137-
138- if ( ( process . platform === 'darwin' ) || ( process . platform === 'win32' ) ) {
139- logger . skip ( `Test skipped for platform: ${ process . platform } (Docker test only runs on Linux)` ) ;
140- return true ;
141- }
142-
143- try {
144- logger . step ( 1 , 'Launching dashboard start action with Docker' ) ;
145- await dashboard . runAction ( constants . GRADLE_PROJECT , constants . START_DASHBOARD_ACTION_WITHDOCKER , constants . START_DASHBOARD_MAC_ACTION_WITHDOCKER ) ;
146-
147- logger . step ( 2 , 'Waiting for server to start in Docker container' ) ;
148- const serverStartStatus = await utils . waitForServerStart ( constants . SERVER_START_STRING ) ;
149-
150- if ( ! serverStartStatus ) {
151- logger . error ( 'Server started message not found in the terminal' ) ;
152- } else {
153- logger . stepSuccess ( 2 , 'Server successfully started in Docker container' ) ;
154-
155- logger . step ( 3 , 'Launching dashboard stop action' ) ;
156- await dashboard . runAction ( constants . GRADLE_PROJECT , constants . STOP_DASHBOARD_ACTION , constants . STOP_DASHBOARD_MAC_ACTION ) ;
157-
158- logger . step ( 4 , 'Waiting for server to stop' ) ;
159- const serverStopStatus = await utils . waitForServerStop ( constants . SERVER_STOP_STRING ) ;
160-
161- if ( ! serverStopStatus ) {
162- logger . error ( 'Server stopped message not found in the terminal' ) ;
163- } else {
164- logger . stepSuccess ( 4 , 'Server stopped successfully' ) ;
165- }
166- expect ( serverStopStatus ) . to . be . true ;
167- }
168-
169- expect ( serverStartStatus ) . to . be . true ;
170- logger . testComplete ( 'Start Gradle with Docker from Liberty Tools' ) ;
171- } catch ( error ) {
172- logger . testFailed ( 'Start Gradle with Docker from Liberty Tools' , error ) ;
173- throw error ;
174- }
175- } ) . timeout ( 350000 ) ;
176-
177- it ( 'Run tests for Gradle project' , async ( ) => {
178- logger . testStart ( 'Run tests for Gradle project' ) ;
179- try {
180- logger . step ( 1 , 'Launching dashboard start action' ) ;
181- await dashboard . runAction ( constants . GRADLE_PROJECT , constants . START_DASHBOARD_ACTION , constants . START_DASHBOARD_MAC_ACTION ) ;
182-
183- logger . step ( 2 , 'Waiting for server to start' ) ;
184- const serverStartStatus = await utils . waitForServerStart ( constants . SERVER_START_STRING ) ;
185-
186- if ( ! serverStartStatus ) {
187- logger . error ( 'Server started message not found in the terminal' ) ;
188- } else {
189- logger . stepSuccess ( 2 , 'Server successfully started' ) ;
190-
191- logger . step ( 3 , 'Launching run tests dashboard action' ) ;
192- await dashboard . runAction ( constants . GRADLE_PROJECT , constants . RUNTEST_DASHBOARD_ACTION , constants . RUNTEST_DASHBOARD_MAC_ACTION ) ;
193-
194- logger . step ( 4 , 'Checking test execution status' ) ;
195- const testStatus = await utils . checkTestStatus ( constants . GRADLE_TEST_RUN_STRING ) ;
196- logger . info ( `Test status result: ${ testStatus } ` ) ;
197- expect ( testStatus ) . to . be . true ;
198- logger . stepSuccess ( 4 , 'Tests executed successfully' ) ;
199-
200- logger . step ( 5 , 'Launching dashboard stop action' ) ;
201- await dashboard . runAction ( constants . GRADLE_PROJECT , constants . STOP_DASHBOARD_ACTION , constants . STOP_DASHBOARD_MAC_ACTION ) ;
202-
203- logger . step ( 6 , 'Waiting for server to stop' ) ;
204- const serverStopStatus = await utils . waitForServerStop ( constants . SERVER_STOP_STRING ) ;
205-
206- if ( ! serverStopStatus ) {
207- logger . error ( 'Server stopped message not found in the terminal' ) ;
208- } else {
209- logger . stepSuccess ( 6 , 'Server stopped successfully' ) ;
210- }
211- expect ( serverStopStatus ) . to . be . true ;
212- }
213-
214- expect ( serverStartStatus ) . to . be . true ;
215- logger . testComplete ( 'Run tests for Gradle project' ) ;
216- } catch ( error ) {
217- logger . testFailed ( 'Run tests for Gradle project' , error ) ;
218- throw error ;
219- }
220- } ) . timeout ( 350000 ) ;
221-
222-
22331 it ( 'Start Gradle with options from Liberty Tools' , async ( ) => {
22432 logger . testStart ( 'Start Gradle with options from Liberty Tools' ) ;
22533 try {
@@ -328,72 +136,6 @@ describe('Devmode action tests for Gradle Project', () => {
328136 }
329137 } ) . timeout ( 550000 ) ;
330138
331- /**
332- * All future test cases should be written before the test that attaches the debugger, as this will switch the UI to the debugger view.
333- * 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.
334- */
335- it ( 'Attach debugger for Gradle with custom parameter event' , async ( ) => {
336- logger . testStart ( 'Attach debugger for Gradle with custom parameter event' ) ;
337- let isServerRunning : Boolean = true ;
338- let attachStatus : Boolean = false ;
339-
340- try {
341- logger . step ( 1 , 'Launching dashboard start action with custom parameters' ) ;
342- await dashboard . runAction ( constants . GRADLE_PROJECT , constants . START_DASHBOARD_ACTION_WITH_PARAM , constants . START_DASHBOARD_MAC_ACTION_WITH_PARAM ) ;
343-
344- logger . step ( 2 , 'Setting custom debug parameter: -DdebugPort=7777' ) ;
345- await utils . setCustomParameter ( "-DdebugPort=7777" ) ;
346-
347- logger . step ( 3 , 'Waiting for server to start in debug mode' ) ;
348- isServerRunning = await utils . waitForServerStart ( constants . SERVER_START_STRING ) ;
349-
350- if ( ! isServerRunning ) {
351- logger . error ( 'Server started with params message not found in terminal' ) ;
352- } else {
353- logger . stepSuccess ( 3 , 'Server successfully started in debug mode' ) ;
354-
355- logger . step ( 4 , 'Launching attach debugger dashboard action' ) ;
356- await dashboard . runAction ( constants . GRADLE_PROJECT , constants . ATTACH_DEBUGGER_DASHBOARD_ACTION , constants . ATTACH_DEBUGGER_DASHBOARD_MAC_ACTION ) ;
357- logger . info ( 'Attach Debugger action completed' ) ;
358-
359- logger . step ( 5 , 'Waiting for debugger to attach' ) ;
360- attachStatus = await utils . waitForDebuggerAttach ( ) ;
361-
362- if ( ! attachStatus ) {
363- logger . error ( 'DebugToolbar not found - debugger may not have attached' ) ;
364- } else {
365- logger . stepSuccess ( 5 , 'Debugger attached successfully' ) ;
366- }
367-
368- logger . step ( 6 , 'Stopping Liberty server' ) ;
369- await utils . stopLibertyserver ( constants . GRADLE_PROJECT ) ;
370-
371- logger . step ( 7 , 'Waiting for server to stop' ) ;
372- isServerRunning = ! await utils . waitForServerStop ( constants . SERVER_STOP_STRING ) ;
373-
374- if ( ! isServerRunning ) {
375- logger . stepSuccess ( 7 , 'Server stopped successfully' ) ;
376- } else {
377- logger . error ( 'Server stop message not found in terminal' ) ;
378- }
379- }
380- } catch ( e ) {
381- logger . error ( 'Exception occurred during attach debugger test' , e ) ;
382- throw e ;
383- } finally {
384- logger . info ( `Finally block - Server running status: ${ isServerRunning } ` ) ;
385- if ( isServerRunning ) {
386- logger . info ( 'Attempting to stop server in finally block' ) ;
387- await utils . stopLibertyserver ( constants . GRADLE_PROJECT ) ;
388- } else {
389- logger . info ( 'Server already stopped, test cleanup complete' ) ;
390- }
391- }
392-
393- expect ( attachStatus ) . to . be . true ;
394- logger . testComplete ( 'Attach debugger for Gradle with custom parameter event' ) ;
395- } ) . timeout ( 350000 ) ;
396-
397139 it ( 'View test report for Gradle project' , async ( ) => {
398140 logger . testStart ( 'View test report for Gradle project' ) ;
399141
@@ -437,11 +179,6 @@ describe('Devmode action tests for Gradle Project', () => {
437179 throw error ;
438180 }
439181 } ) . timeout ( 100000 ) ;
182+ } ) ;
183+
440184
441- /**
442- * 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.
443- */
444- after ( ( ) => {
445- utils . copyScreenshotsToProjectFolder ( 'gradle' ) ;
446- } ) ;
447- } ) ;
0 commit comments