Skip to content

Commit f922e45

Browse files
authored
Add support for IntelliJ 2022.1 (#109)
* Add support for IntelliJ 2022.1 Fixes #108 Signed-off-by: Zbynek Cervinka <[email protected]> * Several fixes and reworks: - exctraction of the enumeration with supported IntelliJs to start - rewrite some tests to use conditional test execution - fix linux failing test - change the 10 second timeout to 2 seconds Signed-off-by: Zbynek Cervinka <[email protected]> * Move the enumeration from inside a class to toplevel. Signed-off-by: Zbynek Cervinka <[email protected]> * Timeout 400 Signed-off-by: Zbynek Cervinka <[email protected]> * Timeout 500 Signed-off-by: Zbynek Cervinka <[email protected]>
1 parent 6b693f0 commit f922e45

File tree

45 files changed

+935
-221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+935
-221
lines changed

src/main/java/com/redhat/devtools/intellij/commonuitest/UITestRunner.java

Lines changed: 35 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
1717
import com.redhat.devtools.intellij.commonuitest.exceptions.UITestException;
1818
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.FlatWelcomeFrame;
19+
import com.redhat.devtools.intellij.commonuitest.utils.runner.IntelliJVersion;
1920

2021
import java.io.File;
2122
import java.io.FileOutputStream;
@@ -49,7 +50,7 @@ public class UITestRunner {
4950
private static final String USER_HOME = System.getProperty("user.home");
5051
private static RemoteRobot remoteRobot = null;
5152
private static Process ideProcess;
52-
private static IdeaVersion ideaVersion;
53+
private static IntelliJVersion ideaVersion;
5354

5455
/**
5556
* Start the given version of IntelliJ Idea listening on the given port
@@ -58,19 +59,20 @@ public class UITestRunner {
5859
* @param port port number on which will the IntelliJ Idea be listening
5960
* @return instance of the RemoteRobot
6061
*/
61-
public static RemoteRobot runIde(IdeaVersion ideaVersion, int port) {
62+
public static RemoteRobot runIde(IntelliJVersion ideaVersion, int port) {
6263
StepWorker.registerProcessor(new StepLogger());
6364

6465
return step("Start IntelliJ Idea ('" + ideaVersion.toString() + "') listening on port " + port, () -> {
66+
System.setProperty("uitestlib.idea.version", Integer.toString(ideaVersion.toInt()));
6567
UITestRunner.ideaVersion = ideaVersion;
66-
acceptAllTermsAndConditions();
6768

69+
acceptAllTermsAndConditions();
6870
if (ideaVersion.isUltimate()) {
6971
activateEvaluateForFree();
7072
}
7173

7274
String fileExtension = OS_NAME.contains("windows") ? ".bat" : "";
73-
ProcessBuilder pb = new ProcessBuilder("." + File.separator + "gradlew" + fileExtension, "runIdeForUiTests", "-PideaVersion=" + ideaVersion.toString(), "-Drobot-server.port=" + port);
75+
ProcessBuilder pb = new ProcessBuilder("." + File.separator + "gradlew" + fileExtension, "runIdeForUiTests", "-PideaVersion=" + ideaVersion, "-Drobot-server.port=" + port);
7476

7577
try {
7678
ideProcess = pb.start();
@@ -91,7 +93,7 @@ public static RemoteRobot runIde(IdeaVersion ideaVersion, int port) {
9193
* @param ideaVersion version of the IntelliJ Idea to start
9294
* @return instance of the RemoteRobot
9395
*/
94-
public static RemoteRobot runIde(IdeaVersion ideaVersion) {
96+
public static RemoteRobot runIde(IntelliJVersion ideaVersion) {
9597
return runIde(ideaVersion, DEFAULT_PORT);
9698
}
9799

@@ -103,14 +105,23 @@ public static void closeIde() {
103105
}
104106

105107
/**
106-
* Return the integer representation of the currently running IntelliJ Idea version
108+
* Return the IdeaVersion representation of the currently running IntelliJ Idea version
107109
*
108110
* @return version of the currently running IntelliJ Idea
109111
*/
110-
public static IdeaVersion getIdeaVersion() {
112+
public static IntelliJVersion getIdeaVersion() {
111113
return ideaVersion;
112114
}
113115

116+
/**
117+
* Return the integer representation of the currently running IntelliJ Idea version
118+
*
119+
* @return version of the currently running IntelliJ Idea
120+
*/
121+
public static int getIdeaVersionInt() {
122+
return getIdeaVersion().toInt();
123+
}
124+
114125
/**
115126
* Return the reference to the Remote Robot instance
116127
*
@@ -146,53 +157,30 @@ public static RemoteRobot getRemoteRobotConnection(int port) {
146157
});
147158
}
148159

149-
/**
150-
* Enumeration for supported versions of the IntelliJ Idea
151-
*/
152-
public enum IdeaVersion {
153-
COMMUNITY_V_2020_2("IC-2020.2"),
154-
COMMUNITY_V_2020_3("IC-2020.3"),
155-
COMMUNITY_V_2021_1("IC-2021.1"),
156-
COMMUNITY_V_2021_2("IC-2021.2"),
157-
COMMUNITY_V_2021_3("IC-2021.3"),
158-
ULTIMATE_V_2020_2("IU-2020.2"),
159-
ULTIMATE_V_2020_3("IU-2020.3"),
160-
ULTIMATE_V_2021_1("IU-2021.1"),
161-
ULTIMATE_V_2021_2("IU-2021.2");
162-
163-
private final String ideaVersionStringRepresentation;
164-
165-
IdeaVersion(String ideaVersionStringRepresentation) {
166-
this.ideaVersionStringRepresentation = ideaVersionStringRepresentation;
167-
}
168-
169-
@Override
170-
public String toString() {
171-
return ideaVersionStringRepresentation;
172-
}
173-
174-
public int toInt() {
175-
String ideaVersion = this.ideaVersionStringRepresentation.substring(3).replace(".", "");
176-
return Integer.parseInt(ideaVersion);
160+
private static void acceptAllTermsAndConditions() {
161+
String osxPlistSourceLocation;
162+
if (ideaVersion.isUltimate()) {
163+
osxPlistSourceLocation = "plist/ultimate_all/com.apple.java.util.prefs.plist";
164+
} else if (ideaVersion.toInt() <= 20213) {
165+
osxPlistSourceLocation = "plist/2021_3_and_older/com.apple.java.util.prefs.plist";
166+
} else {
167+
osxPlistSourceLocation = "plist/2022_1/com.apple.java.util.prefs.plist";
177168
}
178169

179-
public boolean isUltimate() {
180-
return this.ideaVersionStringRepresentation.charAt(1) == 'U';
170+
String linuxPrefsXmlSourceLocation;
171+
if (ideaVersion.isUltimate()) {
172+
linuxPrefsXmlSourceLocation = "prefs_xml/ultimate_all/prefs.xml";
173+
} else if (ideaVersion.toInt() <= 20213) {
174+
linuxPrefsXmlSourceLocation = "prefs_xml/2021_3_and_older/prefs.xml";
175+
} else {
176+
linuxPrefsXmlSourceLocation = "prefs_xml/2022_1/prefs.xml";
181177
}
182-
}
183178

184-
private static void acceptAllTermsAndConditions() {
185179
if (OS_NAME.contains("linux")) {
186180
step("Copy the 'prefs.xml' file to the appropriate location", () -> {
187-
String prefsXmlSourceLocation;
188-
if (!ideaVersion.isUltimate()) {
189-
prefsXmlSourceLocation = "prefs.xml";
190-
} else {
191-
prefsXmlSourceLocation = "prefs_xml/ultimate_all/prefs.xml";
192-
}
193181
String prefsXmlDir = USER_HOME + "/.java/.userPrefs/jetbrains/_!(!!cg\"p!(}!}@\"j!(k!|w\"w!'8!b!\"p!':!e@==";
194182
createDirectoryHierarchy(prefsXmlDir);
195-
copyFileFromJarResourceDir(prefsXmlSourceLocation, prefsXmlDir + "/prefs.xml");
183+
copyFileFromJarResourceDir(linuxPrefsXmlSourceLocation, prefsXmlDir + "/prefs.xml");
196184
});
197185

198186
step(COPY_ACCEPTED_FILE_STEP_DESCRIPTION, () -> {
@@ -202,14 +190,8 @@ private static void acceptAllTermsAndConditions() {
202190
});
203191
} else if (OS_NAME.contains("os x")) {
204192
step("Copy the 'com.apple.java.util.prefs.plist' file to the appropriate location", () -> {
205-
String plistSourceLocation;
206-
if (!ideaVersion.isUltimate()) {
207-
plistSourceLocation = "com.apple.java.util.prefs.plist";
208-
} else {
209-
plistSourceLocation = "plist/ultimate_all/com.apple.java.util.prefs.plist";
210-
}
211193
String plistDir = USER_HOME + "/Library/Preferences";
212-
copyFileFromJarResourceDir(plistSourceLocation, plistDir + "/com.apple.java.util.prefs.plist");
194+
copyFileFromJarResourceDir(osxPlistSourceLocation, plistDir + "/com.apple.java.util.prefs.plist");
213195
});
214196

215197
step(COPY_ACCEPTED_FILE_STEP_DESCRIPTION, () -> {

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.settings.SettingsDialog;
3232
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.settings.pages.NotificationsPage;
3333
import com.redhat.devtools.intellij.commonuitest.utils.constans.XPathDefinitions;
34+
import com.redhat.devtools.intellij.commonuitest.utils.internalerror.IdeInternalErrorUtils;
35+
import com.redhat.devtools.intellij.commonuitest.utils.runner.IntelliJVersion;
3436
import org.apache.commons.io.FileUtils;
3537
import org.jetbrains.annotations.NotNull;
3638

@@ -44,6 +46,7 @@
4446
import java.util.logging.Logger;
4547

4648
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
49+
import static com.redhat.devtools.intellij.commonuitest.utils.screenshot.ScreenshotUtils.takeScreenshot;
4750

4851
/**
4952
* Welcome to IntelliJ IDEA dialog fixture
@@ -56,7 +59,7 @@ public class FlatWelcomeFrame extends CommonContainerFixture {
5659
private static final Logger LOGGER = Logger.getLogger(FlatWelcomeFrame.class.getName());
5760
private static final String PROJECTS_BUTTON = "Projects";
5861
private final RemoteRobot remoteRobot;
59-
private final UITestRunner.IdeaVersion intelliJVersion;
62+
private final IntelliJVersion intelliJVersion;
6063
private final int ideaVersion;
6164

6265
public FlatWelcomeFrame(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
@@ -175,11 +178,13 @@ public TipDialog openTipDialog() {
175178
} else if (ideaVersion <= 20212) {
176179
JListFixture jListFixture = remoteRobot.find(JListFixture.class, byXpath(XPathDefinitions.JBLIST));
177180
jListFixture.findText("Learn IntelliJ IDEA").click();
178-
remoteRobot.find(JLabelFixture.class, byXpath(XPathDefinitions.TIP_DIALOGA_2)).click();
181+
remoteRobot.find(JLabelFixture.class, byXpath(XPathDefinitions.TIP_DIALOG_2)).click();
179182
} else {
183+
IdeInternalErrorUtils.clearWindowsErrorsIfTheyAppear(remoteRobot);
180184
JTreeFixture jTreeFixture = remoteRobot.find(JTreeFixture.class, byXpath(XPathDefinitions.TREE));
181185
jTreeFixture.findText("Learn IntelliJ IDEA").click();
182-
remoteRobot.find(JLabelFixture.class, byXpath(XPathDefinitions.TIP_DIALOGA_2)).click();
186+
FlatWelcomeFrame flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class);
187+
flatWelcomeFrame.findText("Tip of the Day").click();
183188
}
184189

185190
return remoteRobot.find(TipDialog.class, Duration.ofSeconds(10));
@@ -195,14 +200,7 @@ public void disableNotifications() {
195200
NotificationsPage notificationsPage = remoteRobot.find(NotificationsPage.class, Duration.ofSeconds(5));
196201
notificationsPage.toggleNotifications(false);
197202
settingsDialog.ok();
198-
199-
if (ideaVersion >= 20213) {
200-
JTreeFixture jTreeFixture = remoteRobot.find(JTreeFixture.class, byXpath(XPathDefinitions.TREE));
201-
jTreeFixture.findText(PROJECTS_BUTTON).click();
202-
} else if (ideaVersion >= 20203) {
203-
JListFixture jListFixture = remoteRobot.find(JListFixture.class, byXpath(XPathDefinitions.JBLIST));
204-
jListFixture.clickItem(PROJECTS_BUTTON, false);
205-
}
203+
switchToProjectsPage();
206204
}
207205

208206
/**
@@ -212,7 +210,13 @@ public void preventTipDialogFromOpening() {
212210
TipDialog tipDialog = openTipDialog();
213211
tipDialog.dontShowTipsCheckBox().setValue(true);
214212
tipDialog.close();
213+
switchToProjectsPage();
214+
}
215215

216+
/**
217+
* Switch to the 'Projects' page of flat welcome frame
218+
*/
219+
public void switchToProjectsPage() {
216220
if (ideaVersion >= 20213) {
217221
JTreeFixture jTreeFixture = remoteRobot.find(JTreeFixture.class, byXpath(XPathDefinitions.TREE));
218222
jTreeFixture.findText(PROJECTS_BUTTON).click();

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.awt.event.KeyEvent;
2929
import java.time.Duration;
30+
import java.util.ArrayList;
3031
import java.util.List;
3132

3233
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
@@ -40,7 +41,7 @@
4041
@DefaultXpath(by = "SearchEverywhereUI type", xpath = XPathDefinitions.SEARCH_EVERYWHERE_POPUP)
4142
@FixtureName(name = "Search Everywhere Popup")
4243
public class SearchEverywherePopup extends CommonContainerFixture {
43-
private RemoteRobot remoteRobot;
44+
private final RemoteRobot remoteRobot;
4445

4546
public SearchEverywherePopup(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
4647
super(remoteRobot, remoteComponent);
@@ -79,7 +80,11 @@ private boolean didSearchFinish(String cmdToInvoke) {
7980
}
8081

8182
private List<RemoteText> getSearchResults() {
82-
JListFixture searchResultsList = jLists(JListFixture.Companion.byType()).get(0);
83+
List<JListFixture> searchResults = jLists(JListFixture.Companion.byType());
84+
if (searchResults.isEmpty()) {
85+
return new ArrayList<>();
86+
};
87+
JListFixture searchResultsList = searchResults.get(0);
8388
return searchResultsList.findAllText();
8489
}
8590
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.intellij.remoterobot.fixtures.FixtureName;
1818
import com.intellij.remoterobot.fixtures.JButtonFixture;
1919
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
20+
import com.redhat.devtools.intellij.commonuitest.UITestRunner;
2021
import com.redhat.devtools.intellij.commonuitest.exceptions.UITestException;
2122
import com.redhat.devtools.intellij.commonuitest.utils.constans.ButtonLabels;
2223
import com.redhat.devtools.intellij.commonuitest.utils.constans.XPathDefinitions;
@@ -49,10 +50,14 @@ public void next() {
4950
}
5051

5152
/**
52-
* Finish the 'New Project' dialog by clicking on the 'Finish' button
53+
* Finish the 'New Project' dialog
5354
*/
5455
public void finish() {
55-
clickOnButton(ButtonLabels.FINISH_LABEL);
56+
if (UITestRunner.getIdeaVersionInt() >= 20221) {
57+
clickOnButton(ButtonLabels.CREATE_LABEL);
58+
} else {
59+
clickOnButton(ButtonLabels.FINISH_LABEL);
60+
}
5661
}
5762

5863
/**

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

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@
1313
import com.intellij.remoterobot.RemoteRobot;
1414
import com.intellij.remoterobot.data.RemoteComponent;
1515
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
16+
import com.intellij.remoterobot.fixtures.ComponentFixture;
1617
import com.intellij.remoterobot.fixtures.DefaultXpath;
1718
import com.intellij.remoterobot.fixtures.FixtureName;
1819
import com.intellij.remoterobot.fixtures.JTextFieldFixture;
20+
import com.redhat.devtools.intellij.commonuitest.UITestRunner;
21+
import com.redhat.devtools.intellij.commonuitest.exceptions.UITestException;
1922
import com.redhat.devtools.intellij.commonuitest.utils.constans.XPathDefinitions;
2023
import org.jetbrains.annotations.NotNull;
2124

25+
import java.util.List;
26+
27+
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
28+
import static com.redhat.devtools.intellij.commonuitest.utils.texttranformation.TextUtils.listOfRemoteTextToString;
29+
2230
/**
2331
* New Project dialog abstract terminal page fixture
2432
*
@@ -37,7 +45,11 @@ protected AbstractNewProjectFinalPage(@NotNull RemoteRobot remoteRobot, @NotNull
3745
* @return currently set new project name
3846
*/
3947
public String getProjectName() {
40-
return textFields(JTextFieldFixture.Companion.byType()).get(0).getText();
48+
if (UITestRunner.getIdeaVersionInt() >= 20221) {
49+
return textFields(byXpath("//div[@class='JBTextField']")).get(0).getText();
50+
} else {
51+
return textFields(JTextFieldFixture.Companion.byType()).get(0).getText();
52+
}
4153
}
4254

4355
/**
@@ -46,7 +58,11 @@ public String getProjectName() {
4658
* @param projectName name of the new project
4759
*/
4860
public void setProjectName(String projectName) {
49-
textFields(JTextFieldFixture.Companion.byType()).get(0).setText(projectName);
61+
if (UITestRunner.getIdeaVersionInt() >= 20221) {
62+
textFields(byXpath("//div[@class='JBTextField']")).get(0).setText(projectName);
63+
} else {
64+
textFields(JTextFieldFixture.Companion.byType()).get(0).setText(projectName);
65+
}
5066
}
5167

5268
/**
@@ -55,7 +71,11 @@ public void setProjectName(String projectName) {
5571
* @return currently set new project location
5672
*/
5773
public String getProjectLocation() {
58-
return textFields(JTextFieldFixture.Companion.byType()).get(1).getText();
74+
if (UITestRunner.getIdeaVersionInt() >= 20221) {
75+
return find(JTextFieldFixture.class, byXpath("//div[@class='ExtendableTextField']")).getText();
76+
} else {
77+
return textFields(JTextFieldFixture.Companion.byType()).get(1).getText();
78+
}
5979
}
6080

6181
/**
@@ -64,7 +84,39 @@ public String getProjectLocation() {
6484
* @param projectLocation project location of the new project
6585
*/
6686
public void setProjectLocation(String projectLocation) {
67-
textFields(JTextFieldFixture.Companion.byType()).get(1).setText(projectLocation);
87+
if (UITestRunner.getIdeaVersionInt() >= 20221) {
88+
find(JTextFieldFixture.class, byXpath("//div[@class='ExtendableTextField']")).setText(projectLocation);
89+
} else {
90+
textFields(JTextFieldFixture.Companion.byType()).get(1).setText(projectLocation);
91+
}
92+
}
93+
94+
/**
95+
* Open the 'Advanced Settings' section
96+
*/
97+
public void openAdvanceSettings() {
98+
if (!isAdvancedSettingsOpened()) {
99+
find(ComponentFixture.class, byXpath("//div[@class='CollapsibleTitledSeparator']")).click();
100+
}
101+
}
102+
103+
/**
104+
* Close the 'Advanced Settings' section
105+
*/
106+
public void closeAdvanceSettings() {
107+
if (isAdvancedSettingsOpened()) {
108+
find(ComponentFixture.class, byXpath("//div[@class='CollapsibleTitledSeparator']")).click();
109+
}
110+
}
111+
112+
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;
117+
}
118+
}
119+
throw new UITestException("Wizard does not contain 'Advanced Settings' section.");
68120
}
69121

70122
/**
@@ -74,7 +126,7 @@ public enum ProjectFormatType {
74126
IDEA_DIRECTORY_BASED(".idea"),
75127
IPR_FILE_BASED(".ipr");
76128

77-
private String textRepresentation;
129+
private final String textRepresentation;
78130

79131
ProjectFormatType(String textRepresentation) {
80132
this.textRepresentation = textRepresentation;

0 commit comments

Comments
 (0)