Skip to content

Commit 1984371

Browse files
authored
Add support for IntelliJ CE 2022.2 (#141)
Fixes #140 Signed-off-by: Zbynek Cervinka <zcervink@redhat.com>
1 parent f00e91f commit 1984371

File tree

11 files changed

+120
-54
lines changed

11 files changed

+120
-54
lines changed

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/FlatWelcomeFrame.java

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,8 @@ public void clickOnLink(String label) {
9696
* Clear the workspace by deleting the content of the IdeaProjects folder and clearing all the projects' links in the 'Welcome to IntelliJ IDEA' dialog
9797
*/
9898
public void clearWorkspace() {
99-
List<JListFixture> jListFixtures = jLists(byXpath(XPathDefinitions.RECENT_PROJECTS));
10099
for (int i = 0; i < projectsCount(); i++) {
101-
JListFixture recentProjectsList = jListFixtures.get(0);
102-
recentProjectsList.runJs("const horizontal_offset = component.getWidth()-22;\n" +
103-
"robot.click(component, new Point(horizontal_offset, 22), MouseButton.LEFT_BUTTON, 1);");
104-
// Code for IntelliJ Idea 2020.3 or newer
105-
if (ideaVersion >= 20203) {
106-
List<JPopupMenuFixture> jPopupMenuFixtures = jPopupMenus(JPopupMenuFixture.Companion.byType());
107-
if (!jPopupMenuFixtures.isEmpty()) {
108-
JPopupMenuFixture contextMenu = jPopupMenuFixtures.get(0);
109-
contextMenu.select("Remove from Recent Projects");
110-
}
111-
}
100+
removeTopProjectFromRecentProjects();
112101
}
113102

114103
try {
@@ -227,18 +216,27 @@ public void switchToProjectsPage() {
227216
}
228217

229218
private int projectsCount() {
230-
try {
231-
ContainerFixture projectWrapper = find(ContainerFixture.class, byXpath(XPathDefinitions.NEW_RECENT_PROJECT_PANEL));
232-
JListFixture projectList = projectWrapper.find(JListFixture.class, byXpath(XPathDefinitions.MY_LIST));
233-
return projectList.collectItems().size();
234-
} catch (WaitForConditionTimeoutException e) {
235-
return 0;
219+
if (ideaVersion >= 20222) {
220+
try {
221+
JTreeFixture projects = remoteRobot.findAll(JTreeFixture.class, byXpath(XPathDefinitions.RECENT_PROJECT_PANEL_NEW_2)).get(0);
222+
return projects.findAllText().size() / 2;
223+
} catch (IndexOutOfBoundsException e) {
224+
return 0;
225+
}
226+
} else {
227+
try {
228+
ContainerFixture projectWrapper = find(ContainerFixture.class, byXpath(XPathDefinitions.RECENT_PROJECT_PANEL_NEW));
229+
JListFixture projectList = projectWrapper.find(JListFixture.class, byXpath(XPathDefinitions.MY_LIST));
230+
return projectList.collectItems().size();
231+
} catch (WaitForConditionTimeoutException e) {
232+
return 0;
233+
}
236234
}
237235
}
238236

239237
// Works for IntelliJ Idea 2020.3+
240238
private JButtonFixture welcomeFrameLink(String label) {
241-
if (UtilsKt.hasAnyComponent(this, byXpath(XPathDefinitions.NEW_RECENT_PROJECT_PANEL))) {
239+
if (UtilsKt.hasAnyComponent(this, byXpath(XPathDefinitions.RECENT_PROJECT_PANEL_NEW))) {
242240
return button(byXpath(XPathDefinitions.jBOptionButton(label)), Duration.ofSeconds(2));
243241
}
244242
return button(byXpath(XPathDefinitions.nonOpaquePanel(label)), Duration.ofSeconds(2));
@@ -247,4 +245,30 @@ private JButtonFixture welcomeFrameLink(String label) {
247245
private ComponentFixture ideErrorsIcon() {
248246
return find(ComponentFixture.class, byXpath(XPathDefinitions.IDE_ERROR_ICON), Duration.ofSeconds(10));
249247
}
248+
249+
private void removeTopProjectFromRecentProjects() {
250+
ComponentFixture recentProjects;
251+
if (ideaVersion >= 20222) {
252+
recentProjects = remoteRobot.findAll(JTreeFixture.class, byXpath(XPathDefinitions.RECENT_PROJECT_PANEL_NEW_2)).get(0);
253+
} else {
254+
recentProjects = jLists(byXpath(XPathDefinitions.RECENT_PROJECTS)).get(0);
255+
}
256+
257+
recentProjects.runJs("const horizontal_offset = component.getWidth()-22;\n" +
258+
"robot.click(component, new Point(horizontal_offset, 22), MouseButton.LEFT_BUTTON, 1);");
259+
260+
// Code for IntelliJ Idea 2020.3 or newer
261+
if (ideaVersion >= 20203) {
262+
List<JPopupMenuFixture> jPopupMenuFixtures = jPopupMenus(JPopupMenuFixture.Companion.byType());
263+
if (!jPopupMenuFixtures.isEmpty()) {
264+
JPopupMenuFixture contextMenu = jPopupMenuFixtures.get(0);
265+
if (ideaVersion >= 20222) {
266+
contextMenu.select("Remove from Recent Projects" + '\u2026');
267+
button(byXpath(XPathDefinitions.REMOVE_PROJECT_BUTTON)).click();
268+
} else {
269+
contextMenu.select("Remove from Recent Projects");
270+
}
271+
}
272+
}
273+
}
250274
}

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected AbstractNewProjectFinalPage(@NotNull RemoteRobot remoteRobot, @NotNull
4646
*/
4747
public String getProjectName() {
4848
if (UITestRunner.getIdeaVersionInt() >= 20221) {
49-
return textFields(byXpath("//div[@class='JBTextField']")).get(0).getText();
49+
return textFields(byXpath(XPathDefinitions.JBTEXT_FIELD)).get(0).getText();
5050
} else {
5151
return textFields(JTextFieldFixture.Companion.byType()).get(0).getText();
5252
}
@@ -59,7 +59,7 @@ public String getProjectName() {
5959
*/
6060
public void setProjectName(String projectName) {
6161
if (UITestRunner.getIdeaVersionInt() >= 20221) {
62-
textFields(byXpath("//div[@class='JBTextField']")).get(0).setText(projectName);
62+
textFields(byXpath(XPathDefinitions.JBTEXT_FIELD)).get(0).setText(projectName);
6363
} else {
6464
textFields(JTextFieldFixture.Companion.byType()).get(0).setText(projectName);
6565
}
@@ -72,7 +72,7 @@ public void setProjectName(String projectName) {
7272
*/
7373
public String getProjectLocation() {
7474
if (UITestRunner.getIdeaVersionInt() >= 20221) {
75-
return find(JTextFieldFixture.class, byXpath("//div[@class='ExtendableTextField']")).getText();
75+
return find(JTextFieldFixture.class, byXpath(XPathDefinitions.EXTENDABLE_TEXT_FIELD)).getText();
7676
} else {
7777
return textFields(JTextFieldFixture.Companion.byType()).get(1).getText();
7878
}
@@ -85,7 +85,7 @@ public String getProjectLocation() {
8585
*/
8686
public void setProjectLocation(String projectLocation) {
8787
if (UITestRunner.getIdeaVersionInt() >= 20221) {
88-
find(JTextFieldFixture.class, byXpath("//div[@class='ExtendableTextField']")).setText(projectLocation);
88+
find(JTextFieldFixture.class, byXpath(XPathDefinitions.EXTENDABLE_TEXT_FIELD )).setText(projectLocation);
8989
} else {
9090
textFields(JTextFieldFixture.Companion.byType()).get(1).setText(projectLocation);
9191
}
@@ -96,7 +96,11 @@ public void setProjectLocation(String projectLocation) {
9696
*/
9797
public void openAdvanceSettings() {
9898
if (!isAdvancedSettingsOpened()) {
99-
find(ComponentFixture.class, byXpath("//div[@class='CollapsibleTitledSeparator']")).click();
99+
if (UITestRunner.getIdeaVersionInt() >= 20222) {
100+
find(ComponentFixture.class, byXpath(XPathDefinitions.COLLAPSIBLE_TITLED_SEPARATOR_NEW)).click();
101+
} else {
102+
find(ComponentFixture.class, byXpath(XPathDefinitions.COLLAPSIBLE_TITLED_SEPARATOR)).click();
103+
}
100104
}
101105
}
102106

@@ -105,15 +109,26 @@ public void openAdvanceSettings() {
105109
*/
106110
public void closeAdvanceSettings() {
107111
if (isAdvancedSettingsOpened()) {
108-
find(ComponentFixture.class, byXpath("//div[@class='CollapsibleTitledSeparator']")).click();
112+
if (UITestRunner.getIdeaVersionInt() >= 20222) {
113+
find(ComponentFixture.class, byXpath(XPathDefinitions.COLLAPSIBLE_TITLED_SEPARATOR_NEW)).click();
114+
} else {
115+
find(ComponentFixture.class, byXpath(XPathDefinitions.COLLAPSIBLE_TITLED_SEPARATOR)).click();
116+
}
109117
}
110118
}
111119

112120
private boolean isAdvancedSettingsOpened() {
113-
List<ComponentFixture> ss = findAll(ComponentFixture.class, byXpath("//div[@class='CollapsibleTitledSeparator']/../*"));
114-
for (int i = 0; i < ss.size(); i++) {
115-
if (listOfRemoteTextToString(ss.get(i).findAllText()).contains("Advanced Settings")) {
116-
return i != ss.size() - 1;
121+
List<ComponentFixture> cf;
122+
123+
if (UITestRunner.getIdeaVersionInt() >= 20222) {
124+
cf = findAll(ComponentFixture.class, byXpath(XPathDefinitions.COLLAPSIBLE_TITLED_SEPARATOR_NEW_SIBLINGS));
125+
} else {
126+
cf = findAll(ComponentFixture.class, byXpath(XPathDefinitions.COLLAPSIBLE_TITLED_SEPARATOR_SIBLINGS));
127+
}
128+
129+
for (int i = 0; i < cf.size(); i++) {
130+
if (listOfRemoteTextToString(cf.get(i).findAllText()).contains("Advanced Settings")) {
131+
return i != cf.size() - 1;
117132
}
118133
}
119134
throw new UITestException("Wizard does not contain 'Advanced Settings' section.");

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void closeMoreSettings() {
7171
*/
7272
public String getModuleName() {
7373
if (UITestRunner.getIdeaVersionInt() >= 20221) {
74-
return find(JTextFieldFixture.class, byXpath("//div[@accessiblename='Module name:' and @accessiblename.key='label.project.wizard.new.project.module.name' and @class='JBTextField']")).getText();
74+
return find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_MODULE_NAME)).getText();
7575
} else {
7676
return textField("Module name:", true).getText();
7777
}
@@ -84,7 +84,7 @@ public String getModuleName() {
8484
*/
8585
public void setModuleName(String moduleName) {
8686
if (UITestRunner.getIdeaVersionInt() >= 20221) {
87-
find(JTextFieldFixture.class, byXpath("//div[@accessiblename='Module name:' and @accessiblename.key='label.project.wizard.new.project.module.name' and @class='JBTextField']")).setText(moduleName);
87+
find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_MODULE_NAME)).setText(moduleName);
8888
} else {
8989
textField("Module name:", true).setText(moduleName);
9090
}
@@ -97,7 +97,7 @@ public void setModuleName(String moduleName) {
9797
*/
9898
public String getContentRoot() {
9999
if (UITestRunner.getIdeaVersionInt() >= 20221) {
100-
return find(JTextFieldFixture.class, byXpath("//div[@accessiblename='Content root:' and @accessiblename.key='label.project.wizard.new.project.content.root' and @class='ExtendableTextField']")).getText();
100+
return find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_CONTENT_ROOT)).getText();
101101
} else {
102102
return textField("Content root:", true).getText();
103103
}
@@ -110,7 +110,7 @@ public String getContentRoot() {
110110
*/
111111
public void setContentRoot(String contentRoot) {
112112
if (UITestRunner.getIdeaVersionInt() >= 20221) {
113-
find(JTextFieldFixture.class, byXpath("//div[@accessiblename='Content root:' and @accessiblename.key='label.project.wizard.new.project.content.root' and @class='ExtendableTextField']")).setText(contentRoot);
113+
find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_CONTENT_ROOT)).setText(contentRoot);
114114
} else {
115115
textField("Content root:", true).setText(contentRoot);
116116
}
@@ -123,7 +123,7 @@ public void setContentRoot(String contentRoot) {
123123
*/
124124
public String getModuleFileLocation() {
125125
if (UITestRunner.getIdeaVersionInt() >= 20221) {
126-
return find(JTextFieldFixture.class, byXpath("//div[@accessiblename='Module file location:' and @accessiblename.key='label.project.wizard.new.project.module.file.location' and @class='ExtendableTextField']")).getText();
126+
return find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_MODULE_FILE_LOCATION)).getText();
127127
} else {
128128
return textField("Module file location:", true).getText();
129129
}
@@ -136,7 +136,7 @@ public String getModuleFileLocation() {
136136
*/
137137
public void setModuleFileLocation(String moduleFileLocation) {
138138
if (UITestRunner.getIdeaVersionInt() >= 20221) {
139-
find(JTextFieldFixture.class, byXpath("//div[@accessiblename='Module file location:' and @accessiblename.key='label.project.wizard.new.project.module.file.location' and @class='ExtendableTextField']")).setText(moduleFileLocation);
139+
find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_MODULE_FILE_LOCATION)).setText(moduleFileLocation);
140140
} else {
141141
textField("Module file location:", true).setText(moduleFileLocation);
142142
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void selectNewProjectType(String projectType) {
6767
*/
6868
@Override
6969
public void setProjectName(String projectName) {
70-
find(JTextFieldFixture.class, byXpath("//div[@class='JBTextField']")).setText(projectName);
70+
find(JTextFieldFixture.class, byXpath(XPathDefinitions.JBTEXT_FIELD)).setText(projectName);
7171
}
7272

7373
/**
@@ -76,7 +76,7 @@ public void setProjectName(String projectName) {
7676
* @param language project language
7777
*/
7878
public void setLanguage(String language) {
79-
findAll(JLabelFixture.class, byXpath("//div[@class='SegmentedButtonComponent'][.//div[contains(@action.key, 'language.groovy')]]")).get(0).findText(language).click();
79+
findAll(JLabelFixture.class, byXpath(XPathDefinitions.SET_LANGUAGE)).get(0).findText(language).click();
8080
}
8181

8282
/**
@@ -85,7 +85,7 @@ public void setLanguage(String language) {
8585
* @param buildSystem build system type
8686
*/
8787
public void setBuildSystem(String buildSystem) {
88-
find(JLabelFixture.class, byXpath("//div[@class='SegmentedButtonComponent'][.//div[@action.key='buildsystem.type.intellij']]")).findText(buildSystem).click();
88+
find(JLabelFixture.class, byXpath(XPathDefinitions.SET_BUILD_SYSTEM)).findText(buildSystem).click();
8989
}
9090

9191
/**

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/menubar/MenuBar.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ private JButtonFixture mainMenuItem(String label) {
7575
CommonContainerFixture cf;
7676
if (remoteRobot.isLinux()) {
7777
cf = remoteRobot.find(CommonContainerFixture.class, byXpath(XPathDefinitions.LINUX_MAIN_MENU), Duration.ofSeconds(10));
78+
} else if (remoteRobot.isWin() && ideaVersion.toInt() >= 20222) {
79+
cf = remoteRobot.find(CommonContainerFixture.class, byXpath(XPathDefinitions.WINDOWS_MAIN_MENU_2022_2_AND_NEWER), Duration.ofSeconds(10));
7880
} else if (remoteRobot.isWin() && ideaVersion.toInt() >= 20203) {
79-
cf = remoteRobot.find(CommonContainerFixture.class, byXpath(XPathDefinitions.WINDOWS_MAIN_MENU_2020_3_AND_NEWER), Duration.ofSeconds(10));
81+
cf = remoteRobot.find(CommonContainerFixture.class, byXpath(XPathDefinitions.WINDOWS_MAIN_MENU_2020_3_TO_2022_1), Duration.ofSeconds(10));
8082
} else {
8183
cf = remoteRobot.find(CommonContainerFixture.class, byXpath(XPathDefinitions.WINDOWS_MAIN_MENU_2020_2_AND_OLDER), Duration.ofSeconds(10));
8284
}

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/toolwindowspane/AbstractToolWinPane.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane.buildtoolpane.GradleBuildToolPane;
2121
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane.buildtoolpane.MavenBuildToolPane;
2222
import com.redhat.devtools.intellij.commonuitest.utils.constants.ButtonLabels;
23+
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
2324
import org.jetbrains.annotations.NotNull;
2425

2526
import java.time.Duration;
@@ -98,12 +99,12 @@ public void closeGradleBuildToolPane() {
9899
public JButtonFixture stripeButton(String label, boolean isPaneOpened) {
99100
if (isPaneOpened) {
100101
if (label.equals(ButtonLabels.MAVEN_STRIPE_BUTTON_LABEL) || label.equals(ButtonLabels.GRADLE_STRIPE_BUTTON_LABEL)) {
101-
return button(byXpath("//div[@disabledicon='toolWindow" + label + ".svg']"), Duration.ofSeconds(2));
102+
return button(byXpath(XPathDefinitions.toolWindowSvg(label)), Duration.ofSeconds(2));
102103
} else if (label.equals(ButtonLabels.PROJECT_STRIPE_BUTTON_LABEL)) {
103-
return button(byXpath("//div[@tooltiptext='Project']"), Duration.ofSeconds(2));
104+
return button(byXpath(XPathDefinitions.TOOLTIP_TEXT_PROJECT), Duration.ofSeconds(2));
104105
}
105106
}
106-
return button(byXpath("//div[@text='" + label + "']"), Duration.ofSeconds(2));
107+
return button(byXpath(XPathDefinitions.label(label)), Duration.ofSeconds(2));
107108
}
108109

109110
protected <T extends Fixture> T togglePane(String label, Class<T> fixtureClass, boolean openPane) {

0 commit comments

Comments
 (0)