Skip to content

Commit

Permalink
fix(test): setprojectsdk test for windows
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Szuc <[email protected]>
  • Loading branch information
martinszuc committed Sep 30, 2024
1 parent a667bc2 commit d11dfeb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d11dfeb

Please sign in to comment.