|
27 | 27 |
|
28 | 28 | import java.io.File; |
29 | 29 | import java.time.Duration; |
| 30 | +import java.util.List; |
30 | 31 | import java.util.Optional; |
31 | 32 |
|
32 | 33 | import static com.intellij.remoterobot.search.locators.Locators.byXpath; |
| 34 | +import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitFor; |
33 | 35 |
|
34 | 36 | /** |
35 | 37 | * Project creation utilities |
@@ -101,6 +103,7 @@ public static void createEmptyProject(RemoteRobot remoteRobot, String projectNam |
101 | 103 | NewProjectFirstPage newProjectFirstPage = newProjectDialogWizard.find(NewProjectFirstPage.class, Duration.ofSeconds(10)); |
102 | 104 |
|
103 | 105 | newProjectFirstPage.selectNewProjectType(NewProjectType.EMPTY_PROJECT.toString()); |
| 106 | + ensureEmptyProjectPageIsOpened(newProjectFirstPage, remoteRobot); |
104 | 107 |
|
105 | 108 | newProjectFirstPage.setProjectName(projectName); |
106 | 109 | newProjectFirstPage.setProjectLocation(PROJECT_LOCATION); |
@@ -179,6 +182,51 @@ public static AbstractNewProjectFinalPage getFinalPage(NewProjectDialogWizard ne |
179 | 182 | } |
180 | 183 | } |
181 | 184 |
|
| 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 | + |
182 | 230 | /** |
183 | 231 | * Enumeration for new project type |
184 | 232 | */ |
|
0 commit comments