Skip to content

Commit a8b70ff

Browse files
authored
fix: waitForDialogsToDisappear method for project creation process
fix: waitForDialogsToDisappear method for project creation process
2 parents 054c657 + 626ef59 commit a8b70ff

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/main/java/com/redhat/devtools/intellij/commonuitest/utils/project/CreateCloseUtils.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727

2828
import java.io.File;
2929
import java.time.Duration;
30+
import java.util.List;
3031
import java.util.Optional;
3132

3233
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
34+
import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitFor;
3335

3436
/**
3537
* Project creation utilities
@@ -101,6 +103,7 @@ public static void createEmptyProject(RemoteRobot remoteRobot, String projectNam
101103
NewProjectFirstPage newProjectFirstPage = newProjectDialogWizard.find(NewProjectFirstPage.class, Duration.ofSeconds(10));
102104

103105
newProjectFirstPage.selectNewProjectType(NewProjectType.EMPTY_PROJECT.toString());
106+
ensureEmptyProjectPageIsOpened(newProjectFirstPage, remoteRobot);
104107

105108
newProjectFirstPage.setProjectName(projectName);
106109
newProjectFirstPage.setProjectLocation(PROJECT_LOCATION);
@@ -179,6 +182,51 @@ public static AbstractNewProjectFinalPage getFinalPage(NewProjectDialogWizard ne
179182
}
180183
}
181184

185+
/**
186+
* Ensures that the Empty Project page is opened by checking for specific text on the page.
187+
* If verification fails, it waits for dialogs to disappear and reselects the Empty Project type.
188+
*
189+
* @param newProjectFirstPage the first page of the new project dialog
190+
* @param remoteRobot reference to the RemoteRobot instance
191+
*/
192+
private static void ensureEmptyProjectPageIsOpened(NewProjectFirstPage newProjectFirstPage, RemoteRobot remoteRobot) {
193+
int ideaVersionInt = UITestRunner.getIdeaVersionInt();
194+
boolean isEmptyProjectPageDisplayed;
195+
196+
if (ideaVersionInt >= 20231) { // For IntelliJ IDEA version 2023.1 and newer
197+
isEmptyProjectPageDisplayed = newProjectFirstPage.hasText("A basic project with free structure.");
198+
} else { // For IntelliJ IDEA version 2022.1 and newer
199+
isEmptyProjectPageDisplayed = newProjectFirstPage.hasText("A basic project that allows working with separate files and compiling Java and Kotlin classes.");
200+
}
201+
202+
if (!isEmptyProjectPageDisplayed) {
203+
// If the expected text is not found, wait for dialogs to disappear and reselect the Empty Project type
204+
waitForDialogsToDisappear(remoteRobot, Duration.ofSeconds(20));
205+
newProjectFirstPage.selectNewProjectType(NewProjectType.EMPTY_PROJECT.toString());
206+
}
207+
}
208+
209+
/**
210+
* Waits until only the "New Project" dialog is open.
211+
* If any other dialogs are open, it waits for them to disappear.
212+
*
213+
* @param remoteRobot the RemoteRobot instance
214+
* @param timeout the maximum duration to wait for the other dialogs to disappear
215+
*/
216+
private static void waitForDialogsToDisappear(RemoteRobot remoteRobot, Duration timeout) {
217+
waitFor(
218+
timeout,
219+
Duration.ofSeconds(2),
220+
"Waiting for only the New Project dialog to remain open",
221+
() -> "Extra dialogs did not disappear within the timeout",
222+
() -> {
223+
List<ComponentFixture> allDialogs = remoteRobot.findAll(ComponentFixture.class, byXpath(XPathDefinitions.MY_DIALOG));
224+
// Proceed if only one dialog is open, assumed to be the New Project dialog
225+
return allDialogs.size() == 1;
226+
}
227+
);
228+
}
229+
182230
/**
183231
* Enumeration for new project type
184232
*/

0 commit comments

Comments
 (0)