Skip to content

Commit

Permalink
Merge pull request #1049 from anusreelakshmi934/Issue-929-cleanupterm…
Browse files Browse the repository at this point in the history
…inal

Stop the running terminal and then Clean and close all terminal tabs.
  • Loading branch information
anusreelakshmi934 authored Nov 7, 2024
2 parents efe3fed + a7f96ee commit 9272646
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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.
*/
Expand All @@ -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");
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();
}
23 changes: 23 additions & 0 deletions src/test/java/io/openliberty/tools/intellij/it/UIBotTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2510,4 +2510,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.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 9272646

Please sign in to comment.