diff --git a/src/test/java/io/openliberty/tools/intellij/it/GradleSingleModMPProjectTest.java b/src/test/java/io/openliberty/tools/intellij/it/GradleSingleModMPProjectTest.java index a22df91ba..678b347c8 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/GradleSingleModMPProjectTest.java +++ b/src/test/java/io/openliberty/tools/intellij/it/GradleSingleModMPProjectTest.java @@ -60,6 +60,11 @@ public class GradleSingleModMPProjectTest extends SingleModMPProjectTestCommon { */ private final String BUILD_FILE_NAME = "build.gradle"; + /** + * Build Category. + */ + private final BuildType BUILD_CATEGORY = BuildType.GRADLE_TYPE; + /** * Action command to open the build file. */ @@ -202,4 +207,12 @@ public void validateTestReportsExist() { //TODO: rewrite validateTestReportExists() to accept one argument or to accept a null as the second argument TestUtils.validateTestReportExists(TEST_REPORT_PATH, TEST_REPORT_PATH); } + + /** + * Returns the build type category (either MAVEN_TYPE or GRADLE_TYPE) + */ + @Override + public BuildType getBuildCategory() { + return BUILD_CATEGORY; + } } \ No newline at end of file diff --git a/src/test/java/io/openliberty/tools/intellij/it/GradleSingleModMPSIDProjectTest.java b/src/test/java/io/openliberty/tools/intellij/it/GradleSingleModMPSIDProjectTest.java index 7596d4205..8c7923cc1 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/GradleSingleModMPSIDProjectTest.java +++ b/src/test/java/io/openliberty/tools/intellij/it/GradleSingleModMPSIDProjectTest.java @@ -74,6 +74,11 @@ public class GradleSingleModMPSIDProjectTest extends SingleModMPProjectTestCommo */ private final String BUILD_FILE_NAME = "build.gradle"; + /** + * Build Category. + */ + private final BuildType BUILD_CATEGORY = BuildType.GRADLE_TYPE; + /** * Action command to open the build file. */ @@ -255,4 +260,12 @@ public void deleteTestReports() { public void validateTestReportsExist() { TestUtils.validateTestReportExists(TEST_REPORT_PATH, TEST_REPORT_PATH); } + + /** + * Returns the build type category (either MAVEN_TYPE or GRADLE_TYPE) + */ + @Override + public BuildType getBuildCategory() { + return BUILD_CATEGORY; + } } \ No newline at end of file diff --git a/src/test/java/io/openliberty/tools/intellij/it/MavenSingleModMPProjectTest.java b/src/test/java/io/openliberty/tools/intellij/it/MavenSingleModMPProjectTest.java index 32a3a92d9..8b49902cc 100755 --- a/src/test/java/io/openliberty/tools/intellij/it/MavenSingleModMPProjectTest.java +++ b/src/test/java/io/openliberty/tools/intellij/it/MavenSingleModMPProjectTest.java @@ -57,6 +57,11 @@ public class MavenSingleModMPProjectTest extends SingleModMPProjectTestCommon { */ private final String BUILD_FILE_NAME = "pom.xml"; + /** + * Build Category. + */ + private final BuildType BUILD_CATEGORY = BuildType.MAVEN_TYPE; + /** * Action command to open the build file. */ @@ -219,4 +224,12 @@ public void validateTestReportsExist() { TestUtils.validateTestReportExists(pathToITReport34, pathToITReport35); TestUtils.validateTestReportExists(pathToUTReport34, pathToUTReport35); } + + /** + * Returns the build type category (either MAVEN_TYPE or GRADLE_TYPE) + */ + @Override + public BuildType getBuildCategory() { + return BUILD_CATEGORY; + } } diff --git a/src/test/java/io/openliberty/tools/intellij/it/MavenSingleModMPSIDProjectTest.java b/src/test/java/io/openliberty/tools/intellij/it/MavenSingleModMPSIDProjectTest.java index 186e7a4e9..f9322b814 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/MavenSingleModMPSIDProjectTest.java +++ b/src/test/java/io/openliberty/tools/intellij/it/MavenSingleModMPSIDProjectTest.java @@ -64,6 +64,11 @@ public class MavenSingleModMPSIDProjectTest extends SingleModMPProjectTestCommon */ private final String BUILD_FILE_NAME = "pom.xml"; + /** + * Build Category. + */ + private final BuildType BUILD_CATEGORY = BuildType.MAVEN_TYPE; + /** * Action command to open the build file. */ @@ -245,4 +250,12 @@ public void validateTestReportsExist() { TestUtils.validateTestReportExists(pathToITReport34, pathToITReport35); TestUtils.validateTestReportExists(pathToUTReport34, pathToUTReport35); } + + /** + * Returns the build type category (either MAVEN_TYPE or GRADLE_TYPE) + */ + @Override + public BuildType getBuildCategory() { + return BUILD_CATEGORY; + } } diff --git a/src/test/java/io/openliberty/tools/intellij/it/SingleModMPProjectTestCommon.java b/src/test/java/io/openliberty/tools/intellij/it/SingleModMPProjectTestCommon.java index b81c26b6b..b4c55edde 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/SingleModMPProjectTestCommon.java +++ b/src/test/java/io/openliberty/tools/intellij/it/SingleModMPProjectTestCommon.java @@ -11,17 +11,22 @@ import com.automation.remarks.junit5.Video; import com.intellij.remoterobot.RemoteRobot; +import com.intellij.remoterobot.fixtures.ComponentFixture; +import com.intellij.remoterobot.utils.Keyboard; +import io.openliberty.tools.intellij.it.fixtures.ProjectFrameFixture; import io.openliberty.tools.intellij.it.fixtures.WelcomeFrameFixture; import org.junit.jupiter.api.*; import org.junit.jupiter.api.condition.EnabledOnOs; import org.junit.jupiter.api.condition.OS; +import java.awt.Point; import java.io.File; import java.io.IOException; import java.nio.file.Paths; import java.time.Duration; import java.util.Map; +import static com.intellij.remoterobot.search.locators.Locators.byXpath; import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError; /** @@ -35,6 +40,18 @@ public abstract class SingleModMPProjectTestCommon { */ public static final String REMOTE_BOT_URL = "http://localhost:8082"; + /** + * To clean the terminal. + */ + private boolean shouldCleanupTerminal = true; + + /** + * Supported build types. + */ + public enum BuildType { + MAVEN_TYPE, GRADLE_TYPE + } + /** * The remote robot object. */ @@ -57,6 +74,9 @@ public void beforeEach(TestInfo info) { */ @AfterEach public void afterEach(TestInfo info) { + if (shouldCleanupTerminal) { + cleanAndResetTerminal(); + } TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, this.getClass().getSimpleName() + "." + info.getDisplayName() + ". Exit"); } @@ -84,6 +104,7 @@ protected static void closeProjectView() { @Test @Video public void testOpenBuildFileActionUsingPopUpMenu() { + shouldCleanupTerminal = false; String editorTabName = getBuildFileName() + " (" + getSmMPProjectName() + ")"; // Close the editor tab if it was previously opened. @@ -672,6 +693,7 @@ public void testStartWithConfigInRunModeUsingMenu() { @Test @Video public void testMultipleConfigEditHistory() { + shouldCleanupTerminal = false; String testName = "testMultipleConfigEditHistory"; // The path of the project build file expected in the configuration. This path constant for this test. @@ -1007,6 +1029,62 @@ public static void deleteDirectoryIfExists(String dirPath) { } } + /** + * Clean project. + */ + public void stopTerminal() { + + Keyboard keyboard = new Keyboard(remoteRobot); + ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofSeconds(10)); + ComponentFixture terminal = remoteRobot.find(ComponentFixture.class, byXpath("//div[@class='JBTerminalPanel']"), Duration.ofSeconds(10)); + + terminal.rightClick(); + ComponentFixture openFixtureNewTab = projectFrame.getActionMenuItem("New Tab"); + openFixtureNewTab.click(new Point()); + + // Perform Stop Action + if (getBuildCategory() == BuildType.MAVEN_TYPE) { + keyboard.enterText("./mvnw liberty:stop"); + } else if (getBuildCategory() == BuildType.GRADLE_TYPE) { + keyboard.enterText("./gradlew libertyStop"); + } else { + TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, "Invalid build type specified"); + return; + } + keyboard.enter(); + TestUtils.sleepAndIgnoreException(10); + } + + /** + * Stop the Server. + */ + public void cleanTerminal() { + + Keyboard keyboard = new Keyboard(remoteRobot); + // Perform clean + if (getBuildCategory() == BuildType.MAVEN_TYPE) { + keyboard.enterText("./mvnw clean"); + } else if (getBuildCategory() == BuildType.GRADLE_TYPE) { + keyboard.enterText("./gradlew clean"); + } else { + TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, "Invalid build type specified"); + return; + } + keyboard.enter(); + TestUtils.sleepAndIgnoreException(10); + } + + /** + * Cleans up and resets the terminal. + */ + public void cleanAndResetTerminal() { + stopTerminal(); + UIBotTestUtils.closeTerminalTabs(remoteRobot); + UIBotTestUtils.openTerminalWindow(remoteRobot); + cleanTerminal(); + UIBotTestUtils.closeTerminalTabs(remoteRobot); + } + /** * Returns the projects directory path. * @@ -1088,4 +1166,9 @@ public static void deleteDirectoryIfExists(String dirPath) { * Validates that test reports were generated. */ public abstract void validateTestReportsExist(); + + /** + * Returns Build Category + */ + public abstract BuildType getBuildCategory(); } \ No newline at end of file diff --git a/src/test/java/io/openliberty/tools/intellij/it/UIBotTestUtils.java b/src/test/java/io/openliberty/tools/intellij/it/UIBotTestUtils.java index 0e4d07615..9e075dcc9 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/UIBotTestUtils.java +++ b/src/test/java/io/openliberty/tools/intellij/it/UIBotTestUtils.java @@ -2498,4 +2498,27 @@ public static void closeErrorDialog(RemoteRobot remoteRobot) { okButton.click(); } } + + /** + * Closes Terminal. + */ + public static void closeTerminalTabs(RemoteRobot remoteRobot) { + ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofSeconds(10)); + try { + ProjectFrameFixture.rightClickOnTerminalTab(projectFrame); + ProjectFrameFixture.clickMenuOption(projectFrame, "action.CloseAllNotifications.text"); + + while (true) { + ComponentFixture terminateButton = projectFrame.find(ComponentFixture.class, byXpath("//div[@accessiblename='Terminate']")); + if (terminateButton.callJs("component.isEnabled();", false)) { + terminateButton.click(); + TestUtils.sleepAndIgnoreException(10); + } else { + break; // Exit loop if no enabled "Terminate" button is found + } + } + } catch (WaitForConditionTimeoutException e) { + // The Terminal tab is most likely closed. + } + } } diff --git a/src/test/java/io/openliberty/tools/intellij/it/fixtures/ProjectFrameFixture.java b/src/test/java/io/openliberty/tools/intellij/it/fixtures/ProjectFrameFixture.java index 2416c2fef..5b1d476e7 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/fixtures/ProjectFrameFixture.java +++ b/src/test/java/io/openliberty/tools/intellij/it/fixtures/ProjectFrameFixture.java @@ -217,6 +217,24 @@ public ComponentFixture getTree(String... xpathVars) { Duration.ofSeconds(Integer.parseInt(waitTime))); } + /** + * Right-clicks on the terminal tab. + */ + public static void rightClickOnTerminalTab(ProjectFrameFixture projectFrame) { + String terminalLabelXPath = "//div[@class='TabPanel'][.//div[@class='BaseLabel']]//div[@text='Terminal:']"; + ComponentFixture terminalLabel = projectFrame.getActionButton(terminalLabelXPath, "10"); + terminalLabel.rightClick(); + } + + /** + * Clicks on a menu option based on the text key provided. + */ + public static void clickMenuOption(ProjectFrameFixture projectFrame, String textKey) { + String optionXPath = String.format("//div[contains(@text.key, '%s')]", textKey); + ComponentFixture option = projectFrame.getActionButton(optionXPath, "10"); + option.click(); + } + /** * Return the ComponentFixture object associated with the InplaceButton class. *