Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests fix #332

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ jobs:
name: linux-steplogger-logs
path: src/test-project/build/test-results/*
if: always()
- name: Archiving coverage for sonar
uses: actions/upload-artifact@v4
if: always()
with:
name: sonar-coverage
path: |
src/test-project/build/test-results/**/*.xml
src/test-project/build/jacoco/

run_on_windows:
runs-on: windows-latest
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/download-artifact@v4
with:
path: reports
pattern: -test-reports
pattern: sonar-coverage
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{github.event.workflow_run.id}}
- name: Download PrInfo
Expand All @@ -37,13 +37,16 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
mkdir build
ls reports
cp -r reports/* build/
if [ '${{github.event.workflow_run.event}}' == 'pull_request' ]; then
PR_NUMBER=$(<prInfo/PR)
BASE_REF=$(<prInfo/base_ref)
HEAD_REF=$(<prInfo/head_ref)
./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}}
./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}}
else
./gradlew build sonar
./gradlew jacocoTestReport sonar
fi
shell: bash


4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ tasks {
property("sonar.projectKey", "redhat-developer_intellij-common-ui-test-library")
property("sonar.organization", "redhat-developer")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.sources", "src")
property("sonar.junit.reportsPath", layout.buildDirectory.dir("test-results").get().asFile.absolutePath)
property("sonar.gradle.skipCompile", "true")
}
}

}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@

import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.data.RemoteComponent;
import com.intellij.remoterobot.fixtures.*;
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
import com.intellij.remoterobot.fixtures.ComponentFixture;
import com.intellij.remoterobot.fixtures.ContainerFixture;
import com.intellij.remoterobot.fixtures.DefaultXpath;
import com.intellij.remoterobot.fixtures.FixtureName;
import com.intellij.remoterobot.fixtures.HeavyWeightWindowFixture;
import com.intellij.remoterobot.fixtures.JButtonFixture;
import com.intellij.remoterobot.fixtures.JListFixture;
import com.intellij.remoterobot.fixtures.JPopupMenuFixture;
import com.intellij.remoterobot.fixtures.JTreeFixture;
import com.intellij.remoterobot.utils.UtilsKt;
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
import com.redhat.devtools.intellij.commonuitest.UITestRunner;
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.errors.IdeFatalErrorsDialog;
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.information.TipDialog;
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.project.NewProjectDialogWizard;
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.settings.SettingsDialog;
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.settings.pages.NotificationsPage;
import com.redhat.devtools.intellij.commonuitest.utils.constants.ButtonLabels;
import com.redhat.devtools.intellij.commonuitest.utils.constants.ProjectLocation;
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
import com.redhat.devtools.intellij.commonuitest.utils.project.CreateCloseUtils;
import com.redhat.devtools.intellij.commonuitest.utils.steps.SharedSteps;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -99,7 +109,7 @@ public void clickOnLink(String label) {
public void clearWorkspace() {
// Remove projects on disk
try {
String pathToDirToMakeEmpty = CreateCloseUtils.PROJECT_LOCATION;
String pathToDirToMakeEmpty = ProjectLocation.PROJECT_LOCATION;
Path path = Paths.get(pathToDirToMakeEmpty);
boolean doesProjectDirExists = Files.exists(path);
if (doesProjectDirExists) {
Expand Down Expand Up @@ -129,7 +139,6 @@ public void clearExceptions() {
find(IdeFatalErrorsDialog.class, Duration.ofSeconds(10)).clearAll();
} catch (WaitForConditionTimeoutException e) {
LOGGER.log(Level.INFO, "No fatal errors dialog found to clear.");

try {
find(IdeFatalErrorsDialog.class, Duration.ofSeconds(10)).clearAll();
} catch (Exception e2) {
Expand All @@ -153,46 +162,43 @@ public void openSettingsDialog() {
} else {
JTreeFixture jTreeFixture = remoteRobot.find(JTreeFixture.class, byXpath(XPathDefinitions.TREE));
jTreeFixture.findText("Customize").click();

if (remoteRobot.isMac()) {
resizeWelcomeWindow(remoteRobot, 900);
resizeWelcomeWindow(900);
}

remoteRobot.find(ContainerFixture.class, byXpath(XPathDefinitions.DIALOG_PANEL))
.findText("All settings" + '\u2026')
.click();
remoteRobot.find(ContainerFixture.class, byXpath(XPathDefinitions.DIALOG_PANEL)).findText("All settings" + '\u2026').click();
}
}

/**
* Resize the Welcome to IntelliJ IDEA window
*
* @param remoteRobot Valid instance of remote robot
* @param newHeight Integer of new height to use
* @param newHeight Integer of new height to use
*/
private void resizeWelcomeWindow(RemoteRobot remoteRobot, int newHeight) {
private void resizeWelcomeWindow(int newHeight) {
try {
remoteRobot.callJs(String.format("""
importClass(java.awt.Frame);
importClass(javax.swing.SwingUtilities);
var frames = Frame.getFrames();
var resized = false;
for (var i = 0; i < frames.length; i++) {
var frame = frames[i];
if (frame.isShowing() && frame.getClass().getName().contains("FlatWelcomeFrame")) {
SwingUtilities.invokeLater(function() {
frame.setSize(frame.getWidth(), %d);
frame.validate();
});
resized = true;
break;
}
importClass(java.awt.Frame);
importClass(javax.swing.SwingUtilities);
var frames = Frame.getFrames();
var resized = false;
for (var i = 0; i < frames.length; i++) {
var frame = frames[i];
if (frame.isShowing() && frame.getClass().getName().contains("FlatWelcomeFrame")) {
SwingUtilities.invokeLater(function() {
frame.setSize(frame.getWidth(), %d);
frame.validate();
});
resized = true;
break;
}
resized;
""", newHeight));
}
resized;
""", newHeight));
Thread.sleep(5000);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to resize the Welcome window: " + e.getMessage());
LOGGER.log(Level.WARNING, "Failed to resize the Welcome window: {0}", e.getMessage());
/* Clean up whatever needs to be handled before interrupting */
Thread.currentThread().interrupt();
}
}

Expand All @@ -209,7 +215,7 @@ public TipDialog openTipDialog() {
} else {
flatWelcomeFrame.findText(ButtonLabels.LEARN_INTELLIJ_IDEA_LABEL).click();
}
SharedSteps.waitForComponentByXpath(remoteRobot, 2, 1, byXpath(XPathDefinitions.TIP_DIALOG_2));
SharedSteps.createSharedSteps().waitForComponentByXpath(remoteRobot, 2, 1, byXpath(XPathDefinitions.TIP_DIALOG_2));
flatWelcomeFrame.findText(TIP_OF_THE_DAY).click();
} else if (ideaVersion <= 20202) {
clickOnLink("Get Help");
Expand Down Expand Up @@ -304,12 +310,11 @@ private void removeTopProjectFromRecentProjects() {

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

if (ideaVersion >= 20231) {
ComponentFixture removeDialog = remoteRobot.find(ComponentFixture.class, byXpath(XPathDefinitions.MY_DIALOG), Duration.ofSeconds(10));
removeDialog.findText(ButtonLabels.REMOVE_FROM_LIST_LABEL)
.click();
removeDialog.findText(ButtonLabels.REMOVE_FROM_LIST_LABEL).click();
} else if (ideaVersion >= 20203) { // Code for IntelliJ Idea 2020.3 or newer
List<JPopupMenuFixture> jPopupMenuFixtures = jPopupMenus(JPopupMenuFixture.Companion.byType());
if (!jPopupMenuFixtures.isEmpty()) {
Expand All @@ -323,4 +328,17 @@ private void removeTopProjectFromRecentProjects() {
}
}
}

/**
* Open 'New Project' dialog from 'Welcome to IntelliJ IDEA' dialog
*
* @param remoteRobot reference to the RemoteRobot instance
* @return NewProjectDialogWizard fixture
*/
public NewProjectDialogWizard openNewProjectDialogFromWelcomeDialog(RemoteRobot remoteRobot) {
FlatWelcomeFrame flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10));
flatWelcomeFrame.switchToProjectsPage();
flatWelcomeFrame.createNewProject();
return remoteRobot.find(NewProjectDialogWizard.class, Duration.ofSeconds(10));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.intellij.remoterobot.data.RemoteComponent;
import com.intellij.remoterobot.fixtures.ComboBoxFixture;
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
import com.intellij.remoterobot.fixtures.ContainerFixture;
import com.intellij.remoterobot.fixtures.DefaultXpath;
import com.intellij.remoterobot.fixtures.FixtureName;
import com.intellij.remoterobot.fixtures.HeavyWeightWindowFixture;
Expand All @@ -25,12 +26,15 @@
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
import com.redhat.devtools.intellij.commonuitest.UITestRunner;
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
import com.redhat.devtools.intellij.commonuitest.utils.screenshot.ScreenshotUtils;
import com.redhat.devtools.intellij.commonuitest.utils.texttranformation.TextUtils;
import org.jetbrains.annotations.NotNull;

import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.Map;

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

ComboBoxFixture projectJdkComboBox = getProjectJdkComboBox();
String currentlySelectedProjectSdk = TextUtils.listOfRemoteTextToString(projectJdkComboBox.findAllText());
if (currentlySelectedProjectSdk.contains(targetSdkName)) {
if (currentlySelectedProjectSdk.startsWith(targetSdkName)) {
return;
}

Expand All @@ -144,6 +148,7 @@ public void setProjectSdkIfAvailable(String targetSdkName) {
try {
waitFor(Duration.ofSeconds(10), Duration.ofMillis(250), "HeavyWeightWindow still visible.", this::noHeavyWeightWindowVisible);
} catch (WaitForConditionTimeoutException e) {
ScreenshotUtils.takeScreenshot(remoteRobot, "HeavyWeightWindow still visible." + targetSdkName);
popupOpenedPermanently = true;
}
if (!popupOpenedPermanently) {
Expand All @@ -154,8 +159,26 @@ public void setProjectSdkIfAvailable(String targetSdkName) {
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);
JPopupMenuFixture projectSdkList = parentFixture.jPopupMenus(byXpath(XPathDefinitions.HEAVY_WEIGHT_WINDOW)).get(0); // issue https://github.com/JetBrains/intellij-ui-test-robot/issues/104
List<String> sdkItems = projectSdkList.jList().collectItems();
Optional<String> item = sdkItems.stream().filter(s -> s.startsWith(targetSdkName)).findFirst();
item.ifPresent(s -> projectSdkList.jList().clickItem(s, true));
Map<String, String> foundItems = new HashMap<>();
sdkItems.forEach(item ->
Arrays.stream(item.split(" ")).filter(s ->
s.startsWith(targetSdkName)).findFirst().ifPresent(s -> foundItems.put(s, item))
);
if (!foundItems.isEmpty()) {
String label = foundItems.values().stream().findFirst().get();
projectSdkList.jList().clickItem(label, true);
System.out.println(remoteRobot.findAll(CommonContainerFixture.class));
System.out.println(remoteRobot.findAll(ContainerFixture.class));
// wait for 'resolving JDK' progressmonitor to end
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} else {
ScreenshotUtils.takeScreenshot(remoteRobot, "No SDK found starting with " + targetSdkName);
}

});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,26 @@ public MainIdeWindow(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent
*/
public void maximizeIdeWindow() {
if (remoteRobot.isWin()) {
runJs("const width = component.getWidth();\n" +
"const height = component.getHeight();\n" +
"const horizontal_offset = width-72;\n" +
"robot.click(component, new Point(horizontal_offset, 14), MouseButton.LEFT_BUTTON, 1);\n" +
"const width_after = component.getWidth();\n" +
"const height_after = component.getHeight();\n" +
"const horizontal_offset_after = width_after-72;\n" +
"if (width > width_after || height > height_after) { robot.click(component, new Point(horizontal_offset_after, 14), MouseButton.LEFT_BUTTON, 1); }");
runJs("""
const width = component.getWidth();
const height = component.getHeight();
const horizontal_offset = width-72;
robot.click(component, new Point(horizontal_offset, 14), MouseButton.LEFT_BUTTON, 1);
const width_after = component.getWidth();
const height_after = component.getHeight();
const horizontal_offset_after = width_after-72;
if (width > width_after || height > height_after) { robot.click(component, new Point(horizontal_offset_after, 14), MouseButton.LEFT_BUTTON, 1); }""");

} else {
runJs("const width = component.getWidth();\n" +
"const height = component.getHeight();\n" +
"const horizontal_offset = width/2;\n" +
"robot.click(component, new Point(horizontal_offset, 10), MouseButton.LEFT_BUTTON, 2);\n" +
"const width_after = component.getWidth();\n" +
"const height_after = component.getHeight();\n" +
"const horizontal_offset_after = width_after/2;\n" +
"if (width > width_after || height > height_after) { robot.click(component, new Point(horizontal_offset_after, 10), MouseButton.LEFT_BUTTON, 2); }");
runJs("""
const width = component.getWidth();
const height = component.getHeight();
const horizontal_offset = width/2;
robot.click(component, new Point(horizontal_offset, 10), MouseButton.LEFT_BUTTON, 2);
const width_after = component.getWidth();
const height_after = component.getHeight();
const horizontal_offset_after = width_after/2;
if (width > width_after || height > height_after) { robot.click(component, new Point(horizontal_offset_after, 10), MouseButton.LEFT_BUTTON, 2); }""");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
import com.intellij.remoterobot.fixtures.DefaultXpath;
import com.intellij.remoterobot.fixtures.FixtureName;
import com.intellij.remoterobot.fixtures.JButtonFixture;
import com.redhat.devtools.intellij.commonuitest.UITestRunner;
import com.redhat.devtools.intellij.commonuitest.utils.constants.ButtonLabels;
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
import org.jetbrains.annotations.NotNull;

import java.time.Duration;

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

@DefaultXpath(by = "ToolWindowRightToolbar type", xpath = "//div[@class='ToolWindowRightToolbar']")
@FixtureName(name = "Tool Window Right Toolbar")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.redhat.devtools.intellij.commonuitest.utils.constants;

import java.io.File;
import java.util.Optional;

public final class ProjectLocation {
// For more info on testProjectLocation please check README
public static final String PROJECT_LOCATION = Optional.ofNullable(System.getProperty("testProjectLocation"))
.filter(s -> !s.isEmpty())
.orElseGet(() -> System.getProperty("user.home") + File.separator + "IdeaProjects" + File.separator + "intellij-ui-test-projects");

private ProjectLocation() {}

}
Loading
Loading