Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop the running terminal and then Clean and close all terminal tabs. #1049

Merged
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);
}

turkeylurkey marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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 @@ -10,31 +10,52 @@
package io.openliberty.tools.intellij.it;

import com.automation.remarks.junit5.Video;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.fixtures.ComponentFixture;
import com.intellij.remoterobot.utils.Keyboard;
import io.openliberty.tools.intellij.LibertyExplorer;
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;

/**
* Holds common tests that use a single module MicroProfile project.
*/
public abstract class SingleModMPProjectTestCommon {

private final static Logger LOGGER = Logger.getInstance(LibertyExplorer.class);

/**
* URL to display the UI Component hierarchy. This is used to obtain xPath related
* information to find UI components.
*/
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 +78,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 +108,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 +697,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 +1033,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 {
LOGGER.warn("Invalid build type specified.");
anusreelakshmi934 marked this conversation as resolved.
Show resolved Hide resolved
return;
}
keyboard.enter();
anusreelakshmi934 marked this conversation as resolved.
Show resolved Hide resolved
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 {
LOGGER.warn("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 +1170,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 @@ -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.
}
}
}
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
Loading