diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/project/pages/NewProjectFirstPage.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/project/pages/NewProjectFirstPage.java index 882f68d6..8d91bd3e 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/project/pages/NewProjectFirstPage.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/project/pages/NewProjectFirstPage.java @@ -121,12 +121,21 @@ public ComboBoxFixture getProjectJdkComboBox() { * @param targetSdkName name of the SDK to which will be changed the current settings */ public void setProjectSdkIfAvailable(String targetSdkName) { - step("Select the '" + targetSdkName + "' as new project SDK", () -> { - ComboBoxFixture projectJdkComboBox = getProjectJdkComboBox(); - String currentlySelectedProjectSdk = TextUtils.listOfRemoteTextToString(projectJdkComboBox.findAllText()); - if (currentlySelectedProjectSdk.contains(targetSdkName)) { - return; - } + step("Select the '" + targetSdkName + "' as new project SDK", () -> { + + waitFor( + Duration.ofSeconds(20), + Duration.ofSeconds(5), + "Waiting for exactly one dialog to be visible.", + () -> "Expected exactly one dialog but found " + remoteRobot.findAll(CommonContainerFixture.class, byXpath(XPathDefinitions.MY_DIALOG)).size(), + () -> remoteRobot.findAll(CommonContainerFixture.class, byXpath(XPathDefinitions.MY_DIALOG)).size() == 1 + ); + + ComboBoxFixture projectJdkComboBox = getProjectJdkComboBox(); + String currentlySelectedProjectSdk = TextUtils.listOfRemoteTextToString(projectJdkComboBox.findAllText()); + if (currentlySelectedProjectSdk.contains(targetSdkName)) { + return; + } if (UITestRunner.getIdeaVersionInt() >= 20221) { projectJdkComboBox.click(); diff --git a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/project_manipulation/NewProjectDialogTest.java b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/project_manipulation/NewProjectDialogTest.java index eb1a911b..01db2047 100644 --- a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/project_manipulation/NewProjectDialogTest.java +++ b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/project_manipulation/NewProjectDialogTest.java @@ -10,11 +10,7 @@ ******************************************************************************/ package com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.project_manipulation; -import com.intellij.remoterobot.fixtures.ComboBoxFixture; -import com.intellij.remoterobot.fixtures.ComponentFixture; -import com.intellij.remoterobot.fixtures.ContainerFixture; -import com.intellij.remoterobot.fixtures.JLabelFixture; -import com.intellij.remoterobot.fixtures.JListFixture; +import com.intellij.remoterobot.fixtures.*; import com.intellij.remoterobot.utils.WaitForConditionTimeoutException; import com.redhat.devtools.intellij.commonuitest.LibraryTestBase; import com.redhat.devtools.intellij.commonuitest.UITestRunner; @@ -30,6 +26,7 @@ import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.idestatusbar.IdeStatusBar; import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions; import com.redhat.devtools.intellij.commonuitest.utils.project.CreateCloseUtils; +import com.redhat.devtools.intellij.commonuitest.utils.screenshot.ScreenshotUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -311,7 +308,7 @@ public void nextButtonTest() { public void finishButtonTest() { if (UITestRunner.getIdeaVersionInt() < 20221) { newProjectFirstPage.selectNewProjectType(CreateCloseUtils.NewProjectType.PLAIN_JAVA.toString()); - newProjectFirstPage.setProjectSdkIfAvailable("11"); + newProjectFirstPage.setProjectSdkIfAvailable("17"); assertThrows(UITestException.class, () -> newProjectDialogWizard.finish(), "The 'UITestException' should be thrown because the 'Finish' button is not available on the first page of the 'New Project' wizard for java project."); newProjectDialogWizard.next(); @@ -333,13 +330,24 @@ public void cancelButtonTest() { @Test public void setProjectSdkIfAvailableTest() { - newProjectFirstPage.setProjectSdkIfAvailable("11"); - ComboBoxFixture projectJdkComboBox = newProjectFirstPage.getProjectJdkComboBox(); - String currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText()); - assertTrue(currentlySelectedProjectSdk.contains("11"), "Selected project SDK should be Java 11 but is '" + currentlySelectedProjectSdk + "'"); - newProjectFirstPage.setProjectSdkIfAvailable("17"); - currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText()); - assertTrue(currentlySelectedProjectSdk.contains("17"), "Selected project SDK should be Java 17 but is '" + currentlySelectedProjectSdk + "'"); + if (ideaVersionInt >= 20242 && remoteRobot.isWin()) { + newProjectFirstPage.setProjectSdkIfAvailable("Download JDK"); + try { + ContainerFixture downloadJdkDialog = remoteRobot.find(ContainerFixture.class, byXpath("//div[@title='Download JDK']"), Duration.ofSeconds(10)); + downloadJdkDialog.find(ActionButtonFixture.class, byXpath("//div[@text='Cancel']"), Duration.ofSeconds(5)).click(); + } catch (WaitForConditionTimeoutException e) { + ScreenshotUtils.takeScreenshot(remoteRobot, "sdktestfailed"); + fail("Download JDK button was not pressed and Download JDK dialog was not found"); + } + } else { + newProjectFirstPage.setProjectSdkIfAvailable("11"); + ComboBoxFixture projectJdkComboBox = newProjectFirstPage.getProjectJdkComboBox(); + String currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText()); + assertTrue(currentlySelectedProjectSdk.contains("11"), "Selected project SDK should be Java 11 but is '" + currentlySelectedProjectSdk + "'"); + newProjectFirstPage.setProjectSdkIfAvailable("17"); + currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText()); + assertTrue(currentlySelectedProjectSdk.contains("17"), "Selected project SDK should be Java 17 but is '" + currentlySelectedProjectSdk + "'"); + } } @Test