From f6b0043a64a428a93334c7431bb5b05eacc42811 Mon Sep 17 00:00:00 2001 From: Venya Sharma Date: Wed, 17 Jun 2026 10:09:21 -0500 Subject: [PATCH 1/2] Add LSP4Jakarta diagnostic + quick fix tests for Maven and Gradle (#125) 1. Added MavenTestLSPRestSnippetAndDiagnostic.ts and the Gradle equivalent to test the rest_class snippet, the "Only public methods can be exposed as resource methods" diagnostic, and the "Make method public" quick fix. 2. Added empty TestRest.java fixtures for both projects (the tests fill and reset them each run). 3. Added a JAX-RS dependency to the Maven pom so the rest_class snippet populates. 4. Added the init-project setup to the existing test files so they can be run individually. --- src/test/GradleTestDevModeActions.ts | 5 +- src/test/GradleTestLSPHover.ts | 6 +- .../GradleTestLSPRestSnippetAndDiagnostic.ts | 233 ++++++++++++++++++ src/test/MavenTestDevModeActions.ts | 8 +- src/test/MavenTestLSPHover.ts | 9 +- .../MavenTestLSPRestSnippetAndDiagnostic.ts | 233 ++++++++++++++++++ .../test/gradle/liberty/web/app/TestRest.java | 0 .../liberty-maven-test-wrapper-app/pom.xml | 6 + .../test/maven/liberty/web/app/TestRest.java | 0 9 files changed, 494 insertions(+), 6 deletions(-) create mode 100644 src/test/GradleTestLSPRestSnippetAndDiagnostic.ts create mode 100644 src/test/MavenTestLSPRestSnippetAndDiagnostic.ts create mode 100644 src/test/resources/gradle/liberty-gradle-test-wrapper-app/src/main/java/test/gradle/liberty/web/app/TestRest.java create mode 100644 src/test/resources/maven/liberty-maven-test-wrapper-app/src/main/java/test/maven/liberty/web/app/TestRest.java diff --git a/src/test/GradleTestDevModeActions.ts b/src/test/GradleTestDevModeActions.ts index 90c0703e..7201a86c 100755 --- a/src/test/GradleTestDevModeActions.ts +++ b/src/test/GradleTestDevModeActions.ts @@ -3,7 +3,7 @@ * Copyright IBM Corp. 2023, 2026 */ import { expect } from 'chai'; -import { DefaultTreeItem, EditorView, InputBox, SideBarView, ViewSection, VSBrowser, Workbench } from 'vscode-extension-tester'; +import { DefaultTreeItem, EditorView, InputBox, SideBarView, ViewSection, VSBrowser, WebDriver, Workbench } from 'vscode-extension-tester'; import * as utils from './utils/testUtils'; import * as constants from './definitions/constants'; import { logger } from './utils/testLogger'; @@ -14,10 +14,13 @@ describe('Devmode action tests for Gradle Project', () => { let section: ViewSection; let item: DefaultTreeItem; let tabs: string[]; + let driver: WebDriver; before(async function() { this.timeout(30000); // Wait for workbench to be ready + driver = VSBrowser.instance.driver; + await VSBrowser.instance.openResources(utils.getGradleProjectPath()); await VSBrowser.instance.waitForWorkbench(); sidebar = new SideBarView(); }); diff --git a/src/test/GradleTestLSPHover.ts b/src/test/GradleTestLSPHover.ts index 201a9c8d..06d52ec9 100644 --- a/src/test/GradleTestLSPHover.ts +++ b/src/test/GradleTestLSPHover.ts @@ -3,7 +3,7 @@ * Copyright IBM Corp. 2026 */ import { expect } from 'chai'; -import { EditorView, TextEditor, VSBrowser, Workbench } from 'vscode-extension-tester'; +import { EditorView, TextEditor, VSBrowser, WebDriver, Workbench } from 'vscode-extension-tester'; import * as utils from './utils/testUtils'; import { logger } from './utils/testLogger'; import * as path from 'path'; @@ -12,11 +12,15 @@ describe('LSP Hover tests for Gradle Project', () => { let editorView: EditorView; let editor: TextEditor; let wait: any; + let driver: WebDriver; before(async function() { this.timeout(60000); logger.info('Setting up Gradle LSP Hover tests'); + driver = VSBrowser.instance.driver; + await VSBrowser.instance.openResources(utils.getGradleProjectPath()); + // Wait for workbench to be ready await VSBrowser.instance.waitForWorkbench(); editorView = new EditorView(); diff --git a/src/test/GradleTestLSPRestSnippetAndDiagnostic.ts b/src/test/GradleTestLSPRestSnippetAndDiagnostic.ts new file mode 100644 index 00000000..dcaf9264 --- /dev/null +++ b/src/test/GradleTestLSPRestSnippetAndDiagnostic.ts @@ -0,0 +1,233 @@ + +/* + * IBM Confidential + * Copyright IBM Corp. 2026 + */ +import { expect } from 'chai'; +import { EditorView, TextEditor, VSBrowser, Workbench, WebDriver, BottomBarPanel, MarkerType, Key, By } from 'vscode-extension-tester'; +import * as utils from './utils/testUtils'; +import { logger } from './utils/testLogger'; +import * as path from 'path'; + +describe('Rest Class Snippet Test for Gradle Project', () => { + let editorView: EditorView; + let javaEditor: TextEditor; + let wait: any; + let driver: WebDriver; + + const testRestPath = path.resolve( + utils.getGradleProjectPath(), + 'src', 'main', 'java', 'test', 'gradle', 'liberty', 'web', 'app', + 'TestRest.java' + ); + + before(async function() { + this.timeout(60000); + logger.info('Setting up rest_class snippet test'); + + driver = VSBrowser.instance.driver; + await VSBrowser.instance.openResources(utils.getGradleProjectPath()); + + // Wait for workbench to be ready + await VSBrowser.instance.waitForWorkbench(); + editorView = new EditorView(); + wait = utils.getWaitHelper(); + + // Open the file + await VSBrowser.instance.openResources(testRestPath, async () => { + await wait.sleep(3000); + }); + javaEditor = await editorView.openEditor('TestRest.java') as TextEditor; + }); + + afterEach(async function() { + // Take screenshot on failure but don't close editor + if (this.currentTest?.state === 'failed') { + const driver = VSBrowser.instance.driver; + const screenshot = await driver.takeScreenshot(); + logger.error(`Test failed: ${this.currentTest.title}`); + } + }); + + after(async function() { + this.timeout(10000); // Increase timeout for cleanup operations + // Close editor after all tests complete + try { + if(javaEditor){ + await javaEditor.setText(''); + await javaEditor.save(); + logger.info('Reset TestRest.java to empty after test') + + } + } catch (error){ + logger.error('Failed to reset TestRest.java ', error); + } + try { + await editorView.closeAllEditors(); + logger.info('Closed all editors after test suite'); + } catch (error) { + logger.error('Failed to close editors in after hook', error); + } + + utils.copyScreenshotsToProjectFolder('gradle'); + }); + + it('LSP4Jakarta Language Server should initialize', async function() { + this.timeout(60000); + logger.testStart('LSP4Jakarta Language Server should initialize'); + + try { + await utils.waitForLanguageServerInit( + 'Language Support for Jakarta EE', + 'Initializing Jakarta EE server', + 60 + ); + logger.testComplete('LSP4Jakarta Language Server initialized successfully'); + } catch (error) { + logger.testFailed('LSP4Jakarta Language Server should initialize', error); + throw error; + } + }); + + it('rest_class snippet populates correct REST class', async function () { + this.timeout(275000); + logger.testStart('rest_class snippet inserts correct REST class'); + + // at the top of the rest_class snippet test, before positioning the cursor + await javaEditor.setText(''); + await javaEditor.save(); + await wait.sleep(1500); // let any auto-stub settle, then confirm + const check = await javaEditor.getText(); + logger.info('Buffer before snippet: ' + JSON.stringify(check)); + + try { + logger.step(1, 'Positioning cursor for snippet insertion'); + // Position cursor at end of file + const lastLine = (await javaEditor.getText()).split('\n').length; + await javaEditor.setCursor(lastLine - 1, 1); + + logger.step(2, 'Typing "rest" to trigger snippet'); + await javaEditor.typeText('rest'); + logger.stepSuccess(2, 'Typed "rest"'); + + logger.step(3, 'Opening content assist'); + const assist = await javaEditor.toggleContentAssist(true); + if (assist) { + logger.step(4,'Selecting rest_class snippet'); + await assist.select('rest_class'); + await new Promise(res => setTimeout(res, 600)); // 300–800ms + logger.stepSuccess(4, 'rest_class snippet selected'); + } + await javaEditor.toggleContentAssist(false); + + logger.step(5, 'Verifying snippet insertion'); + const codeInsertion = await javaEditor.getText(); + logger.info('Inserted code snapshot: ' + codeInsertion); + expect(codeInsertion).to.include('@GET') + expect(codeInsertion).to.include('methodname'); + logger.stepSuccess(5, 'Snippet rest_class was inserted correctly'); + + logger.testComplete('rest_class snippet inserts correct REST class'); + } catch (error) { + logger.testFailed('rest_class snippet inserts correct REST class', error); + throw error; + } + }); + it('Show that private @GET method displays diagnostic and quick fix removes it ', async function () { + this.timeout(90000); + logger.testStart('Diagnostic for a private @GET method and quick fix clears it'); + try { + // Find the method with @GET and change it to private + let lineNum = await javaEditor.getLineOfText('methodname'); + if (lineNum < 1) throw new Error('Could not find the methodname line'); + const oldLine = await javaEditor.getTextAtLine(lineNum); + const newLine = oldLine.replace("public", "private"); + await javaEditor.setTextAtLine(lineNum, newLine); + + // Save file and wait for reanalysis + await javaEditor.save(); + await wait.sleep(500); + + // Open problems view + const bottomBar = new BottomBarPanel(); + await bottomBar.toggle(true); + let problemsView = await bottomBar.openProblemsView(); + let markers = await problemsView.getAllVisibleMarkers(MarkerType.Any); + + // Check if the marker is present + let found = false; + for (const marker of markers) { + const text = await marker.getText(); + // Check if text contains your diagnostic message + if(text.includes('Only public methods can be exposed as resource methods.')){ + found = true; + break; + } + } + expect(found).to.be.true; + logger.testComplete('Diagnostic shows for private @GET method'); + + // Quick fix implementation to get rid of diagnostic + // Re-find line and place cursor on "methodname()" + const buffer = await javaEditor.getText(); + logger.info('Buffer before quick fix: ' + JSON.stringify(buffer)); + + // Get column on the method name + await javaEditor.selectText('methodname'); + await wait.sleep(300); + + // Open the quick-fix menu with Cmd+. (Mac) / Ctrl+. (Linux/Windows) + const modKey = process.platform === 'darwin' ? Key.COMMAND : Key.CONTROL; + await driver.actions().keyDown(modKey).sendKeys('.').keyUp(modKey).perform(); + await wait.sleep(2000); + + // Click on the option to make the method public within the quick-fixes options + const options = await driver.findElements(By.css('.action-widget .action-list-item, .action-widget .monaco-list-row')); + let clicked = false; + for (const opt of options) { + const text = await opt.getText(); + logger.info('OPTION: ' + JSON.stringify(text)); + if (text.toLowerCase().includes('make method public')) { + await driver.executeScript('arguments[0].click();', opt); + clicked = true; + break; + } + } + if (!clicked) { + await driver.actions().sendKeys(Key.ESCAPE).perform(); // close menu cleanly + throw new Error('No "make public" quick fix was offered — see OPTION logs above'); + } + + await wait.sleep(3000); + await javaEditor.save(); + await wait.sleep(5000); + + // Check quick fix was implemented at correct line number + const after = await javaEditor.getText(); + logger.info('Buffer after quick fix: ' + JSON.stringify(after)); + expect(after).to.include('public String methodname'); + + problemsView = await bottomBar.openProblemsView(); + markers = await problemsView.getAllVisibleMarkers(MarkerType.Any); + + // Check if the marker is present + let stillPresent = false; + for (const marker of markers) { + const text = await marker.getText(); + // Check if text contains diagnostic message + if(text.includes('Only public methods can be exposed as resource methods.')){ + stillPresent = true; + break; + } + } + expect(stillPresent).to.be.false; + logger.testComplete('Diagnostic no longer shows for public @GET method as expected'); + + } catch (error) { + logger.testFailed('Diagnostic/quick-fix test flow failed', error); + throw error; + } + + }); + }); + diff --git a/src/test/MavenTestDevModeActions.ts b/src/test/MavenTestDevModeActions.ts index dfb05671..33eac2f9 100755 --- a/src/test/MavenTestDevModeActions.ts +++ b/src/test/MavenTestDevModeActions.ts @@ -3,7 +3,7 @@ * Copyright IBM Corp. 2023, 2026 */ import { expect } from 'chai'; -import { DefaultTreeItem, EditorView, SideBarView, ViewItem, ViewSection, VSBrowser, Workbench } from 'vscode-extension-tester'; +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'; @@ -15,11 +15,15 @@ describe('Devmode action tests for Maven Project', () => { let menu: ViewItem[]; let item: DefaultTreeItem; let tabs: string[]; + let driver: WebDriver; before(async function() { this.timeout(30000); - // Wait for workbench to be ready + + driver = VSBrowser.instance.driver; + await VSBrowser.instance.openResources(utils.getMvnProjectPath()); await VSBrowser.instance.waitForWorkbench(); + sidebar = new SideBarView(); }); diff --git a/src/test/MavenTestLSPHover.ts b/src/test/MavenTestLSPHover.ts index beb3e711..5e1467ce 100644 --- a/src/test/MavenTestLSPHover.ts +++ b/src/test/MavenTestLSPHover.ts @@ -3,7 +3,7 @@ * Copyright IBM Corp. 2026 */ import { expect } from 'chai'; -import { EditorView, TextEditor, VSBrowser, Workbench } from 'vscode-extension-tester'; +import { EditorView, TextEditor, VSBrowser, Workbench, WebDriver } from 'vscode-extension-tester'; import * as utils from './utils/testUtils'; import { logger } from './utils/testLogger'; import * as path from 'path'; @@ -12,9 +12,13 @@ describe('LSP Hover tests for Maven Project', () => { let editorView: EditorView; let editor: TextEditor; let wait: any; + let driver: WebDriver; + before(async function() { this.timeout(60000); + driver = VSBrowser.instance.driver; + await VSBrowser.instance.openResources(utils.getMvnProjectPath()); logger.info('Setting up Maven LSP Hover tests'); // Wait for workbench to be ready @@ -214,4 +218,5 @@ describe('LSP Hover tests for Maven Project', () => { }); -// Made with Bob + + diff --git a/src/test/MavenTestLSPRestSnippetAndDiagnostic.ts b/src/test/MavenTestLSPRestSnippetAndDiagnostic.ts new file mode 100644 index 00000000..c6d808ed --- /dev/null +++ b/src/test/MavenTestLSPRestSnippetAndDiagnostic.ts @@ -0,0 +1,233 @@ + +/* + * IBM Confidential + * Copyright IBM Corp. 2026 + */ +import { expect } from 'chai'; +import { EditorView, TextEditor, VSBrowser, Workbench, WebDriver, BottomBarPanel, MarkerType, Key, By } from 'vscode-extension-tester'; +import * as utils from './utils/testUtils'; +import { logger } from './utils/testLogger'; +import * as path from 'path'; + +describe('Rest Class Snippet Test for Maven Project', () => { + let editorView: EditorView; + let javaEditor: TextEditor; + let wait: any; + let driver: WebDriver; + + const testRestPath = path.resolve( + utils.getMvnProjectPath(), + 'src', 'main', 'java', 'test', 'maven', 'liberty', 'web', 'app', + 'TestRest.java' + ); + + before(async function() { + this.timeout(60000); + logger.info('Setting up rest_class snippet test'); + + driver = VSBrowser.instance.driver; + await VSBrowser.instance.openResources(utils.getMvnProjectPath()); + + // Wait for workbench to be ready + await VSBrowser.instance.waitForWorkbench(); + editorView = new EditorView(); + wait = utils.getWaitHelper(); + + // Open the file + await VSBrowser.instance.openResources(testRestPath, async () => { + await wait.sleep(3000); + }); + javaEditor = await editorView.openEditor('TestRest.java') as TextEditor; + }); + + afterEach(async function() { + // Take screenshot on failure but don't close editor + if (this.currentTest?.state === 'failed') { + const driver = VSBrowser.instance.driver; + const screenshot = await driver.takeScreenshot(); + logger.error(`Test failed: ${this.currentTest.title}`); + } + }); + + after(async function() { + this.timeout(10000); // Increase timeout for cleanup operations + // Close editor after all tests complete + try { + if(javaEditor){ + await javaEditor.setText(''); + await javaEditor.save(); + logger.info('Reset TestRest.java to empty after test') + + } + } catch (error){ + logger.error('Failed to reset TestRest.java ', error); + } + try { + await editorView.closeAllEditors(); + logger.info('Closed all editors after test suite'); + } catch (error) { + logger.error('Failed to close editors in after hook', error); + } + + utils.copyScreenshotsToProjectFolder('maven'); + }); + + it('LSP4Jakarta Language Server should initialize', async function() { + this.timeout(60000); + logger.testStart('LSP4Jakarta Language Server should initialize'); + + try { + await utils.waitForLanguageServerInit( + 'Language Support for Jakarta EE', + 'Initializing Jakarta EE server', + 60 + ); + logger.testComplete('LSP4Jakarta Language Server initialized successfully'); + } catch (error) { + logger.testFailed('LSP4Jakarta Language Server should initialize', error); + throw error; + } + }); + + it('rest_class snippet populates correct REST class', async function () { + this.timeout(275000); + logger.testStart('rest_class snippet inserts correct REST class'); + + // at the top of the rest_class snippet test, before positioning the cursor + await javaEditor.setText(''); + await javaEditor.save(); + await wait.sleep(1500); // let any auto-stub settle, then confirm + const check = await javaEditor.getText(); + logger.info('Buffer before snippet: ' + JSON.stringify(check)); + + try { + logger.step(1, 'Positioning cursor for snippet insertion'); + // Position cursor at end of file + const lastLine = (await javaEditor.getText()).split('\n').length; + await javaEditor.setCursor(lastLine - 1, 1); + + logger.step(2, 'Typing "rest" to trigger snippet'); + await javaEditor.typeText('rest'); + logger.stepSuccess(2, 'Typed "rest"'); + + logger.step(3, 'Opening content assist'); + const assist = await javaEditor.toggleContentAssist(true); + if (assist) { + logger.step(4,'Selecting rest_class snippet'); + await assist.select('rest_class'); + await new Promise(res => setTimeout(res, 600)); // 300–800ms + logger.stepSuccess(4, 'rest_class snippet selected'); + } + await javaEditor.toggleContentAssist(false); + + logger.step(5, 'Verifying snippet insertion'); + const codeInsertion = await javaEditor.getText(); + logger.info('Inserted code snapshot: ' + codeInsertion); + expect(codeInsertion).to.include('@GET') + expect(codeInsertion).to.include('methodname'); + logger.stepSuccess(5, 'Snippet rest_class was inserted correctly'); + + logger.testComplete('rest_class snippet inserts correct REST class'); + } catch (error) { + logger.testFailed('rest_class snippet inserts correct REST class', error); + throw error; + } + }); + it('Show that private @GET method displays diagnostic and quick fix removes it ', async function () { + this.timeout(90000); + logger.testStart('Diagnostic for a private @GET method and quick fix clears it'); + try { + // Find the method with @GET and change it to private + let lineNum = await javaEditor.getLineOfText('methodname'); + if (lineNum < 1) throw new Error('Could not find the methodname line'); + const oldLine = await javaEditor.getTextAtLine(lineNum); + const newLine = oldLine.replace("public", "private"); + await javaEditor.setTextAtLine(lineNum, newLine); + + // Save file and wait for reanalysis + await javaEditor.save(); + await wait.sleep(500); + + // Open problems view + const bottomBar = new BottomBarPanel(); + await bottomBar.toggle(true); + let problemsView = await bottomBar.openProblemsView(); + let markers = await problemsView.getAllVisibleMarkers(MarkerType.Any); + + // Check if the marker is present + let found = false; + for (const marker of markers) { + const text = await marker.getText(); + // Check if text contains your diagnostic message + if(text.includes('Only public methods can be exposed as resource methods.')){ + found = true; + break; + } + } + expect(found).to.be.true; + logger.testComplete('Diagnostic shows for private @GET method'); + + // Quick fix implementation to get rid of diagnostic + // Re-find line and place cursor on "methodname()" + const buffer = await javaEditor.getText(); + logger.info('Buffer before quick fix: ' + JSON.stringify(buffer)); + + // Get column on the method name + await javaEditor.selectText('methodname'); + await wait.sleep(300); + + // Open the quick-fix menu with Cmd+. (Mac) / Ctrl+. (Linux/Windows) + const modKey = process.platform === 'darwin' ? Key.COMMAND : Key.CONTROL; + await driver.actions().keyDown(modKey).sendKeys('.').keyUp(modKey).perform(); + await wait.sleep(2000); + + // Click on the option to make the method public within the quick-fixes options + const options = await driver.findElements(By.css('.action-widget .action-list-item, .action-widget .monaco-list-row')); + let clicked = false; + for (const opt of options) { + const text = await opt.getText(); + logger.info('OPTION: ' + JSON.stringify(text)); + if (text.toLowerCase().includes('make method public')) { + await driver.executeScript('arguments[0].click();', opt); + clicked = true; + break; + } + } + if (!clicked) { + await driver.actions().sendKeys(Key.ESCAPE).perform(); // close menu cleanly + throw new Error('No "make public" quick fix was offered — see OPTION logs above'); + } + + await wait.sleep(3000); + await javaEditor.save(); + await wait.sleep(5000); + + // Check quick fix was implemented at correct line number + const after = await javaEditor.getText(); + logger.info('Buffer after quick fix: ' + JSON.stringify(after)); + expect(after).to.include('public String methodname'); + + problemsView = await bottomBar.openProblemsView(); + markers = await problemsView.getAllVisibleMarkers(MarkerType.Any); + + // Check if the marker is present + let stillPresent = false; + for (const marker of markers) { + const text = await marker.getText(); + // Check if text contains diagnostic message + if(text.includes('Only public methods can be exposed as resource methods.')){ + stillPresent = true; + break; + } + } + expect(stillPresent).to.be.false; + logger.testComplete('Diagnostic no longer shows for public @GET method as expected'); + + } catch (error) { + logger.testFailed('Diagnostic/quick-fix test flow failed', error); + throw error; + } + + }); + }); + diff --git a/src/test/resources/gradle/liberty-gradle-test-wrapper-app/src/main/java/test/gradle/liberty/web/app/TestRest.java b/src/test/resources/gradle/liberty-gradle-test-wrapper-app/src/main/java/test/gradle/liberty/web/app/TestRest.java new file mode 100644 index 00000000..e69de29b diff --git a/src/test/resources/maven/liberty-maven-test-wrapper-app/pom.xml b/src/test/resources/maven/liberty-maven-test-wrapper-app/pom.xml index 79a2ccbb..8d10039e 100755 --- a/src/test/resources/maven/liberty-maven-test-wrapper-app/pom.xml +++ b/src/test/resources/maven/liberty-maven-test-wrapper-app/pom.xml @@ -47,6 +47,12 @@ 5.8.1 test + + jakarta.ws.rs + jakarta.ws.rs-api + 3.1.0 + provided + diff --git a/src/test/resources/maven/liberty-maven-test-wrapper-app/src/main/java/test/maven/liberty/web/app/TestRest.java b/src/test/resources/maven/liberty-maven-test-wrapper-app/src/main/java/test/maven/liberty/web/app/TestRest.java new file mode 100644 index 00000000..e69de29b From ffe5a11a987584e7128c24470101ce61cc1a0585 Mon Sep 17 00:00:00 2001 From: Venya Sharma Date: Wed, 17 Jun 2026 14:55:42 -0500 Subject: [PATCH 2/2] Fix test cleanup and timeout issues --- src/test/GradleTestDevModeActions.ts | 2 - .../GradleTestLSPRestSnippetAndDiagnostic.ts | 57 ++++++++++++------- src/test/MavenTestDevModeActions.ts | 2 - .../MavenTestLSPRestSnippetAndDiagnostic.ts | 39 ++++++++----- 4 files changed, 61 insertions(+), 39 deletions(-) diff --git a/src/test/GradleTestDevModeActions.ts b/src/test/GradleTestDevModeActions.ts index 7201a86c..a1ed691f 100755 --- a/src/test/GradleTestDevModeActions.ts +++ b/src/test/GradleTestDevModeActions.ts @@ -14,12 +14,10 @@ describe('Devmode action tests for Gradle Project', () => { let section: ViewSection; let item: DefaultTreeItem; let tabs: string[]; - let driver: WebDriver; before(async function() { this.timeout(30000); // Wait for workbench to be ready - driver = VSBrowser.instance.driver; await VSBrowser.instance.openResources(utils.getGradleProjectPath()); await VSBrowser.instance.waitForWorkbench(); sidebar = new SideBarView(); diff --git a/src/test/GradleTestLSPRestSnippetAndDiagnostic.ts b/src/test/GradleTestLSPRestSnippetAndDiagnostic.ts index dcaf9264..79b492d8 100644 --- a/src/test/GradleTestLSPRestSnippetAndDiagnostic.ts +++ b/src/test/GradleTestLSPRestSnippetAndDiagnostic.ts @@ -50,27 +50,42 @@ describe('Rest Class Snippet Test for Gradle Project', () => { }); after(async function() { - this.timeout(10000); // Increase timeout for cleanup operations - // Close editor after all tests complete - try { - if(javaEditor){ - await javaEditor.setText(''); - await javaEditor.save(); - logger.info('Reset TestRest.java to empty after test') - - } - } catch (error){ - logger.error('Failed to reset TestRest.java ', error); + this.timeout(15000); + try { + if (javaEditor) { + // Select all text first, then clear + const currentText = await javaEditor.getText(); + try { + await javaEditor.selectText(currentText); + await wait.sleep(300); + } catch (selectError) { + // selectText may fail but setText still works + } + + await javaEditor.setText(''); + await wait.sleep(500); + await javaEditor.save(); + await wait.sleep(500); + logger.info('Reset TestRest.java to empty after test'); + } + } catch (error) { + logger.error('Failed to reset TestRest.java', error); } - try { - await editorView.closeAllEditors(); - logger.info('Closed all editors after test suite'); - } catch (error) { - logger.error('Failed to close editors in after hook', error); - } - - utils.copyScreenshotsToProjectFolder('gradle'); - }); + + try { + await editorView.closeAllEditors(); + await wait.sleep(500); + logger.info('Closed all editors after test suite'); + } catch (error) { + logger.error('Failed to close editors in after hook', error); + } + + try { + utils.copyScreenshotsToProjectFolder('maven'); + } catch (error) { + // Ignore screenshot errors + } + }); it('LSP4Jakarta Language Server should initialize', async function() { this.timeout(60000); @@ -122,7 +137,6 @@ describe('Rest Class Snippet Test for Gradle Project', () => { logger.step(5, 'Verifying snippet insertion'); const codeInsertion = await javaEditor.getText(); - logger.info('Inserted code snapshot: ' + codeInsertion); expect(codeInsertion).to.include('@GET') expect(codeInsertion).to.include('methodname'); logger.stepSuccess(5, 'Snippet rest_class was inserted correctly'); @@ -204,7 +218,6 @@ describe('Rest Class Snippet Test for Gradle Project', () => { // Check quick fix was implemented at correct line number const after = await javaEditor.getText(); - logger.info('Buffer after quick fix: ' + JSON.stringify(after)); expect(after).to.include('public String methodname'); problemsView = await bottomBar.openProblemsView(); diff --git a/src/test/MavenTestDevModeActions.ts b/src/test/MavenTestDevModeActions.ts index 33eac2f9..9a88dff8 100755 --- a/src/test/MavenTestDevModeActions.ts +++ b/src/test/MavenTestDevModeActions.ts @@ -15,12 +15,10 @@ describe('Devmode action tests for Maven Project', () => { 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(); diff --git a/src/test/MavenTestLSPRestSnippetAndDiagnostic.ts b/src/test/MavenTestLSPRestSnippetAndDiagnostic.ts index c6d808ed..e08324c8 100644 --- a/src/test/MavenTestLSPRestSnippetAndDiagnostic.ts +++ b/src/test/MavenTestLSPRestSnippetAndDiagnostic.ts @@ -50,26 +50,41 @@ describe('Rest Class Snippet Test for Maven Project', () => { }); after(async function() { - this.timeout(10000); // Increase timeout for cleanup operations - // Close editor after all tests complete + this.timeout(15000); try { - if(javaEditor){ - await javaEditor.setText(''); - await javaEditor.save(); - logger.info('Reset TestRest.java to empty after test') - - } - } catch (error){ - logger.error('Failed to reset TestRest.java ', error); + if (javaEditor) { + // Select all text first, then clear + const currentText = await javaEditor.getText(); + try { + await javaEditor.selectText(currentText); + await wait.sleep(300); + } catch (selectError) { + // selectText may fail but setText still works + } + + await javaEditor.setText(''); + await wait.sleep(500); + await javaEditor.save(); + await wait.sleep(500); + logger.info('Reset TestRest.java to empty after test'); } + } catch (error) { + logger.error('Failed to reset TestRest.java', error); + } + try { await editorView.closeAllEditors(); + await wait.sleep(500); logger.info('Closed all editors after test suite'); } catch (error) { logger.error('Failed to close editors in after hook', error); } - utils.copyScreenshotsToProjectFolder('maven'); + try { + utils.copyScreenshotsToProjectFolder('maven'); + } catch (error) { + // Ignore screenshot errors + } }); it('LSP4Jakarta Language Server should initialize', async function() { @@ -122,7 +137,6 @@ describe('Rest Class Snippet Test for Maven Project', () => { logger.step(5, 'Verifying snippet insertion'); const codeInsertion = await javaEditor.getText(); - logger.info('Inserted code snapshot: ' + codeInsertion); expect(codeInsertion).to.include('@GET') expect(codeInsertion).to.include('methodname'); logger.stepSuccess(5, 'Snippet rest_class was inserted correctly'); @@ -204,7 +218,6 @@ describe('Rest Class Snippet Test for Maven Project', () => { // Check quick fix was implemented at correct line number const after = await javaEditor.getText(); - logger.info('Buffer after quick fix: ' + JSON.stringify(after)); expect(after).to.include('public String methodname'); problemsView = await bottomBar.openProblemsView();