Skip to content

Commit 4bb5c14

Browse files
authored
Integration tests fix (#332)
* chore: fix integration tests --------- Signed-off-by: Stephane Bouchet <[email protected]>
1 parent 3e32f0f commit 4bb5c14

File tree

24 files changed

+218
-148
lines changed

24 files changed

+218
-148
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ jobs:
8888
name: linux-steplogger-logs
8989
path: src/test-project/build/test-results/*
9090
if: always()
91+
- name: Archiving coverage for sonar
92+
uses: actions/upload-artifact@v4
93+
if: always()
94+
with:
95+
name: sonar-coverage
96+
path: |
97+
src/test-project/build/test-results/**/*.xml
98+
src/test-project/build/jacoco/
9199
92100
run_on_windows:
93101
runs-on: windows-latest

.github/workflows/sonar.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: actions/download-artifact@v4
2424
with:
2525
path: reports
26-
pattern: -test-reports
26+
pattern: sonar-coverage
2727
github-token: ${{ secrets.GITHUB_TOKEN }}
2828
run-id: ${{github.event.workflow_run.id}}
2929
- name: Download PrInfo
@@ -37,13 +37,16 @@ jobs:
3737
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3838
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3939
run: |
40+
mkdir build
41+
ls reports
42+
cp -r reports/* build/
4043
if [ '${{github.event.workflow_run.event}}' == 'pull_request' ]; then
4144
PR_NUMBER=$(<prInfo/PR)
4245
BASE_REF=$(<prInfo/base_ref)
4346
HEAD_REF=$(<prInfo/head_ref)
44-
./gradlew build sonar -Dsonar.pullrequest.base=$BASE_REF -Dsonar.pullrequest.branch=$HEAD_REF -Dsonar.pullrequest.key=$PR_NUMBER -Dsonar.pullrequest.provider=GitHub -Dsonar.pullrequest.github.repository=${{github.repository}}
47+
./gradlew jacocoTestReport sonar -Dsonar.pullrequest.base=$BASE_REF -Dsonar.pullrequest.branch=$HEAD_REF -Dsonar.pullrequest.key=$PR_NUMBER -Dsonar.pullrequest.provider=GitHub -Dsonar.pullrequest.github.repository=${{github.repository}}
4548
else
46-
./gradlew build sonar
49+
./gradlew jacocoTestReport sonar
4750
fi
4851
shell: bash
49-
52+

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ tasks {
4545
property("sonar.projectKey", "redhat-developer_intellij-common-ui-test-library")
4646
property("sonar.organization", "redhat-developer")
4747
property("sonar.host.url", "https://sonarcloud.io")
48-
property("sonar.sources", "src")
48+
property("sonar.junit.reportsPath", layout.buildDirectory.dir("test-results").get().asFile.absolutePath)
49+
property("sonar.gradle.skipCompile", "true")
4950
}
5051
}
51-
5252
}
5353

5454
publishing {

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

Lines changed: 37 additions & 33 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;
@@ -21,8 +30,8 @@
2130
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.settings.SettingsDialog;
2231
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.settings.pages.NotificationsPage;
2332
import com.redhat.devtools.intellij.commonuitest.utils.constants.ButtonLabels;
33+
import com.redhat.devtools.intellij.commonuitest.utils.constants.ProjectLocation;
2434
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
25-
import com.redhat.devtools.intellij.commonuitest.utils.project.CreateCloseUtils;
2635
import com.redhat.devtools.intellij.commonuitest.utils.steps.SharedSteps;
2736
import org.jetbrains.annotations.NotNull;
2837

@@ -99,7 +108,7 @@ public void clickOnLink(String label) {
99108
public void clearWorkspace() {
100109
// Remove projects on disk
101110
try {
102-
String pathToDirToMakeEmpty = CreateCloseUtils.PROJECT_LOCATION;
111+
String pathToDirToMakeEmpty = ProjectLocation.PROJECT_LOCATION;
103112
Path path = Paths.get(pathToDirToMakeEmpty);
104113
boolean doesProjectDirExists = Files.exists(path);
105114
if (doesProjectDirExists) {
@@ -129,7 +138,6 @@ public void clearExceptions() {
129138
find(IdeFatalErrorsDialog.class, Duration.ofSeconds(10)).clearAll();
130139
} catch (WaitForConditionTimeoutException e) {
131140
LOGGER.log(Level.INFO, "No fatal errors dialog found to clear.");
132-
133141
try {
134142
find(IdeFatalErrorsDialog.class, Duration.ofSeconds(10)).clearAll();
135143
} catch (Exception e2) {
@@ -153,46 +161,43 @@ public void openSettingsDialog() {
153161
} else {
154162
JTreeFixture jTreeFixture = remoteRobot.find(JTreeFixture.class, byXpath(XPathDefinitions.TREE));
155163
jTreeFixture.findText("Customize").click();
156-
157164
if (remoteRobot.isMac()) {
158-
resizeWelcomeWindow(remoteRobot, 900);
165+
resizeWelcomeWindow(900);
159166
}
160-
161-
remoteRobot.find(ContainerFixture.class, byXpath(XPathDefinitions.DIALOG_PANEL))
162-
.findText("All settings" + '\u2026')
163-
.click();
167+
remoteRobot.find(ContainerFixture.class, byXpath(XPathDefinitions.DIALOG_PANEL)).findText("All settings" + '\u2026').click();
164168
}
165169
}
166170

167171
/**
168172
* Resize the Welcome to IntelliJ IDEA window
169173
*
170-
* @param remoteRobot Valid instance of remote robot
171-
* @param newHeight Integer of new height to use
174+
* @param newHeight Integer of new height to use
172175
*/
173-
private void resizeWelcomeWindow(RemoteRobot remoteRobot, int newHeight) {
176+
private void resizeWelcomeWindow(int newHeight) {
174177
try {
175178
remoteRobot.callJs(String.format("""
176-
importClass(java.awt.Frame);
177-
importClass(javax.swing.SwingUtilities);
178-
var frames = Frame.getFrames();
179-
var resized = false;
180-
for (var i = 0; i < frames.length; i++) {
181-
var frame = frames[i];
182-
if (frame.isShowing() && frame.getClass().getName().contains("FlatWelcomeFrame")) {
183-
SwingUtilities.invokeLater(function() {
184-
frame.setSize(frame.getWidth(), %d);
185-
frame.validate();
186-
});
187-
resized = true;
188-
break;
189-
}
179+
importClass(java.awt.Frame);
180+
importClass(javax.swing.SwingUtilities);
181+
var frames = Frame.getFrames();
182+
var resized = false;
183+
for (var i = 0; i < frames.length; i++) {
184+
var frame = frames[i];
185+
if (frame.isShowing() && frame.getClass().getName().contains("FlatWelcomeFrame")) {
186+
SwingUtilities.invokeLater(function() {
187+
frame.setSize(frame.getWidth(), %d);
188+
frame.validate();
189+
});
190+
resized = true;
191+
break;
190192
}
191-
resized;
192-
""", newHeight));
193+
}
194+
resized;
195+
""", newHeight));
193196
Thread.sleep(5000);
194197
} catch (Exception e) {
195-
LOGGER.log(Level.WARNING, "Failed to resize the Welcome window: " + e.getMessage());
198+
LOGGER.log(Level.WARNING, "Failed to resize the Welcome window: {0}", e.getMessage());
199+
/* Clean up whatever needs to be handled before interrupting */
200+
Thread.currentThread().interrupt();
196201
}
197202
}
198203

@@ -304,12 +309,11 @@ private void removeTopProjectFromRecentProjects() {
304309

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

309314
if (ideaVersion >= 20231) {
310315
ComponentFixture removeDialog = remoteRobot.find(ComponentFixture.class, byXpath(XPathDefinitions.MY_DIALOG), Duration.ofSeconds(10));
311-
removeDialog.findText(ButtonLabels.REMOVE_FROM_LIST_LABEL)
312-
.click();
316+
removeDialog.findText(ButtonLabels.REMOVE_FROM_LIST_LABEL).click();
313317
} else if (ideaVersion >= 20203) { // Code for IntelliJ Idea 2020.3 or newer
314318
List<JPopupMenuFixture> jPopupMenuFixtures = jPopupMenus(JPopupMenuFixture.Companion.byType());
315319
if (!jPopupMenuFixtures.isEmpty()) {

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.intellij.remoterobot.data.RemoteComponent;
1515
import com.intellij.remoterobot.fixtures.ComboBoxFixture;
1616
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
17+
import com.intellij.remoterobot.fixtures.ContainerFixture;
1718
import com.intellij.remoterobot.fixtures.DefaultXpath;
1819
import com.intellij.remoterobot.fixtures.FixtureName;
1920
import com.intellij.remoterobot.fixtures.HeavyWeightWindowFixture;
@@ -25,12 +26,15 @@
2526
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
2627
import com.redhat.devtools.intellij.commonuitest.UITestRunner;
2728
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
29+
import com.redhat.devtools.intellij.commonuitest.utils.screenshot.ScreenshotUtils;
2830
import com.redhat.devtools.intellij.commonuitest.utils.texttranformation.TextUtils;
2931
import org.jetbrains.annotations.NotNull;
3032

3133
import java.time.Duration;
34+
import java.util.Arrays;
35+
import java.util.HashMap;
3236
import java.util.List;
33-
import java.util.Optional;
37+
import java.util.Map;
3438

3539
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
3640
import static com.intellij.remoterobot.stepsProcessing.StepWorkerKt.step;
@@ -134,7 +138,7 @@ public void setProjectSdkIfAvailable(String targetSdkName) {
134138

135139
ComboBoxFixture projectJdkComboBox = getProjectJdkComboBox();
136140
String currentlySelectedProjectSdk = TextUtils.listOfRemoteTextToString(projectJdkComboBox.findAllText());
137-
if (currentlySelectedProjectSdk.contains(targetSdkName)) {
141+
if (currentlySelectedProjectSdk.startsWith(targetSdkName)) {
138142
return;
139143
}
140144

@@ -154,8 +158,24 @@ public void setProjectSdkIfAvailable(String targetSdkName) {
154158
CommonContainerFixture parentFixture = waitFor(Duration.ofSeconds(20), Duration.ofSeconds(2), "Wait for the 'Project SDK' list to finish loading all items.", "The project JDK list did not load all items in 20 seconds.", this::didProjectSdkListLoadAllItems);
155159
JPopupMenuFixture projectSdkList = parentFixture.jPopupMenus(byXpath(XPathDefinitions.HEAVY_WEIGHT_WINDOW)).get(0); // issue https://github.com/JetBrains/intellij-ui-test-robot/issues/104
156160
List<String> sdkItems = projectSdkList.jList().collectItems();
157-
Optional<String> item = sdkItems.stream().filter(s -> s.startsWith(targetSdkName)).findFirst();
158-
item.ifPresent(s -> projectSdkList.jList().clickItem(s, true));
161+
Map<String, String> foundItems = new HashMap<>();
162+
sdkItems.forEach(item ->
163+
Arrays.stream(item.split(" ")).filter(s ->
164+
s.startsWith(targetSdkName)).findFirst().ifPresent(s -> foundItems.put(s, item))
165+
);
166+
if (!foundItems.isEmpty()) {
167+
String label = foundItems.values().stream().findFirst().get();
168+
projectSdkList.jList().clickItem(label, true);
169+
// wait for 'resolving JDK' progressmonitor to end
170+
try {
171+
Thread.sleep(5000);
172+
} catch (InterruptedException e) {
173+
throw new RuntimeException(e);
174+
}
175+
} else {
176+
ScreenshotUtils.takeScreenshot(remoteRobot, "No SDK found starting with " + targetSdkName);
177+
}
178+
159179
});
160180
}
161181

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

Lines changed: 23 additions & 20 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

@@ -88,14 +91,14 @@ public void closeProject() {
8891
* @param cmdToInvoke String representation of command which will be executed using the Search Everywhere popup
8992
*/
9093
public void invokeCmdUsingSearchEverywherePopup(String cmdToInvoke) {
91-
SearchEverywherePopup searchEverywherePopup = openSearchEverywherePopup("All");
94+
SearchEverywherePopup searchEverywherePopup = openSearchEverywherePopup();
9295
searchEverywherePopup.invokeCmd(cmdToInvoke);
9396
}
9497

95-
private SearchEverywherePopup openSearchEverywherePopup(String tab) {
98+
private SearchEverywherePopup openSearchEverywherePopup() {
9699
try {
97100
SearchEverywherePopup searchEverywherePopup = find(SearchEverywherePopup.class, Duration.ofSeconds(10));
98-
searchEverywherePopup.activateTab(tab);
101+
searchEverywherePopup.activateTab("All");
99102
return searchEverywherePopup;
100103
} catch (WaitForConditionTimeoutException e) {
101104
Keyboard keyboard = new Keyboard(remoteRobot);
@@ -105,7 +108,7 @@ private SearchEverywherePopup openSearchEverywherePopup(String tab) {
105108
keyboard.hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_N);
106109
}
107110
SearchEverywherePopup searchEverywherePopup = find(SearchEverywherePopup.class, Duration.ofSeconds(10));
108-
searchEverywherePopup.activateTab(tab);
111+
searchEverywherePopup.activateTab("All");
109112
return searchEverywherePopup;
110113
}
111114
}

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")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.redhat.devtools.intellij.commonuitest.utils.constants;
2+
3+
import java.io.File;
4+
import java.util.Optional;
5+
6+
public final class ProjectLocation {
7+
// For more info on testProjectLocation please check README
8+
public static final String PROJECT_LOCATION = Optional.ofNullable(System.getProperty("testProjectLocation"))
9+
.filter(s -> !s.isEmpty())
10+
.orElseGet(() -> System.getProperty("user.home") + File.separator + "IdeaProjects" + File.separator + "intellij-ui-test-projects");
11+
12+
private ProjectLocation() {}
13+
14+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public class XPathDefinitions {
3131
public static final String WINDOWS_MAIN_MENU_2020_3_TO_2022_1 = "//div[@class='MenuFrameHeader']";
3232
public static final String WINDOWS_MAIN_MENU_2020_2_AND_OLDER = "//div[@class='CustomHeaderMenuBar']";
3333
public static final String IDE_STATUS_BAR = "//div[@class='IdeStatusBarImpl']";
34+
@Language("XPath")
3435
public static final String INLINE_PROGRESS_PANEL = "//div[@class='InlineProgressPanel']";
36+
@Language("XPath")
3537
public static final String ENGRAVED_LABEL = "//div[@class='EngravedLabel']";
3638
public static final String FLAT_WELCOME_FRAME = "//div[@class='FlatWelcomeFrame']";
3739
public static final String NEW_PROJECT_DIALOG_WIZARD = "//div[@accessiblename='New Project' and @class='MyDialog']";
@@ -78,6 +80,7 @@ public class XPathDefinitions {
7880
public static final String MY_ICON_EXPAND_ALL = "//div[contains(@myvisibleactions, 'View),')]//div[@myicon='expandall.svg']";
7981
public static final String MY_ICON_EXPAND_ALL_2024_2 = "//div[@myicon='expandAll.svg']";
8082
public static final String MY_ICON_EXPAND_ALL_IDE = "//div[contains(@myvisibleactions, 'IDE')]//div[@myicon='expandall.svg']";
83+
@Language("XPath")
8184
public static final String MY_ICON_LOCATE_SVG = "//div[@myicon='locate.svg']";
8285
public static final String MY_ICON_REFRESH = "//div[@myicon='refresh.svg']";
8386
public static final String CONTENT_COMBO_LABEL = "//div[@class='ContentComboLabel']";

0 commit comments

Comments
 (0)