Skip to content

Commit

Permalink
new Close All Tabs code
Browse files Browse the repository at this point in the history
  • Loading branch information
vaisakhkannan committed Nov 12, 2024
1 parent 067446e commit d6a0ed6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
58 changes: 58 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 @@ -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.
Expand Down

0 comments on commit d6a0ed6

Please sign in to comment.