Skip to content

Commit 985881e

Browse files
committed
fix(test): setprojectsdk test for windows
Signed-off-by: Martin Szuc <[email protected]>
1 parent 1d2096c commit 985881e

File tree

2 files changed

+36
-19
lines changed
  • src

2 files changed

+36
-19
lines changed

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/project/pages/NewProjectFirstPage.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,21 @@ public ComboBoxFixture getProjectJdkComboBox() {
121121
* @param targetSdkName name of the SDK to which will be changed the current settings
122122
*/
123123
public void setProjectSdkIfAvailable(String targetSdkName) {
124-
step("Select the '" + targetSdkName + "' as new project SDK", () -> {
125-
ComboBoxFixture projectJdkComboBox = getProjectJdkComboBox();
126-
String currentlySelectedProjectSdk = TextUtils.listOfRemoteTextToString(projectJdkComboBox.findAllText());
127-
if (currentlySelectedProjectSdk.contains(targetSdkName)) {
128-
return;
129-
}
124+
step("Select the '" + targetSdkName + "' as new project SDK", () -> {
125+
126+
waitFor(
127+
Duration.ofSeconds(20),
128+
Duration.ofSeconds(5),
129+
"Waiting for exactly one dialog to be visible.",
130+
() -> "Expected exactly one dialog but found " + remoteRobot.findAll(CommonContainerFixture.class, byXpath(XPathDefinitions.MY_DIALOG)).size(),
131+
() -> remoteRobot.findAll(CommonContainerFixture.class, byXpath(XPathDefinitions.MY_DIALOG)).size() == 1
132+
);
133+
134+
ComboBoxFixture projectJdkComboBox = getProjectJdkComboBox();
135+
String currentlySelectedProjectSdk = TextUtils.listOfRemoteTextToString(projectJdkComboBox.findAllText());
136+
if (currentlySelectedProjectSdk.contains(targetSdkName)) {
137+
return;
138+
}
130139

131140
if (UITestRunner.getIdeaVersionInt() >= 20221) {
132141
projectJdkComboBox.click();

src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/project_manipulation/NewProjectDialogTest.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
******************************************************************************/
1111
package com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.project_manipulation;
1212

13-
import com.intellij.remoterobot.fixtures.ComboBoxFixture;
14-
import com.intellij.remoterobot.fixtures.ComponentFixture;
15-
import com.intellij.remoterobot.fixtures.ContainerFixture;
16-
import com.intellij.remoterobot.fixtures.JLabelFixture;
17-
import com.intellij.remoterobot.fixtures.JListFixture;
13+
import com.intellij.remoterobot.fixtures.*;
1814
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
1915
import com.redhat.devtools.intellij.commonuitest.LibraryTestBase;
2016
import com.redhat.devtools.intellij.commonuitest.UITestRunner;
@@ -30,6 +26,7 @@
3026
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.idestatusbar.IdeStatusBar;
3127
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
3228
import com.redhat.devtools.intellij.commonuitest.utils.project.CreateCloseUtils;
29+
import com.redhat.devtools.intellij.commonuitest.utils.screenshot.ScreenshotUtils;
3330
import org.junit.jupiter.api.AfterEach;
3431
import org.junit.jupiter.api.BeforeEach;
3532
import org.junit.jupiter.api.Test;
@@ -311,7 +308,7 @@ public void nextButtonTest() {
311308
public void finishButtonTest() {
312309
if (UITestRunner.getIdeaVersionInt() < 20221) {
313310
newProjectFirstPage.selectNewProjectType(CreateCloseUtils.NewProjectType.PLAIN_JAVA.toString());
314-
newProjectFirstPage.setProjectSdkIfAvailable("11");
311+
newProjectFirstPage.setProjectSdkIfAvailable("17");
315312
assertThrows(UITestException.class, () ->
316313
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.");
317314
newProjectDialogWizard.next();
@@ -333,13 +330,24 @@ public void cancelButtonTest() {
333330

334331
@Test
335332
public void setProjectSdkIfAvailableTest() {
336-
newProjectFirstPage.setProjectSdkIfAvailable("11");
337-
ComboBoxFixture projectJdkComboBox = newProjectFirstPage.getProjectJdkComboBox();
338-
String currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText());
339-
assertTrue(currentlySelectedProjectSdk.contains("11"), "Selected project SDK should be Java 11 but is '" + currentlySelectedProjectSdk + "'");
340-
newProjectFirstPage.setProjectSdkIfAvailable("17");
341-
currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText());
342-
assertTrue(currentlySelectedProjectSdk.contains("17"), "Selected project SDK should be Java 17 but is '" + currentlySelectedProjectSdk + "'");
333+
if (ideaVersionInt >= 20242 && remoteRobot.isWin()) {
334+
newProjectFirstPage.setProjectSdkIfAvailable("Download JDK");
335+
try {
336+
ContainerFixture downloadJdkDialog = remoteRobot.find(ContainerFixture.class, byXpath("//div[@title='Download JDK']"), Duration.ofSeconds(10));
337+
downloadJdkDialog.find(ActionButtonFixture.class, byXpath("//div[@text='Cancel']"), Duration.ofSeconds(5)).click();
338+
} catch (WaitForConditionTimeoutException e) {
339+
ScreenshotUtils.takeScreenshot(remoteRobot, "sdktestfailed");
340+
fail("Download JDK button was not pressed and Download JDK dialog was not found");
341+
}
342+
} else {
343+
newProjectFirstPage.setProjectSdkIfAvailable("11");
344+
ComboBoxFixture projectJdkComboBox = newProjectFirstPage.getProjectJdkComboBox();
345+
String currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText());
346+
assertTrue(currentlySelectedProjectSdk.contains("11"), "Selected project SDK should be Java 11 but is '" + currentlySelectedProjectSdk + "'");
347+
newProjectFirstPage.setProjectSdkIfAvailable("17");
348+
currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText());
349+
assertTrue(currentlySelectedProjectSdk.contains("17"), "Selected project SDK should be Java 17 but is '" + currentlySelectedProjectSdk + "'");
350+
}
343351
}
344352

345353
@Test

0 commit comments

Comments
 (0)