Skip to content

Commit 3e037c9

Browse files
committed
fix: Fixed createNewProject method for 2024.1
rh-pre-commit.version: 2.2.0 rh-pre-commit.check-secrets: ENABLED
1 parent cb40785 commit 3e037c9

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545
public class NewProjectFirstPage extends AbstractNewProjectFinalPage {
4646
private final RemoteRobot remoteRobot;
4747
private int projectSdkItemsCount = -1;
48+
private final int ideaVersion;
4849

4950
public NewProjectFirstPage(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
5051
super(remoteRobot, remoteComponent);
5152
this.remoteRobot = remoteRobot;
53+
this.ideaVersion = UITestRunner.getIdeaVersion().toInt();
5254
}
5355

5456
/**
@@ -76,7 +78,12 @@ public void setProjectName(String projectName) {
7678
* @param language project language
7779
*/
7880
public void setLanguage(String language) {
79-
findAll(JLabelFixture.class, byXpath(XPathDefinitions.SET_LANGUAGE)).get(0).findText(language).click();
81+
if (ideaVersion >= 20241) {
82+
JListFixture jListFixture = remoteRobot.find(JListFixture.class, byXpath(XPathDefinitions.JBLIST));
83+
jListFixture.clickItem(language, false);
84+
} else {
85+
findAll(JLabelFixture.class, byXpath(XPathDefinitions.SET_LANGUAGE)).get(0).findText(language).click();
86+
}
8087
}
8188

8289
/**
@@ -85,7 +92,23 @@ public void setLanguage(String language) {
8592
* @param buildSystem build system type
8693
*/
8794
public void setBuildSystem(String buildSystem) {
88-
find(JLabelFixture.class, byXpath(XPathDefinitions.SET_BUILD_SYSTEM)).findText(buildSystem).click();
95+
if (ideaVersion >= 20241) {
96+
find(JLabelFixture.class, byXpath(XPathDefinitions.SET_BUILD_SYSTEM_2024_1_AND_NEWER)).findText(buildSystem).click();
97+
} else {
98+
find(JLabelFixture.class, byXpath(XPathDefinitions.SET_BUILD_SYSTEM)).findText(buildSystem).click();
99+
}
100+
}
101+
102+
/**
103+
* Get the project SDK JdkComboBox
104+
*
105+
* @return JdkComboBox fixture
106+
*/
107+
public ComboBoxFixture getProjectJdkComboBox() {
108+
if (ideaVersion >= 20241) {
109+
return comboBox(byXpath(XPathDefinitions.JDK_COMBOBOX_PROJECT_WIZARD), Duration.ofSeconds(10));
110+
}
111+
return comboBox(byXpath(XPathDefinitions.JDK_COMBOBOX), Duration.ofSeconds(10));
89112
}
90113

91114
/**
@@ -95,7 +118,7 @@ public void setBuildSystem(String buildSystem) {
95118
*/
96119
public void setProjectSdkIfAvailable(String targetSdkName) {
97120
step("Select the '" + targetSdkName + "' as new project SDK", () -> {
98-
ComboBoxFixture projectJdkComboBox = comboBox(byXpath(XPathDefinitions.JDK_COMBOBOX), Duration.ofSeconds(10));
121+
ComboBoxFixture projectJdkComboBox = getProjectJdkComboBox();
99122
String currentlySelectedProjectSdk = TextUtils.listOfRemoteTextToString(projectJdkComboBox.findAllText());
100123
if (currentlySelectedProjectSdk.contains(targetSdkName)) {
101124
return;

src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/XPathDefinitions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class XPathDefinitions {
4949
public static final String ARTIFACTS_COORDINATES_DIALOG_PANEL = "//div[@class='DialogPanel']/*";
5050
public static final String HEAVY_WEIGHT_WINDOW = "//div[@class='HeavyWeightWindow']";
5151
public static final String JDK_COMBOBOX = "//div[@class='JdkComboBox']";
52+
public static final String JDK_COMBOBOX_PROJECT_WIZARD = "//div[@class='ProjectWizardJdkComboBox']"; // works for IntelliJ Idea 2024.1 and higher
5253
public static final String MY_DIALOG = "//div[@class='MyDialog']";
5354
public static final String TREE = "//div[@class='Tree']";
5455
public static final String TOOLTIP_TEXT_PROJECT = "//div[@tooltiptext='Project']";
@@ -78,10 +79,11 @@ public class XPathDefinitions {
7879
public static final String REMOVE_PROJECT_BUTTON = "//div[contains(@text.key, 'button.remove')]";
7980
public static final String SET_LANGUAGE = "//div[@class='SegmentedButtonComponent'][.//div[contains(@action.key, 'language.groovy')]]";
8081
public static final String SET_BUILD_SYSTEM = "//div[@class='SegmentedButtonComponent'][.//div[@action.key='buildsystem.type.intellij']]";
82+
public static final String SET_BUILD_SYSTEM_2024_1_AND_NEWER = "//div[@accessiblename='Build system:' and @class='SegmentedButtonComponent']"; // works for IntelliJ Idea 2024.1 and higher
8183
public static final String GET_SET_MODULE_NAME = "//div[@accessiblename='Module name:' and @accessiblename.key='label.project.wizard.new.project.module.name' and @class='JBTextField']";
8284
public static final String GET_SET_CONTENT_ROOT = "//div[@accessiblename='Content root:' and @accessiblename.key='label.project.wizard.new.project.content.root' and @class='ExtendableTextField']";
8385
public static final String GET_SET_MODULE_FILE_LOCATION = "//div[@accessiblename='Module file location:' and @accessiblename.key='label.project.wizard.new.project.module.file.location' and @class='ExtendableTextField']";
84-
public static final String CREATE_NEW_PROJECT = "//div[@defaulticon='createNewProjectTab.svg']"; // works for 2024.1 and higher
86+
public static final String CREATE_NEW_PROJECT = "//div[@defaulticon='createNewProjectTab.svg']"; // works for IntelliJ Idea 2024.1 and higher
8587

8688
private XPathDefinitions() {
8789
throw new UITestException("Utility class with static methods.");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public void cancelButtonTest() {
334334
@Test
335335
public void setProjectSdkIfAvailableTest() {
336336
newProjectFirstPage.setProjectSdkIfAvailable("11");
337-
ComboBoxFixture projectJdkComboBox = newProjectFirstPage.find(ComboBoxFixture.class, byXpath(XPathDefinitions.JDK_COMBOBOX), Duration.ofSeconds(10));
337+
ComboBoxFixture projectJdkComboBox = newProjectFirstPage.getProjectJdkComboBox();
338338
String currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText());
339339
assertTrue(currentlySelectedProjectSdk.contains("11"), "Selected project SDK should be Java 11 but is '" + currentlySelectedProjectSdk + "'");
340340
newProjectFirstPage.setProjectSdkIfAvailable("17");

0 commit comments

Comments
 (0)