Skip to content

Commit dcf0bb5

Browse files
committed
chore: fix integration tests
Signed-off-by: Stephane Bouchet <[email protected]>
1 parent 8bdfa90 commit dcf0bb5

File tree

20 files changed

+110
-116
lines changed

20 files changed

+110
-116
lines changed

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

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@
1212

1313
import com.intellij.remoterobot.RemoteRobot;
1414
import com.intellij.remoterobot.data.RemoteComponent;
15-
import com.intellij.remoterobot.fixtures.*;
15+
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
16+
import com.intellij.remoterobot.fixtures.ComponentFixture;
17+
import com.intellij.remoterobot.fixtures.ContainerFixture;
18+
import com.intellij.remoterobot.fixtures.DefaultXpath;
19+
import com.intellij.remoterobot.fixtures.FixtureName;
20+
import com.intellij.remoterobot.fixtures.HeavyWeightWindowFixture;
21+
import com.intellij.remoterobot.fixtures.JButtonFixture;
22+
import com.intellij.remoterobot.fixtures.JListFixture;
23+
import com.intellij.remoterobot.fixtures.JPopupMenuFixture;
24+
import com.intellij.remoterobot.fixtures.JTreeFixture;
1625
import com.intellij.remoterobot.utils.UtilsKt;
1726
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
1827
import com.redhat.devtools.intellij.commonuitest.UITestRunner;
@@ -130,7 +139,6 @@ public void clearExceptions() {
130139
find(IdeFatalErrorsDialog.class, Duration.ofSeconds(10)).clearAll();
131140
} catch (WaitForConditionTimeoutException e) {
132141
LOGGER.log(Level.INFO, "No fatal errors dialog found to clear.");
133-
134142
try {
135143
find(IdeFatalErrorsDialog.class, Duration.ofSeconds(10)).clearAll();
136144
} catch (Exception e2) {
@@ -154,43 +162,38 @@ public void openSettingsDialog() {
154162
} else {
155163
JTreeFixture jTreeFixture = remoteRobot.find(JTreeFixture.class, byXpath(XPathDefinitions.TREE));
156164
jTreeFixture.findText("Customize").click();
157-
158165
if (remoteRobot.isMac()) {
159-
resizeWelcomeWindow(remoteRobot, 900);
166+
resizeWelcomeWindow(900);
160167
}
161-
162-
remoteRobot.find(ContainerFixture.class, byXpath(XPathDefinitions.DIALOG_PANEL))
163-
.findText("All settings" + '\u2026')
164-
.click();
168+
remoteRobot.find(ContainerFixture.class, byXpath(XPathDefinitions.DIALOG_PANEL)).findText("All settings" + '\u2026').click();
165169
}
166170
}
167171

168172
/**
169173
* Resize the Welcome to IntelliJ IDEA window
170174
*
171-
* @param remoteRobot Valid instance of remote robot
172-
* @param newHeight Integer of new height to use
175+
* @param newHeight Integer of new height to use
173176
*/
174-
private void resizeWelcomeWindow(RemoteRobot remoteRobot, int newHeight) {
177+
private void resizeWelcomeWindow(int newHeight) {
175178
try {
176179
remoteRobot.callJs(String.format("""
177-
importClass(java.awt.Frame);
178-
importClass(javax.swing.SwingUtilities);
179-
var frames = Frame.getFrames();
180-
var resized = false;
181-
for (var i = 0; i < frames.length; i++) {
182-
var frame = frames[i];
183-
if (frame.isShowing() && frame.getClass().getName().contains("FlatWelcomeFrame")) {
184-
SwingUtilities.invokeLater(function() {
185-
frame.setSize(frame.getWidth(), %d);
186-
frame.validate();
187-
});
188-
resized = true;
189-
break;
190-
}
180+
importClass(java.awt.Frame);
181+
importClass(javax.swing.SwingUtilities);
182+
var frames = Frame.getFrames();
183+
var resized = false;
184+
for (var i = 0; i < frames.length; i++) {
185+
var frame = frames[i];
186+
if (frame.isShowing() && frame.getClass().getName().contains("FlatWelcomeFrame")) {
187+
SwingUtilities.invokeLater(function() {
188+
frame.setSize(frame.getWidth(), %d);
189+
frame.validate();
190+
});
191+
resized = true;
192+
break;
191193
}
192-
resized;
193-
""", newHeight));
194+
}
195+
resized;
196+
""", newHeight));
194197
Thread.sleep(5000);
195198
} catch (Exception e) {
196199
LOGGER.log(Level.WARNING, "Failed to resize the Welcome window: {0}", e.getMessage());
@@ -212,7 +215,7 @@ public TipDialog openTipDialog() {
212215
} else {
213216
flatWelcomeFrame.findText(ButtonLabels.LEARN_INTELLIJ_IDEA_LABEL).click();
214217
}
215-
SharedSteps.waitForComponentByXpath(remoteRobot, 2, 1, byXpath(XPathDefinitions.TIP_DIALOG_2));
218+
SharedSteps.createSharedSteps().waitForComponentByXpath(remoteRobot, 2, 1, byXpath(XPathDefinitions.TIP_DIALOG_2));
216219
flatWelcomeFrame.findText(TIP_OF_THE_DAY).click();
217220
} else if (ideaVersion <= 20202) {
218221
clickOnLink("Get Help");
@@ -307,12 +310,11 @@ private void removeTopProjectFromRecentProjects() {
307310

308311
// Clicks on X on first recent project to remove it from the recent projects list (visible only when hovered over with cursor)
309312
recentProjects.runJs("const horizontal_offset = component.getWidth()-22;\n" +
310-
"robot.click(component, new Point(horizontal_offset, 22), MouseButton.LEFT_BUTTON, 1);");
313+
"robot.click(component, new Point(horizontal_offset, 22), MouseButton.LEFT_BUTTON, 1);");
311314

312315
if (ideaVersion >= 20231) {
313316
ComponentFixture removeDialog = remoteRobot.find(ComponentFixture.class, byXpath(XPathDefinitions.MY_DIALOG), Duration.ofSeconds(10));
314-
removeDialog.findText(ButtonLabels.REMOVE_FROM_LIST_LABEL)
315-
.click();
317+
removeDialog.findText(ButtonLabels.REMOVE_FROM_LIST_LABEL).click();
316318
} else if (ideaVersion >= 20203) { // Code for IntelliJ Idea 2020.3 or newer
317319
List<JPopupMenuFixture> jPopupMenuFixtures = jPopupMenus(JPopupMenuFixture.Companion.byType());
318320
if (!jPopupMenuFixtures.isEmpty()) {
@@ -327,19 +329,6 @@ private void removeTopProjectFromRecentProjects() {
327329
}
328330
}
329331

330-
/**
331-
* Open existing project from the Welcome Dialog
332-
*
333-
* @param remoteRobot reference to the RemoteRobot instance
334-
* @param projectName name of existing project
335-
*/
336-
public void openProjectFromWelcomeDialog(RemoteRobot remoteRobot, String projectName) {
337-
FlatWelcomeFrame flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10));
338-
flatWelcomeFrame.openProject(projectName);
339-
340-
CreateCloseUtils.waitAfterOpeningProject(remoteRobot);
341-
}
342-
343332
/**
344333
* Open 'New Project' dialog from 'Welcome to IntelliJ IDEA' dialog
345334
*

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,26 @@ public MainIdeWindow(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent
4848
*/
4949
public void maximizeIdeWindow() {
5050
if (remoteRobot.isWin()) {
51-
runJs("const width = component.getWidth();\n" +
52-
"const height = component.getHeight();\n" +
53-
"const horizontal_offset = width-72;\n" +
54-
"robot.click(component, new Point(horizontal_offset, 14), MouseButton.LEFT_BUTTON, 1);\n" +
55-
"const width_after = component.getWidth();\n" +
56-
"const height_after = component.getHeight();\n" +
57-
"const horizontal_offset_after = width_after-72;\n" +
58-
"if (width > width_after || height > height_after) { robot.click(component, new Point(horizontal_offset_after, 14), MouseButton.LEFT_BUTTON, 1); }");
51+
runJs("""
52+
const width = component.getWidth();
53+
const height = component.getHeight();
54+
const horizontal_offset = width-72;
55+
robot.click(component, new Point(horizontal_offset, 14), MouseButton.LEFT_BUTTON, 1);
56+
const width_after = component.getWidth();
57+
const height_after = component.getHeight();
58+
const horizontal_offset_after = width_after-72;
59+
if (width > width_after || height > height_after) { robot.click(component, new Point(horizontal_offset_after, 14), MouseButton.LEFT_BUTTON, 1); }""");
60+
5961
} else {
60-
runJs("const width = component.getWidth();\n" +
61-
"const height = component.getHeight();\n" +
62-
"const horizontal_offset = width/2;\n" +
63-
"robot.click(component, new Point(horizontal_offset, 10), MouseButton.LEFT_BUTTON, 2);\n" +
64-
"const width_after = component.getWidth();\n" +
65-
"const height_after = component.getHeight();\n" +
66-
"const horizontal_offset_after = width_after/2;\n" +
67-
"if (width > width_after || height > height_after) { robot.click(component, new Point(horizontal_offset_after, 10), MouseButton.LEFT_BUTTON, 2); }");
62+
runJs("""
63+
const width = component.getWidth();
64+
const height = component.getHeight();
65+
const horizontal_offset = width/2;
66+
robot.click(component, new Point(horizontal_offset, 10), MouseButton.LEFT_BUTTON, 2);
67+
const width_after = component.getWidth();
68+
const height_after = component.getHeight();
69+
const horizontal_offset_after = width_after/2;
70+
if (width > width_after || height > height_after) { robot.click(component, new Point(horizontal_offset_after, 10), MouseButton.LEFT_BUTTON, 2); }""");
6871
}
6972
}
7073

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
import com.intellij.remoterobot.fixtures.DefaultXpath;
77
import com.intellij.remoterobot.fixtures.FixtureName;
88
import com.intellij.remoterobot.fixtures.JButtonFixture;
9-
import com.redhat.devtools.intellij.commonuitest.UITestRunner;
10-
import com.redhat.devtools.intellij.commonuitest.utils.constants.ButtonLabels;
119
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
1210
import org.jetbrains.annotations.NotNull;
1311

1412
import java.time.Duration;
1513

1614
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
17-
import static org.assertj.swing.core.MouseClickInfo.button;
1815

1916
@DefaultXpath(by = "ToolWindowRightToolbar type", xpath = "//div[@class='ToolWindowRightToolbar']")
2017
@FixtureName(name = "Tool Window Right Toolbar")

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public class XPathDefinitions {
7878
public static final String MY_ICON_EXPAND_ALL = "//div[contains(@myvisibleactions, 'View),')]//div[@myicon='expandall.svg']";
7979
public static final String MY_ICON_EXPAND_ALL_2024_2 = "//div[@myicon='expandAll.svg']";
8080
public static final String MY_ICON_EXPAND_ALL_IDE = "//div[contains(@myvisibleactions, 'IDE')]//div[@myicon='expandall.svg']";
81+
@Language("XPath")
8182
public static final String MY_ICON_LOCATE_SVG = "//div[@myicon='locate.svg']";
8283
public static final String MY_ICON_REFRESH = "//div[@myicon='refresh.svg']";
8384
public static final String CONTENT_COMBO_LABEL = "//div[@class='ContentComboLabel']";

src/main/java/com/redhat/devtools/intellij/commonuitest/utils/project/CreateCloseUtils.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,6 @@ public static void waitAfterOpeningProject(RemoteRobot remoteRobot) {
125125
CodeWithMeDialog.closeCodeWithMePopupIfItAppears(remoteRobot);
126126
}
127127

128-
/**
129-
* Close currently opened project
130-
*
131-
* @param remoteRobot reference to the RemoteRobot instance
132-
*/
133-
public static void closeProject(RemoteRobot remoteRobot) {
134-
MainIdeWindow mainIdeWindow = remoteRobot.find(MainIdeWindow.class, Duration.ofSeconds(10));
135-
mainIdeWindow.closeProject();
136-
}
137-
138128
/**
139129
* Get appropriate final page instance
140130
*
@@ -143,15 +133,12 @@ public static void closeProject(RemoteRobot remoteRobot) {
143133
* @return final page instance
144134
*/
145135
public static AbstractNewProjectFinalPage getFinalPage(NewProjectDialogWizard newProjectDialogWizard, NewProjectType newProjectType) {
146-
switch (newProjectType) {
147-
case PLAIN_JAVA:
148-
return newProjectDialogWizard.find(JavaNewProjectFinalPage.class, Duration.ofSeconds(10));
149-
case MAVEN:
150-
case GRADLE:
151-
return newProjectDialogWizard.find(MavenGradleNewProjectFinalPage.class, Duration.ofSeconds(10));
152-
default:
153-
throw new UITestException("Unsupported project type.");
154-
}
136+
return switch (newProjectType) {
137+
case PLAIN_JAVA -> newProjectDialogWizard.find(JavaNewProjectFinalPage.class, Duration.ofSeconds(10));
138+
case MAVEN, GRADLE ->
139+
newProjectDialogWizard.find(MavenGradleNewProjectFinalPage.class, Duration.ofSeconds(10));
140+
default -> throw new UITestException("Unsupported project type.");
141+
};
155142
}
156143

157144
/**

src/main/java/com/redhat/devtools/intellij/commonuitest/utils/steps/SharedSteps.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* These methods facilitate common automation steps that can be reused in various test scenarios.
2222
*/
2323
public class SharedSteps {
24+
private SharedSteps() {}
25+
2426
/**
2527
* Waits for a component to be visible within the IDE's UI hierarchy based on the provided XPath locator.
2628
*
@@ -29,9 +31,13 @@ public class SharedSteps {
2931
* @param interval The interval at which to check the component's visibility, in seconds.
3032
* @param xpath The XPath locator used to find the component within the UI hierarchy.
3133
*/
32-
public static void waitForComponentByXpath(RemoteRobot robot, int duration, int interval , Locator xpath) {
34+
public void waitForComponentByXpath(RemoteRobot robot, int duration, int interval , Locator xpath) {
3335
waitFor(Duration.ofSeconds(duration), Duration.ofSeconds(interval), () -> robot.findAll(ComponentFixture.class, xpath)
3436
.stream()
3537
.anyMatch(ComponentFixture::isShowing));
3638
}
39+
40+
public static SharedSteps createSharedSteps() {
41+
return new SharedSteps();
42+
}
3743
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.time.Duration;
2929

3030
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
31-
import static org.junit.jupiter.api.Assertions.assertTrue;
31+
import static org.junit.jupiter.api.Assertions.assertEquals;
3232

3333
/**
3434
* FlatWelcomeFrame test
@@ -60,14 +60,14 @@ public void clearWorkspaceTest() {
6060
flatWelcomeFrame.clearExceptions();
6161
int projectsOnDisk = getNumberOfProjectsOnDisk();
6262
int projectLinks = getNumberOfProjectLinks();
63-
assertTrue(projectsOnDisk == 1, "Number of projects in the IntelliJ's project folder should be 1 but is " + projectsOnDisk + ".");
64-
assertTrue(projectLinks == 1, "Number of projects' links in the IntelliJ's 'Welcome Frame Dialog' should be 1 but is " + projectLinks + ".");
63+
assertEquals(1, projectsOnDisk, "Number of projects in the IntelliJ's project folder should be 1 but is " + projectsOnDisk + ".");
64+
assertEquals(1, projectLinks, "Number of projects' links in the IntelliJ's 'Welcome Frame Dialog' should be 1 but is " + projectLinks + ".");
6565
IdeInternalErrorUtils.clearWindowsErrorsIfTheyAppear(remoteRobot);
6666
flatWelcomeFrame.clearWorkspace();
6767
int projectCount2 = getNumberOfProjectsOnDisk();
6868
int projectLinks2 = getNumberOfProjectLinks();
69-
assertTrue(projectCount2 == 0, "Number of projects in the IntelliJ's project folder should be 0 but is " + projectCount2 + ".");
70-
assertTrue(projectLinks2 == 0, "Number of projects' links in the IntelliJ's 'Welcome Frame Dialog' should be 0 but is " + projectLinks2 + ".");
69+
assertEquals(0, projectCount2, "Number of projects in the IntelliJ's project folder should be 0 but is " + projectCount2 + ".");
70+
assertEquals(0, projectLinks2, "Number of projects' links in the IntelliJ's 'Welcome Frame Dialog' should be 0 but is " + projectLinks2 + ".");
7171
}
7272

7373
@Test

src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/CodeWithMeDialogTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void prepareProject() {
7373
@AfterAll
7474
public static void closeCurrentProject() {
7575
if (IDEA_VERSION_WITH_CWM_DIALOG_OPENED) {
76-
CreateCloseUtils.closeProject(remoteRobot);
76+
remoteRobot.find(MainIdeWindow.class, Duration.ofSeconds(10)).closeProject();
7777
}
7878
}
7979

src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/ProjectStructureDialogTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static void prepareProject() {
4444

4545
@AfterAll
4646
public static void closeProject() {
47-
CreateCloseUtils.closeProject(remoteRobot);
47+
remoteRobot.find(MainIdeWindow.class, Duration.ofSeconds(10)).closeProject();
4848
}
4949

5050
@Test

src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/TipDialogTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.util.logging.Level;
2626

2727
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
28-
import static org.junit.jupiter.api.Assertions.assertTrue;
28+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2929
import static org.junit.jupiter.api.Assertions.fail;
3030

3131
/**
@@ -69,7 +69,7 @@ public void dontShowTipsCheckBoxTest() {
6969
boolean checkboxStateBefore = tipDialog.dontShowTipsCheckBox().isSelected();
7070
tipDialog.dontShowTipsCheckBox().setValue(!checkboxStateBefore);
7171
boolean checkboxStateAfter = tipDialog.dontShowTipsCheckBox().isSelected();
72-
assertTrue(checkboxStateAfter != checkboxStateBefore,
72+
assertNotEquals(checkboxStateAfter, checkboxStateBefore,
7373
"The checkbox value should be '" + !checkboxStateBefore + "' but is '" + checkboxStateAfter + "'.");
7474
tipDialog.dontShowTipsCheckBox().setValue(checkboxStateBefore);
7575
tipDialog.close();

0 commit comments

Comments
 (0)