Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
287 changes: 13 additions & 274 deletions src/test/GradleTestDevModeActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,223 +3,31 @@
* Copyright IBM Corp. 2023, 2026
*/
import { expect } from 'chai';
import { DefaultTreeItem, EditorView, SideBarView, ViewItem, ViewSection, VSBrowser, Workbench, WebDriver } from 'vscode-extension-tester';
import { EditorView, VSBrowser } from 'vscode-extension-tester';
import { runDevModeTestSuite } from "./shared/devModeTestSuite";
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';

describe('Devmode action tests for Gradle Project', () => {
// Run shared dev mode tests
runDevModeTestSuite({
buildTool: 'gradle',
getProjectPath: utils.getGradleProjectPath,
projectConstant: constants.GRADLE_PROJECT,
testRunString: constants.GRADLE_TEST_RUN_STRING
});

// Gradle-specific tests in their own describe block
describe('Gradle-specific devmode action tests', () => {
let dashboard: DashboardPage;

before(async function() {
this.timeout(30000);

await VSBrowser.instance.openResources(utils.getGradleProjectPath());
await VSBrowser.instance.waitForWorkbench();

dashboard = new DashboardPage();
});

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');
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 - Gradle', async () => {
logger.testStart('Liberty Tools shows items - Gradle');
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 Gradle project item: ${constants.GRADLE_PROJECT}`);
const item = await dashboard.getProjectItem(constants.GRADLE_PROJECT);
logger.stepSuccess(4, 'Gradle project item found');
expect(item).not.undefined;

logger.testComplete('Liberty Tools shows items - Gradle');
} catch (error) {
logger.testFailed('Liberty Tools shows items - Gradle', error);
throw error;
}
}).timeout(275000);

it('Start Gradle project from Liberty Tools', async () => {
logger.testStart('Start Gradle project from Liberty Tools');
try {
logger.step(1, 'Getting dashboard section and item');
await dashboard.runAction(constants.GRADLE_PROJECT, 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(constants.GRADLE_PROJECT, 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 Gradle project from Liberty Tools');
} catch (error) {
logger.testFailed('Start Gradle project from Liberty Tools', error);
throw error;
}
}).timeout(350000);

it('Start Gradle with Docker from Liberty Tools', async () => {
logger.testStart('Start Gradle 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(constants.GRADLE_PROJECT, 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(constants.GRADLE_PROJECT, 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 Gradle with Docker from Liberty Tools');
} catch (error) {
logger.testFailed('Start Gradle with Docker from Liberty Tools', error);
throw error;
}
}).timeout(350000);

it('Run tests for Gradle project', async () => {
logger.testStart('Run tests for Gradle project');
try {
logger.step(1, 'Launching dashboard start action');
await dashboard.runAction(constants.GRADLE_PROJECT, 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(constants.GRADLE_PROJECT, constants.RUNTEST_DASHBOARD_ACTION, constants.RUNTEST_DASHBOARD_MAC_ACTION);

logger.step(4, 'Checking test execution status');
const testStatus = await utils.checkTestStatus(constants.GRADLE_TEST_RUN_STRING);
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(constants.GRADLE_PROJECT, 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 Gradle project');
} catch (error) {
logger.testFailed('Run tests for Gradle project', error);
throw error;
}
}).timeout(350000);


it('Start Gradle with options from Liberty Tools', async () => {
logger.testStart('Start Gradle with options from Liberty Tools');
try {
Expand Down Expand Up @@ -328,72 +136,6 @@ describe('Devmode action tests for Gradle Project', () => {
}
}).timeout(550000);

/**
* 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 Gradle with custom parameter event', async () => {
logger.testStart('Attach debugger for Gradle 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(constants.GRADLE_PROJECT, 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(constants.GRADLE_PROJECT, 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(constants.GRADLE_PROJECT);

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(constants.GRADLE_PROJECT);
} else {
logger.info('Server already stopped, test cleanup complete');
}
}

expect(attachStatus).to.be.true;
logger.testComplete('Attach debugger for Gradle with custom parameter event');
}).timeout(350000);

it('View test report for Gradle project', async () => {
logger.testStart('View test report for Gradle project');

Expand Down Expand Up @@ -423,8 +165,6 @@ describe('Devmode action tests for Gradle Project', () => {
}
}).timeout(30000);

// Based on the UI testing code, it sometimes selects the wrong command in "command palette", such as choosing "Liberty: Start ..." instead of "Liberty: Start" from the recent suggestions. This discrepancy occurs because we specifically need "Liberty: Start" at that moment.
// Now, clear the command history of the "command palette" to avoid receiving "recently used" suggestions. This action should be performed at the end of Gradle Project tests.
it('Clear Command Palette', async () => {
logger.testStart('Clear Command Palette');
try {
Expand All @@ -445,6 +185,5 @@ describe('Devmode action tests for Gradle Project', () => {
after(async function() {
this.timeout(10000);
await utils.closeWorkspace();
utils.copyScreenshotsToProjectFolder('gradle');
});
});
});
Loading
Loading