Skip to content

Commit 43541c2

Browse files
committed
fix(test): setprojectsdk test for windows
Signed-off-by: Martin Szuc <[email protected]>
1 parent 5f05d61 commit 43541c2

File tree

2 files changed

+34
-19
lines changed
  • src

2 files changed

+34
-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: 19 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;
@@ -311,7 +307,7 @@ public void nextButtonTest() {
311307
public void finishButtonTest() {
312308
if (UITestRunner.getIdeaVersionInt() < 20221) {
313309
newProjectFirstPage.selectNewProjectType(CreateCloseUtils.NewProjectType.PLAIN_JAVA.toString());
314-
newProjectFirstPage.setProjectSdkIfAvailable("11");
310+
newProjectFirstPage.setProjectSdkIfAvailable("17");
315311
assertThrows(UITestException.class, () ->
316312
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.");
317313
newProjectDialogWizard.next();
@@ -333,13 +329,23 @@ public void cancelButtonTest() {
333329

334330
@Test
335331
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 + "'");
332+
if (remoteRobot.isWin()) {
333+
newProjectFirstPage.setProjectSdkIfAvailable("Download JDK");
334+
try {
335+
ContainerFixture downloadJdkDialog = remoteRobot.find(ContainerFixture.class, byXpath("//div[@title='Download JDK']"), Duration.ofSeconds(10));
336+
downloadJdkDialog.find(ActionButtonFixture.class, byXpath("//div[@text='Cancel']"), Duration.ofSeconds(5)).click();
337+
} catch (WaitForConditionTimeoutException e) {
338+
fail("Download JDK button was not pressed and Download JDK dialog was not found");
339+
}
340+
} else {
341+
newProjectFirstPage.setProjectSdkIfAvailable("11");
342+
ComboBoxFixture projectJdkComboBox = newProjectFirstPage.getProjectJdkComboBox();
343+
String currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText());
344+
assertTrue(currentlySelectedProjectSdk.contains("11"), "Selected project SDK should be Java 11 but is '" + currentlySelectedProjectSdk + "'");
345+
newProjectFirstPage.setProjectSdkIfAvailable("17");
346+
currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText());
347+
assertTrue(currentlySelectedProjectSdk.contains("17"), "Selected project SDK should be Java 17 but is '" + currentlySelectedProjectSdk + "'");
348+
}
343349
}
344350

345351
@Test

0 commit comments

Comments
 (0)