From 68f4e3ff3b0c7c3732bf6aebf1cbcef97d2d49fa Mon Sep 17 00:00:00 2001 From: Stephane Bouchet Date: Thu, 9 Jan 2025 18:02:03 +0100 Subject: [PATCH] chore: fix integration tests Signed-off-by: Stephane Bouchet --- .gitignore | 1 + .../intellij/commonuitest/UITestRunner.java | 45 ++++++------------- .../fixtures/dialogs/FlatWelcomeFrame.java | 19 +++++--- .../utils/constants/XPathDefinitions.java | 13 ++++++ .../utils/runner/IntelliJVersion.java | 13 +----- .../commonuitest/LibraryTestBase.java | 16 ++----- 6 files changed, 44 insertions(+), 63 deletions(-) diff --git a/.gitignore b/.gitignore index c7579082..7ff38414 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ build/ target/ pom.xml +/src/test-project/.intellijPlatform/self-update.lock diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/UITestRunner.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/UITestRunner.java index 13fafeca..ade49a16 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/UITestRunner.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/UITestRunner.java @@ -72,14 +72,11 @@ public static RemoteRobot runIde(IntelliJVersion ideaVersion, int port) { UITestRunner.ideaVersion = ideaVersion; acceptAllTermsAndConditions(); - if (ideaVersion.isUltimate()) { - activateEvaluateForFree(); - } String fileExtension = OS_NAME.contains("windows") ? ".bat" : ""; String[] platformTypeVersion = generatePlatformTypeVersion(); - ProcessBuilder pb = null; + ProcessBuilder pb; if (ideaVersion.toInt() < 20242) { pb = new ProcessBuilder("." + File.separator + "gradlew" + fileExtension, "runIdeForUiTests", "-PideaVersion=" + ideaVersion, "-Drobot-server.port=" + port); @@ -176,18 +173,14 @@ public static RemoteRobot getRemoteRobotConnection(int port) { private static void acceptAllTermsAndConditions() { String osxPlistSourceLocation; - if (ideaVersion.isUltimate()) { - osxPlistSourceLocation = "plist/ultimate_all/com.apple.java.util.prefs.plist"; - } else if (ideaVersion.toInt() <= 20213) { + if (ideaVersion.toInt() <= 20213) { osxPlistSourceLocation = "plist/2021_3_and_older/com.apple.java.util.prefs.plist"; } else { osxPlistSourceLocation = "plist/2022_1/com.apple.java.util.prefs.plist"; } String linuxPrefsXmlSourceLocation; - if (ideaVersion.isUltimate()) { - linuxPrefsXmlSourceLocation = "prefs_xml/ultimate_all/prefs.xml"; - } else if (ideaVersion.toInt() <= 20213) { + if (ideaVersion.toInt() <= 20213) { linuxPrefsXmlSourceLocation = "prefs_xml/2021_3_and_older/prefs.xml"; } else { linuxPrefsXmlSourceLocation = "prefs_xml/2022_1/prefs.xml"; @@ -259,18 +252,6 @@ private static void acceptAllTermsAndConditions() { } } - private static void activateEvaluateForFree() { - String targetEvaluationKeysDir = System.getProperty("user.dir") + "/build/idea-sandbox/config-uiTest/eval/"; - createDirectoryHierarchy(targetEvaluationKeysDir); - - for (String ideaVersionSubstring : new String[]{"202", "203", "211", "212"}) { - String keyFilename = "idea" + ideaVersionSubstring + ".evaluation.key"; - String sourcePathToKey = "evaluate_for_free_keys/" + keyFilename; - String targetPathToKey = targetEvaluationKeysDir + keyFilename; - copyFileFromJarResourceDir(sourcePathToKey, targetPathToKey); - } - } - private static void waitUntilIntelliJStarts(int port) { waitFor(Duration.ofSeconds(600), Duration.ofSeconds(3), "The IntelliJ Idea did not start in 10 minutes.", () -> isIntelliJUIVisible(port)); } @@ -308,14 +289,16 @@ private static void createDirectoryHierarchy(String location) { } private static void copyFileFromJarResourceDir(String sourceFileLocation, String destFileLocation) { - InputStream resourceStream = UITestRunner.class.getClassLoader().getResourceAsStream(sourceFileLocation); - try (OutputStream outStream = new FileOutputStream(new File(destFileLocation))) { - byte[] buffer = new byte[resourceStream.available()]; - int count = resourceStream.read(buffer); - if (count == 0) { - throw new UITestException("Reading from buffer was unsuccessful."); + try (OutputStream outStream = new FileOutputStream(destFileLocation); + InputStream resourceStream = UITestRunner.class.getClassLoader().getResourceAsStream(sourceFileLocation)) { + if (resourceStream != null) { + byte[] buffer = new byte[resourceStream.available()]; + int count = resourceStream.read(buffer); + if (count == 0) { + throw new UITestException("Reading from buffer was unsuccessful."); + } + outStream.write(buffer); } - outStream.write(buffer); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } @@ -324,7 +307,7 @@ private static void copyFileFromJarResourceDir(String sourceFileLocation, String /** * Redirect stdout and stderr of running subprocess to files * - * @param pb Process builder of running subprocess + * @param pb Process builder of running subprocess */ private static void redirectProcessOutputs(ProcessBuilder pb) { String outDir = System.getProperty("user.dir") + File.separator + "intellij_debug"; @@ -346,7 +329,7 @@ private static void redirectProcessOutputs(ProcessBuilder pb) { */ private static String[] generatePlatformTypeVersion() { String[] platformTypeVersion = ideaVersion.toString().split("-", 2); - if (2 > platformTypeVersion.length){ + if (2 > platformTypeVersion.length) { throw new UITestException("ideaVersion is not recognized."); } return platformTypeVersion; diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/FlatWelcomeFrame.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/FlatWelcomeFrame.java index 8681a433..f3890f69 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/FlatWelcomeFrame.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/FlatWelcomeFrame.java @@ -23,18 +23,20 @@ import com.redhat.devtools.intellij.commonuitest.utils.constants.ButtonLabels; import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions; import com.redhat.devtools.intellij.commonuitest.utils.project.CreateCloseUtils; -import com.redhat.devtools.intellij.commonuitest.utils.runner.IntelliJVersion; import com.redhat.devtools.intellij.commonuitest.utils.steps.SharedSteps; import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; +import java.util.Comparator; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Stream; import static com.intellij.remoterobot.search.locators.Locators.byXpath; @@ -50,14 +52,12 @@ public class FlatWelcomeFrame extends CommonContainerFixture { private static final String PROJECTS_BUTTON = "Projects"; private static final String TIP_OF_THE_DAY = "Tip of the Day"; private final RemoteRobot remoteRobot; - private final IntelliJVersion intelliJVersion; private final int ideaVersion; public FlatWelcomeFrame(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) { super(remoteRobot, remoteComponent); this.remoteRobot = remoteRobot; - this.intelliJVersion = UITestRunner.getIdeaVersion(); - this.ideaVersion = intelliJVersion.toInt(); + this.ideaVersion = UITestRunner.getIdeaVersion().toInt(); } /** @@ -100,11 +100,16 @@ public void clearWorkspace() { // Remove projects on disk try { String pathToDirToMakeEmpty = CreateCloseUtils.PROJECT_LOCATION; - boolean doesProjectDirExists = Files.exists(Paths.get(pathToDirToMakeEmpty)); + Path path = Paths.get(pathToDirToMakeEmpty); + boolean doesProjectDirExists = Files.exists(path); if (doesProjectDirExists) { - Files.delete(new File(pathToDirToMakeEmpty).toPath()); + try (Stream pathStream = Files.walk(new File(pathToDirToMakeEmpty).toPath())) { + pathStream.sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } } else { - Files.createDirectories(Paths.get(pathToDirToMakeEmpty)); + Files.createDirectories(path); } } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/XPathDefinitions.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/XPathDefinitions.java index 63d511ba..1e419116 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/XPathDefinitions.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/XPathDefinitions.java @@ -11,6 +11,7 @@ package com.redhat.devtools.intellij.commonuitest.utils.constants; import com.redhat.devtools.intellij.commonuitest.exceptions.UITestException; +import org.intellij.lang.annotations.Language; /** * XPath definitions @@ -39,10 +40,15 @@ public class XPathDefinitions { public static final String IDE_FATAL_ERRORS_DIALOG = "//div[@accessiblename='IDE Fatal Errors' and @class='MyDialog']"; public static final String PROJECT_STRUCTURE_DIALOG = "//div[@accessiblename='Project Structure' and @class='MyDialog']"; public static final String TIP_DIALOG = "//div[@accessiblename='Tip of the Day' and @class='MyDialog']"; + @Language("XPath") public static final String TIP_DIALOG_2 = "//div[@text='Tip of the Day']"; + @Language("XPath") public static final String RECENT_PROJECTS = "//div[@accessiblename='Recent Projects']"; + @Language("XPath") public static final String RECENT_PROJECT_PANEL_NEW = "//div[@class='NewRecentProjectPanel']"; + @Language("XPath") public static final String RECENT_PROJECT_PANEL_NEW_2 = "//div[@class='JBViewport']/*"; + @Language("XPath") public static final String IDE_ERROR_ICON = "//div[@class='IdeErrorsIcon']"; public static final String BUILD_VIEW_EDITOR = "//div[@accessiblename='Editor']"; public static final String JCOMBOBOX = "//div[@class='JComboBox']"; @@ -51,7 +57,9 @@ public class XPathDefinitions { public static final String HEAVY_WEIGHT_WINDOW = "//div[@class='HeavyWeightWindow']"; public static final String JDK_COMBOBOX = "//div[@class='JdkComboBox']"; public static final String JDK_COMBOBOX_PROJECT_WIZARD = "//div[@class='ProjectWizardJdkComboBox']"; // works for IntelliJ Idea 2024.1 and higher + @Language("XPath") public static final String MY_DIALOG = "//div[@class='MyDialog']"; + @Language("XPath") public static final String TREE = "//div[@class='Tree']"; public static final String TOOLTIP_TEXT_PROJECT = "//div[@tooltiptext='Project']"; public static final String TOOLTIP_TEXT_HIDE = "//div[contains(@myvisibleactions, 'View),')]//div[@tooltiptext='Hide']"; @@ -68,8 +76,11 @@ public class XPathDefinitions { public static final String MY_ICON_LOCATE_SVG = "//div[@myicon='locate.svg']"; public static final String MY_ICON_REFRESH = "//div[@myicon='refresh.svg']"; public static final String CONTENT_COMBO_LABEL = "//div[@class='ContentComboLabel']"; + @Language("XPath") public static final String JBLIST = "//div[@class='JBList']"; + @Language("XPath") public static final String DIALOG_PANEL = "//div[@class='DialogPanel']"; + @Language("XPath") public static final String MY_LIST = "//div[@class='MyList']"; public static final String CODE_WITH_ME_JPANEL = "//div[@class='Wrapper'][.//div[@class='JBLabel']]//div[@class='JPanel']"; public static final String BREAD_CRUMBS = "//div[@class='Breadcrumbs']"; @@ -81,6 +92,7 @@ public class XPathDefinitions { public static final String COLLAPSIBLE_TITLED_SEPARATOR_NEW_SIBLINGS = COLLAPSIBLE_TITLED_SEPARATOR_NEW + "/../*"; public static final String EXTENDABLE_TEXT_FIELD = "//div[@class='ExtendableTextField']"; public static final String JBTEXT_FIELD = "//div[@class='JBTextField']"; + @Language("XPath") public static final String REMOVE_PROJECT_BUTTON = "//div[contains(@text.key, 'button.remove')]"; public static final String SET_LANGUAGE = "//div[@class='SegmentedButtonComponent'][.//div[contains(@action.key, 'language.groovy')]]"; public static final String SET_BUILD_SYSTEM = "//div[@class='SegmentedButtonComponent'][.//div[@action.key='buildsystem.type.intellij']]"; @@ -89,6 +101,7 @@ public class XPathDefinitions { public static final String GET_SET_MODULE_NAME_2024_2_AND_NEWER = "//div[@accessiblename='Module name:' and @class='JBTextField']"; public static final String GET_SET_CONTENT_ROOT = "//div[@accessiblename='Content root:' and @class='ExtendableTextField']"; public static final String GET_SET_MODULE_FILE_LOCATION = "//div[@accessiblename='Module file location:' and @class='ExtendableTextField']"; + @Language("XPath") public static final String CREATE_NEW_PROJECT = "//div[@defaulticon='createNewProjectTab.svg']"; // works for IntelliJ Idea 2024.1 and higher private XPathDefinitions() { diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/runner/IntelliJVersion.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/runner/IntelliJVersion.java index 4a2b95aa..36a964de 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/runner/IntelliJVersion.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/runner/IntelliJVersion.java @@ -28,17 +28,10 @@ public enum IntelliJVersion { COMMUNITY_V_2023_2("IC-2023.2"), COMMUNITY_V_2024_1("IC-2024.1"), COMMUNITY_V_2024_2("IC-2024.2"), - ULTIMATE_V_2020_2("IU-2020.2"), - ULTIMATE_V_2020_3("IU-2020.3"), - ULTIMATE_V_2021_1("IU-2021.1"), - ULTIMATE_V_2021_2("IU-2021.2"), - ULTIMATE_V_2023_2("IU-2023.2"), - ULTIMATE_V_2024_1("IU-2024.1"), - ULTIMATE_V_2024_2("IU-2024.2"); + COMMUNITY_V_2024_3("IC-2024.3"); private final String ideaVersionStringRepresentation; private final int ideaVersionIntRepresentation; - private final boolean isIdeaUltimate; IntelliJVersion(String ideaVersionStringRepresentation) { this.ideaVersionStringRepresentation = ideaVersionStringRepresentation; @@ -46,7 +39,6 @@ public enum IntelliJVersion { String ideaVersionString = this.ideaVersionStringRepresentation.substring(3).replace(".", ""); this.ideaVersionIntRepresentation = Integer.parseInt(ideaVersionString); - this.isIdeaUltimate = this.ideaVersionStringRepresentation.charAt(1) == 'U'; } @Override @@ -58,7 +50,4 @@ public int toInt() { return this.ideaVersionIntRepresentation; } - public boolean isUltimate() { - return this.isIdeaUltimate; - } } diff --git a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/LibraryTestBase.java b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/LibraryTestBase.java index 2e34d871..faf9239d 100644 --- a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/LibraryTestBase.java +++ b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/LibraryTestBase.java @@ -21,7 +21,6 @@ import org.junit.jupiter.api.extension.ExtendWith; import java.time.Duration; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -33,25 +32,16 @@ public class LibraryTestBase { protected static final Logger LOGGER = Logger.getLogger(LibraryTestBase.class.getName()); private static final IntelliJVersion communityIdeaVersion = IntelliJVersion.COMMUNITY_V_2024_2; - private static final IntelliJVersion ultimateIdeaVersion = IntelliJVersion.ULTIMATE_V_2024_2; protected static RemoteRobot remoteRobot; protected static int ideaVersionInt; private static boolean intelliJHasStarted = false; - private static final int port = 8580; + private static final int TEST_RUNNER_PORT = 8580; @BeforeAll protected static void startIntelliJ() { if (!intelliJHasStarted) { - String taskName = System.getProperty("task.name"); - if (taskName != null && taskName.equalsIgnoreCase("integrationUITestUltimate")) { - // Run UI tests for ultimate version - ideaVersionInt = ultimateIdeaVersion.toInt(); - remoteRobot = UITestRunner.runIde(ultimateIdeaVersion, port); - } else { - // Run UI tests for community version - ideaVersionInt = communityIdeaVersion.toInt(); - remoteRobot = UITestRunner.runIde(communityIdeaVersion, port); - } + ideaVersionInt = communityIdeaVersion.toInt(); + remoteRobot = UITestRunner.runIde(communityIdeaVersion, TEST_RUNNER_PORT); intelliJHasStarted = true; Runtime.getRuntime().addShutdownHook(new CloseIntelliJBeforeQuit());