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 47199e1b9..8d8345334 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/SingleModMPProjectTestCommon.java +++ b/src/test/java/io/openliberty/tools/intellij/it/SingleModMPProjectTestCommon.java @@ -928,7 +928,8 @@ public static void prepareEnv(String projectPath, String projectName) { // Closing the build file editor here prevents it from opening automatically when the project // in the Liberty tool window is clicked or right-clicked again. This is done on purpose to // prevent false negative tests related to the build file editor tab. - UIBotTestUtils.closeAllEditorTabs(remoteRobot); +// UIBotTestUtils.closeAllEditorTabs(remoteRobot); + UIBotTestUtils.closeAllTabsUsingSearchEverywherePanel(remoteRobot, "Close All Tabs", 3); TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, "prepareEnv. Exit. ProjectName: " + projectName); 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 f869ba24d..b1a98940f 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/UIBotTestUtils.java +++ b/src/test/java/io/openliberty/tools/intellij/it/UIBotTestUtils.java @@ -1767,6 +1767,64 @@ public static void runActionFromSearchEverywherePanel(RemoteRobot remoteRobot, S } } + public static void closeAllTabsUsingSearchEverywherePanel(RemoteRobot remoteRobot, String action, int maxRetries) { + // Search everywhere UI actions may fail due to UI flickering/indexing on Windows. Retry in case of a failure. + Exception error = null; + for (int i = 0; i < maxRetries; i++) { + try { + error = null; + + // Click on Navigate on the Menu bar. + ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofMinutes(2)); + clickOnFileTabNew(remoteRobot, "Main Menu"); + ComponentFixture navigateMenuEntry = projectFrame.getActionMenu("Navigate", "20"); + navigateMenuEntry.moveMouse(); + + // Click on Search Everywhere in the menu. + ComponentFixture searchFixture = projectFrame.getActionMenuItem("Search Everywhere"); + searchFixture.click(); + + // Click on the Actions tab + ComponentFixture actionsTabFixture = projectFrame.getSETabLabel("Actions"); + actionsTabFixture.click(); + + // Type the search string in the search dialog box. + JTextFieldFixture searchField = projectFrame.textField(JTextFieldFixture.Companion.byType(), Duration.ofSeconds(10)); + searchField.click(); + searchField.setText(action); + TestUtils.sleepAndIgnoreException(1); // allow search time to resolve + + // Wait for the desired action to show in the search output frame and click on it. + RepeatUtilsKt.waitFor(Duration.ofSeconds(20), + Duration.ofSeconds(1), + "Waiting for the search to filter and show " + action + " in search output", + "The search did not filter or show " + action + " in the search output", + () -> findTextInListOutputPanel(projectFrame, action) != null); + + RemoteText foundAction = findTextInListOutputPanel(projectFrame, action); + if (foundAction != null) { + foundAction.click(); + } else { + throw new RuntimeException("Search everywhere found " + action + ", but it can no longer be found after a subsequent attempt to find it."); + } + + // If the Liberty: Start... action was selected, make sure the Edit Configuration dialog is displayed. + break; + } catch (Exception e) { + error = e; + TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, + "Failed to run the " + action + " action using the search everywhere option (" + e.getMessage() + "). Retrying..."); + TestUtils.sleepAndIgnoreException(5); + } + } + + // Report the last error if there is one. + if (error != null) { + throw new RuntimeException("Failed to run the " + action + " action using the search everywhere option", error); + } + } + + /** * Selects the specified project from the list of detected projects shown in the 'Add Liberty project' * dialog.