Skip to content

Commit

Permalink
Merge pull request #927 from turkeylurkey/mac-test-5
Browse files Browse the repository at this point in the history
Handle O/S windows covering IntelliJ
  • Loading branch information
turkeylurkey authored Oct 16, 2024
2 parents e39bd3b + 4d9456f commit 01b4c36
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ jobs:
with:
name: ${{ matrix.reportName }}-LTI-${{ env.REF_LTI_TAG || 'default' }}-LSP4IJ-${{ env.LSP4IJ_BRANCH }}
path: |
liberty-tools-intellij/build/reports/
liberty-tools-intellij/build/reports/
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ public static void prepareEnv(String projectPath, String projectName) {

UIBotTestUtils.importProject(remoteRobot, projectPath, projectName);
UIBotTestUtils.openProjectView(remoteRobot);
UIBotTestUtils.openLibertyToolWindow(remoteRobot);
UIBotTestUtils.validateImportedProjectShowsInLTW(remoteRobot, projectName);
UIBotTestUtils.closeLibertyToolWindow(remoteRobot);
// IntelliJ does not start building and indexing until the project is open in the UI
UIBotTestUtils.waitForIndexing(remoteRobot);
UIBotTestUtils.openAndValidateLibertyToolWindow(remoteRobot, projectName);
UIBotTestUtils.closeLibertyToolWindow(remoteRobot);

// pre-open project tree before attempting to open files needed by testcases
ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofMinutes(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public void testInsertLibertyConfigElementIntoServerXML() {
// Insert a new element in server.xml.
try {
UIBotTestUtils.insertStanzaInAppServerXML(remoteRobot, stanzaSnippet, 20, 0, UIBotTestUtils.InsertionType.ELEMENT, true);
TestUtils.sleepAndIgnoreException(2); // wait for editor to update
Path pathToServerXML = Paths.get(projectsPath, projectName, "src", "main", "liberty", "config", "server.xml");
TestUtils.validateStanzaInConfigFile(pathToServerXML.toString(), insertedConfig);
} finally {
Expand Down Expand Up @@ -390,10 +391,10 @@ public static void prepareEnv(String projectPath, String projectName) {

UIBotTestUtils.importProject(remoteRobot, projectPath, projectName);
UIBotTestUtils.openProjectView(remoteRobot);
UIBotTestUtils.openLibertyToolWindow(remoteRobot);
UIBotTestUtils.validateImportedProjectShowsInLTW(remoteRobot, projectName);
UIBotTestUtils.closeLibertyToolWindow(remoteRobot);
// IntelliJ does not start building and indexing until the project is open in the UI
UIBotTestUtils.waitForIndexing(remoteRobot);
UIBotTestUtils.openAndValidateLibertyToolWindow(remoteRobot, projectName);
UIBotTestUtils.closeLibertyToolWindow(remoteRobot);

// get a JTreeFixture reference to the file project viewer entry
ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofMinutes(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,14 @@ public static void prepareEnv(String projectPath, String projectName) {

UIBotTestUtils.importProject(remoteRobot, projectPath, projectName);
UIBotTestUtils.openProjectView(remoteRobot);
UIBotTestUtils.openLibertyToolWindow(remoteRobot);
UIBotTestUtils.validateImportedProjectShowsInLTW(remoteRobot, projectName);
// IntelliJ does not start building and indexing until the project is open in the UI
UIBotTestUtils.waitForIndexing(remoteRobot);
UIBotTestUtils.openAndValidateLibertyToolWindow(remoteRobot, projectName);
UIBotTestUtils.closeLibertyToolWindow(remoteRobot);

// pre-open project tree before attempting to open files needed by testcases
ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofMinutes(2));
JTreeFixture projTree = projectFrame.getProjectViewJTree(projectName);
UIBotTestUtils.waitForIndexing(remoteRobot);

UIBotTestUtils.openFile(remoteRobot, projectName, "ServiceLiveHealthCheck", projectName, "src", "main", "java", "io.openliberty.mp.sample", "health");
UIBotTestUtils.openFile(remoteRobot, projectName, "microprofile-config.properties", projectName, "src", "main", "resources", "META-INF");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,8 +915,9 @@ public static void prepareEnv(String projectPath, String projectName) {
remoteRobot.find(WelcomeFrameFixture.class, Duration.ofMinutes(2));
UIBotTestUtils.importProject(remoteRobot, projectPath, projectName);
UIBotTestUtils.openProjectView(remoteRobot);
UIBotTestUtils.openLibertyToolWindow(remoteRobot);
UIBotTestUtils.validateImportedProjectShowsInLTW(remoteRobot, projectName);
// IntelliJ does not start building and indexing until the project is open in the UI
UIBotTestUtils.waitForIndexing(remoteRobot);
UIBotTestUtils.openAndValidateLibertyToolWindow(remoteRobot, projectName);
UIBotTestUtils.expandLibertyToolWindowProjectTree(remoteRobot, projectName);

// Close all open editors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ public static void prepareEnv(String projectPath, String projectName) {
remoteRobot.find(WelcomeFrameFixture.class, Duration.ofMinutes(2));
UIBotTestUtils.importProject(remoteRobot, projectPath, projectName);
UIBotTestUtils.openProjectView(remoteRobot);
// IntelliJ does not start building and indexing until the project is open in the UI
UIBotTestUtils.waitForIndexing(remoteRobot);
UIBotTestUtils.openLibertyToolWindow(remoteRobot);

// Wait for indexing to complete. Once indexing completes and Liberty Tools to take control
Expand Down
35 changes: 30 additions & 5 deletions src/test/java/io/openliberty/tools/intellij/it/UIBotTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,10 @@ public static RemoteText findProjectInLibertyToolWindow(RemoteRobot remoteRobot,
* @param remoteRobot The RemoteRobot instance.
* @param treeItem The name of tree item to look for.
*/
public static void validateImportedProjectShowsInLTW(RemoteRobot remoteRobot, String treeItem) {
public static boolean validateImportedProjectShowsInLTW(RemoteRobot remoteRobot, String treeItem) {
ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofSeconds(10));

// The following comment refers to indexing but more recent changes wait for indexing to stop
// There is a window between which the Liberty tool window content may show
// and suddenly disappear when indexing starts. It is not known when indexing may start.
// It can be immediate or take a few seconds (10+). Wait a bit for it to start.
Expand All @@ -378,13 +379,14 @@ public static void validateImportedProjectShowsInLTW(RemoteRobot remoteRobot, St
// that the project is displayed in the Liberty tool window.
}

// Wait for the project to appear in the Liberty tool window. Indexing is a long process right now.
ComponentFixture treeFixture = projectFrame.getTree("LibertyTree", treeItem, "600");
// Wait for the project to appear in the Liberty tool window. This line is sensitive to indexing and depends on the code that waits for indexing before continuing.
ComponentFixture treeFixture = projectFrame.getTree("LibertyTree", treeItem, "10");
RepeatUtilsKt.waitFor(Duration.ofSeconds(10),
Duration.ofSeconds(2),
"Waiting for tree item" + treeItem + " to show in the Liberty tool window.",
"Tree item " + treeItem + " did not show in Liberty tool window.",
treeFixture::isShowing);
return treeFixture.isShowing();
}

/**
Expand All @@ -396,6 +398,25 @@ public static void validateProjectFrameClosed(RemoteRobot remoteRobot) {
remoteRobot.find(WelcomeFrameFixture.class, Duration.ofMinutes(2));
}

/**
* Open and validate the Liberty tool window is open
*/
public static void openAndValidateLibertyToolWindow(RemoteRobot remoteRobot, String treeItem) {
// Try multiple times in case the O/S is displaying a modal dialog that blocks the button.
for (int i = 1; i <=3; i++) {
try {
UIBotTestUtils.openLibertyToolWindow(remoteRobot);
if (UIBotTestUtils.validateImportedProjectShowsInLTW(remoteRobot, treeItem)) {
break;
}
} catch (Exception e) {
// Any of the operations above could end up in an exception if the element is
// not found etc. Wait and retry.
}
TestUtils.sleepAndIgnoreException(3);
}
}

/**
* Opens the Liberty tool window if it is not already open.
*
Expand Down Expand Up @@ -450,6 +471,7 @@ public static void closeLibertyToolWindow(RemoteRobot remoteRobot) {
* @param remoteRobot The RemoteRobot instance.
*/
public static void openProjectView(RemoteRobot remoteRobot) {
TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, "UIBotTestUtils.openProjectView Entry");
int maxRetries = 6;
Exception error = null;
for (int i = 0; i < maxRetries; i++) {
Expand All @@ -475,6 +497,7 @@ public static void openProjectView(RemoteRobot remoteRobot) {
if (error != null) {
throw new RuntimeException("Unable to open the project tool window.", error);
}
TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, "UIBotTestUtils.openProjectView Exit");
}

/**
Expand Down Expand Up @@ -1771,11 +1794,13 @@ public static void waitForLTWTextAreaMessage(RemoteRobot remoteRobot, String mes
* Look for the indexing message and if it is found wait up to 10 minutes for it to stop.
*/
public static void waitForIndexing(RemoteRobot remoteRobot) {
TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, "UIBotTestUtils.waitForIndexing Entry");
String xPath = "//div[@class='InlineProgressPanel']";
boolean needToWait = waitForIndexingToStart(remoteRobot, xPath, 5);
boolean needToWait = waitForIndexingToStart(remoteRobot, xPath, 60);
if (needToWait) {
waitForIndexingToStop(remoteRobot, xPath, 600);
}
TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, "UIBotTestUtils.waitForIndexing Exit");
}

/**
Expand Down Expand Up @@ -2269,7 +2294,7 @@ public static void stopDebugger(RemoteRobot remoteRobot) {
}

Locator locator = byXpath("//div[contains(@myvisibleactions, 'Get')]//div[contains(@myaction.key, 'action.Stop.text')]");
ActionButtonFixture stopButton = projectFrame.actionButton(locator, Duration.ofSeconds(5));
ActionButtonFixture stopButton = projectFrame.actionButton(locator, Duration.ofSeconds(60));
stopButton.click();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ComponentFixture getActionMenu(String... xpathVars) {
*/
public ComponentFixture getActionMenuItem(String... xpathVars) {
String text = xpathVars[0];
RepeatUtilsKt.waitFor(Duration.ofSeconds(10),
RepeatUtilsKt.waitFor(Duration.ofSeconds(16),
Duration.ofSeconds(1),
"Waiting for menu items containing the " + text + " text",
"Menu items containing the " + text + " text were not found",
Expand Down

0 comments on commit 01b4c36

Please sign in to comment.