Skip to content

Commit

Permalink
fix: Fixed createNewProject method for 2024.1
Browse files Browse the repository at this point in the history
rh-pre-commit.version: 2.2.0
rh-pre-commit.check-secrets: ENABLED
  • Loading branch information
richardkocian committed May 6, 2024
1 parent cb40785 commit 3e037c9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
public class NewProjectFirstPage extends AbstractNewProjectFinalPage {
private final RemoteRobot remoteRobot;
private int projectSdkItemsCount = -1;
private final int ideaVersion;

public NewProjectFirstPage(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
super(remoteRobot, remoteComponent);
this.remoteRobot = remoteRobot;
this.ideaVersion = UITestRunner.getIdeaVersion().toInt();
}

/**
Expand Down Expand Up @@ -76,7 +78,12 @@ public void setProjectName(String projectName) {
* @param language project language
*/
public void setLanguage(String language) {
findAll(JLabelFixture.class, byXpath(XPathDefinitions.SET_LANGUAGE)).get(0).findText(language).click();
if (ideaVersion >= 20241) {
JListFixture jListFixture = remoteRobot.find(JListFixture.class, byXpath(XPathDefinitions.JBLIST));
jListFixture.clickItem(language, false);
} else {
findAll(JLabelFixture.class, byXpath(XPathDefinitions.SET_LANGUAGE)).get(0).findText(language).click();
}
}

/**
Expand All @@ -85,7 +92,23 @@ public void setLanguage(String language) {
* @param buildSystem build system type
*/
public void setBuildSystem(String buildSystem) {
find(JLabelFixture.class, byXpath(XPathDefinitions.SET_BUILD_SYSTEM)).findText(buildSystem).click();
if (ideaVersion >= 20241) {
find(JLabelFixture.class, byXpath(XPathDefinitions.SET_BUILD_SYSTEM_2024_1_AND_NEWER)).findText(buildSystem).click();
} else {
find(JLabelFixture.class, byXpath(XPathDefinitions.SET_BUILD_SYSTEM)).findText(buildSystem).click();
}
}

/**
* Get the project SDK JdkComboBox
*
* @return JdkComboBox fixture
*/
public ComboBoxFixture getProjectJdkComboBox() {
if (ideaVersion >= 20241) {
return comboBox(byXpath(XPathDefinitions.JDK_COMBOBOX_PROJECT_WIZARD), Duration.ofSeconds(10));
}
return comboBox(byXpath(XPathDefinitions.JDK_COMBOBOX), Duration.ofSeconds(10));
}

/**
Expand All @@ -95,7 +118,7 @@ public void setBuildSystem(String buildSystem) {
*/
public void setProjectSdkIfAvailable(String targetSdkName) {
step("Select the '" + targetSdkName + "' as new project SDK", () -> {
ComboBoxFixture projectJdkComboBox = comboBox(byXpath(XPathDefinitions.JDK_COMBOBOX), Duration.ofSeconds(10));
ComboBoxFixture projectJdkComboBox = getProjectJdkComboBox();
String currentlySelectedProjectSdk = TextUtils.listOfRemoteTextToString(projectJdkComboBox.findAllText());
if (currentlySelectedProjectSdk.contains(targetSdkName)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class XPathDefinitions {
public static final String ARTIFACTS_COORDINATES_DIALOG_PANEL = "//div[@class='DialogPanel']/*";
public static final String HEAVY_WEIGHT_WINDOW = "//div[@class='HeavyWeightWindow']";
public static final String JDK_COMBOBOX = "//div[@class='JdkComboBox']";
public static final String JDK_COMBOBOX_PROJECT_WIZARD = "//div[@class='ProjectWizardJdkComboBox']"; // works for IntelliJ Idea 2024.1 and higher
public static final String MY_DIALOG = "//div[@class='MyDialog']";
public static final String TREE = "//div[@class='Tree']";
public static final String TOOLTIP_TEXT_PROJECT = "//div[@tooltiptext='Project']";
Expand Down Expand Up @@ -78,10 +79,11 @@ public class XPathDefinitions {
public static final String REMOVE_PROJECT_BUTTON = "//div[contains(@text.key, 'button.remove')]";
public static final String SET_LANGUAGE = "//div[@class='SegmentedButtonComponent'][.//div[contains(@action.key, 'language.groovy')]]";
public static final String SET_BUILD_SYSTEM = "//div[@class='SegmentedButtonComponent'][.//div[@action.key='buildsystem.type.intellij']]";
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
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']";
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']";
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']";
public static final String CREATE_NEW_PROJECT = "//div[@defaulticon='createNewProjectTab.svg']"; // works for 2024.1 and higher
public static final String CREATE_NEW_PROJECT = "//div[@defaulticon='createNewProjectTab.svg']"; // works for IntelliJ Idea 2024.1 and higher

private XPathDefinitions() {
throw new UITestException("Utility class with static methods.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public void cancelButtonTest() {
@Test
public void setProjectSdkIfAvailableTest() {
newProjectFirstPage.setProjectSdkIfAvailable("11");
ComboBoxFixture projectJdkComboBox = newProjectFirstPage.find(ComboBoxFixture.class, byXpath(XPathDefinitions.JDK_COMBOBOX), Duration.ofSeconds(10));
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");
Expand Down

0 comments on commit 3e037c9

Please sign in to comment.