diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff3c6a9e..03482426 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 98eb38ff..6ca223d6 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -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 @@ -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=$(= 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 jPopupMenuFixtures = jPopupMenus(JPopupMenuFixture.Companion.byType()); if (!jPopupMenuFixtures.isEmpty()) { diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/project/pages/NewProjectFirstPage.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/project/pages/NewProjectFirstPage.java index 53f66c7a..3320f110 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/project/pages/NewProjectFirstPage.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/project/pages/NewProjectFirstPage.java @@ -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; @@ -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; @@ -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; } @@ -154,8 +158,24 @@ 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 sdkItems = projectSdkList.jList().collectItems(); - Optional item = sdkItems.stream().filter(s -> s.startsWith(targetSdkName)).findFirst(); - item.ifPresent(s -> projectSdkList.jList().clickItem(s, true)); + Map 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); + // 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); + } + }); } diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/MainIdeWindow.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/MainIdeWindow.java index 2d916eea..6762f2ac 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/MainIdeWindow.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/MainIdeWindow.java @@ -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); }"""); } } @@ -88,14 +91,14 @@ public void closeProject() { * @param cmdToInvoke String representation of command which will be executed using the Search Everywhere popup */ public void invokeCmdUsingSearchEverywherePopup(String cmdToInvoke) { - SearchEverywherePopup searchEverywherePopup = openSearchEverywherePopup("All"); + SearchEverywherePopup searchEverywherePopup = openSearchEverywherePopup(); searchEverywherePopup.invokeCmd(cmdToInvoke); } - private SearchEverywherePopup openSearchEverywherePopup(String tab) { + private SearchEverywherePopup openSearchEverywherePopup() { try { SearchEverywherePopup searchEverywherePopup = find(SearchEverywherePopup.class, Duration.ofSeconds(10)); - searchEverywherePopup.activateTab(tab); + searchEverywherePopup.activateTab("All"); return searchEverywherePopup; } catch (WaitForConditionTimeoutException e) { Keyboard keyboard = new Keyboard(remoteRobot); @@ -105,7 +108,7 @@ private SearchEverywherePopup openSearchEverywherePopup(String tab) { keyboard.hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_N); } SearchEverywherePopup searchEverywherePopup = find(SearchEverywherePopup.class, Duration.ofSeconds(10)); - searchEverywherePopup.activateTab(tab); + searchEverywherePopup.activateTab("All"); return searchEverywherePopup; } } diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/toolwindowspane/ToolWindowRightToolbar.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/toolwindowspane/ToolWindowRightToolbar.java index 3a866d28..7dd93edf 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/toolwindowspane/ToolWindowRightToolbar.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/toolwindowspane/ToolWindowRightToolbar.java @@ -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") diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/ProjectLocation.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/ProjectLocation.java new file mode 100644 index 00000000..ad704c48 --- /dev/null +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/ProjectLocation.java @@ -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() {} + +} diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/XPathDefinitions.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/XPathDefinitions.java index 39fc8329..ac4da5e3 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/XPathDefinitions.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/XPathDefinitions.java @@ -31,7 +31,9 @@ public class XPathDefinitions { public static final String WINDOWS_MAIN_MENU_2020_3_TO_2022_1 = "//div[@class='MenuFrameHeader']"; public static final String WINDOWS_MAIN_MENU_2020_2_AND_OLDER = "//div[@class='CustomHeaderMenuBar']"; public static final String IDE_STATUS_BAR = "//div[@class='IdeStatusBarImpl']"; + @Language("XPath") public static final String INLINE_PROGRESS_PANEL = "//div[@class='InlineProgressPanel']"; + @Language("XPath") public static final String ENGRAVED_LABEL = "//div[@class='EngravedLabel']"; public static final String FLAT_WELCOME_FRAME = "//div[@class='FlatWelcomeFrame']"; public static final String NEW_PROJECT_DIALOG_WIZARD = "//div[@accessiblename='New Project' and @class='MyDialog']"; @@ -78,6 +80,7 @@ public class XPathDefinitions { public static final String MY_ICON_EXPAND_ALL = "//div[contains(@myvisibleactions, 'View),')]//div[@myicon='expandall.svg']"; public static final String MY_ICON_EXPAND_ALL_2024_2 = "//div[@myicon='expandAll.svg']"; public static final String MY_ICON_EXPAND_ALL_IDE = "//div[contains(@myvisibleactions, 'IDE')]//div[@myicon='expandall.svg']"; + @Language("XPath") public static final String MY_ICON_LOCATE_SVG = "//div[@myicon='locate.svg']"; public static final String MY_ICON_REFRESH = "//div[@myicon='refresh.svg']"; public static final String CONTENT_COMBO_LABEL = "//div[@class='ContentComboLabel']"; diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/project/CreateCloseUtils.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/project/CreateCloseUtils.java index e94ed354..ed99fcad 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/project/CreateCloseUtils.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/project/CreateCloseUtils.java @@ -23,12 +23,11 @@ import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.project.pages.NewProjectFirstPage; import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.MainIdeWindow; import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.idestatusbar.IdeStatusBar; +import com.redhat.devtools.intellij.commonuitest.utils.constants.ProjectLocation; import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions; -import java.io.File; import java.time.Duration; import java.util.List; -import java.util.Optional; import static com.intellij.remoterobot.search.locators.Locators.byXpath; import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitFor; @@ -39,9 +38,6 @@ * @author zcervink@redhat.com */ public class CreateCloseUtils { - public static final String PROJECT_LOCATION = Optional.ofNullable(System.getProperty("testProjectLocation")) // For more info on testProjectLocation please check README - .filter(s -> !s.isEmpty()) - .orElseGet(() -> System.getProperty("user.home") + File.separator + "IdeaProjects" + File.separator + "intellij-ui-test-projects"); /** * Create new project with given project name according to given project type @@ -61,10 +57,12 @@ public static void createNewProject(RemoteRobot remoteRobot, String projectName, case PLAIN_JAVA: newProjectFirstPage.setBuildSystem("IntelliJ"); break; - case MAVEN: - case GRADLE: + case MAVEN, GRADLE: newProjectFirstPage.setBuildSystem(newProjectType.toString()); break; + case EMPTY_PROJECT: + default: + throw new IllegalStateException("Unexpected value: " + newProjectType); } } else { newProjectFirstPage.selectNewProjectType(newProjectType.toString()); @@ -76,7 +74,7 @@ public static void createNewProject(RemoteRobot remoteRobot, String projectName, newProjectFirstPage.getProjectNameTextField().click(); // Click to gain focus on newProjectFirstPage newProjectFirstPage.setProjectName(projectName); - newProjectFirstPage.setProjectLocation(PROJECT_LOCATION); + newProjectFirstPage.setProjectLocation(ProjectLocation.PROJECT_LOCATION); } else { newProjectDialogWizard.next(); // Plain java project has more pages in the 'New project' dialog @@ -106,7 +104,7 @@ public static void createEmptyProject(RemoteRobot remoteRobot, String projectNam ensureEmptyProjectPageIsOpened(newProjectFirstPage, remoteRobot); newProjectFirstPage.setProjectName(projectName); - newProjectFirstPage.setProjectLocation(PROJECT_LOCATION); + newProjectFirstPage.setProjectLocation(ProjectLocation.PROJECT_LOCATION); newProjectDialogWizard.finish(); waitAfterOpeningProject(remoteRobot); @@ -171,15 +169,12 @@ public static void openProjectFromWelcomeDialog(RemoteRobot remoteRobot, String * @return final page instance */ public static AbstractNewProjectFinalPage getFinalPage(NewProjectDialogWizard newProjectDialogWizard, NewProjectType newProjectType) { - switch (newProjectType) { - case PLAIN_JAVA: - return newProjectDialogWizard.find(JavaNewProjectFinalPage.class, Duration.ofSeconds(10)); - case MAVEN: - case GRADLE: - return newProjectDialogWizard.find(MavenGradleNewProjectFinalPage.class, Duration.ofSeconds(10)); - default: - throw new UITestException("Unsupported project type."); - } + return switch (newProjectType) { + case PLAIN_JAVA -> newProjectDialogWizard.find(JavaNewProjectFinalPage.class, Duration.ofSeconds(10)); + case MAVEN, GRADLE -> + newProjectDialogWizard.find(MavenGradleNewProjectFinalPage.class, Duration.ofSeconds(10)); + default -> throw new UITestException("Unsupported project type."); + }; } /** diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/screenshot/ScreenshotUtils.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/screenshot/ScreenshotUtils.java index 0e8891a5..66f14d60 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/screenshot/ScreenshotUtils.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/screenshot/ScreenshotUtils.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -48,12 +49,13 @@ private ScreenshotUtils() { public static File takeScreenshot(RemoteRobot remoteRobot, String comment) { try { BufferedImage screenshotBufferedImage = remoteRobot.getScreenshot(); - boolean doesScreenshotDirExists = Files.exists(Paths.get(SCREENSHOT_LOCATION)); + Path path = Paths.get(SCREENSHOT_LOCATION); + boolean doesScreenshotDirExists = Files.exists(path); if (!doesScreenshotDirExists) { - Files.createDirectory(Paths.get(SCREENSHOT_LOCATION)); + Files.createDirectory(path); } - String screenshotFilename = getTimeNow("yyyy_MM_dd_HH_mm_ss"); - String screenshotComment = comment == null || comment.equals("") ? "" : "_" + comment; + String screenshotFilename = getTimeNow(); + String screenshotComment = comment == null || comment.isEmpty() ? "" : "_" + comment.replace(" ", "_"); String screenshotPathname = SCREENSHOT_LOCATION + screenshotFilename + screenshotComment + "." + FILETYPE; File screenshotFile = new File(screenshotPathname); ImageIO.write(screenshotBufferedImage, FILETYPE, screenshotFile); @@ -74,8 +76,8 @@ public static File takeScreenshot(RemoteRobot remoteRobot) { return takeScreenshot(remoteRobot, ""); } - private static String getTimeNow(String timeFormat) { - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(timeFormat); + private static String getTimeNow() { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss"); LocalDateTime localTimeNow = LocalDateTime.now(); return dateTimeFormatter.format(localTimeNow); } diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/steps/SharedSteps.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/steps/SharedSteps.java index 8307fb24..f2259673 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/steps/SharedSteps.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/steps/SharedSteps.java @@ -21,6 +21,8 @@ * These methods facilitate common automation steps that can be reused in various test scenarios. */ public class SharedSteps { + private SharedSteps() {} + /** * Waits for a component to be visible within the IDE's UI hierarchy based on the provided XPath locator. * diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/testextension/ScreenshotAfterTestFailExtension.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/testextension/ScreenshotAfterTestFailExtension.java index ecbba427..2ed1b7cf 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/testextension/ScreenshotAfterTestFailExtension.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/testextension/ScreenshotAfterTestFailExtension.java @@ -36,13 +36,8 @@ * @author zcervink@redhat.com */ public class ScreenshotAfterTestFailExtension implements AfterTestExecutionCallback { - private final RemoteRobot remoteRobot; protected static final Logger LOGGER = Logger.getLogger(ScreenshotAfterTestFailExtension.class.getName()); - public ScreenshotAfterTestFailExtension() { - this.remoteRobot = UITestRunner.getRemoteRobot(); - } - /** * Take screenshot right after a test has failed and perform a cleanup to ensure no dialog or window is opened * @@ -50,22 +45,23 @@ public ScreenshotAfterTestFailExtension() { */ @Override public void afterTestExecution(ExtensionContext extensionContext) { - if (remoteRobot == null) { - LOGGER.log(Level.SEVERE, "Can take a screenshot, remoteRobot is null!"); - return; - } + RemoteRobot remoteRobot = UITestRunner.getRemoteRobot(); boolean testFailed = extensionContext.getExecutionException().isPresent(); if (testFailed) { - step("Take a screenshot after a test has failed", () -> - ScreenshotUtils.takeScreenshot(remoteRobot) + if (remoteRobot == null) { + LOGGER.log(Level.SEVERE, "Can't take a screenshot, remoteRobot is null!"); + return; + } + step("Take a screenshot after a test has failed", + () -> ScreenshotUtils.takeScreenshot(remoteRobot) ); step("Return to the 'Welcome Frame' dialog", - this::cleanAfterTestFail + () -> cleanAfterTestFail(remoteRobot) ); } } - private void cleanAfterTestFail() { + private void cleanAfterTestFail(RemoteRobot remoteRobot) { // New Project Dialog is visible -> close it try { NewProjectDialogWizard newProjectDialogWizard = remoteRobot.find(NewProjectDialogWizard.class, Duration.ofSeconds(10)); diff --git a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/texttranformation/TextUtils.java b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/texttranformation/TextUtils.java index 9e22568f..983d17b5 100644 --- a/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/texttranformation/TextUtils.java +++ b/src/main/java/com/redhat/devtools/intellij/commonuitest/utils/texttranformation/TextUtils.java @@ -33,11 +33,9 @@ private TextUtils() { * @return String containing a concatenation of all the labels in the 'data' List */ public static String listOfRemoteTextToString(List data) { - List listOfStrings = data + return data .stream() .map(RemoteText::getText) - .collect(Collectors.toList()); - - return String.join("", listOfStrings); + .collect(Collectors.joining(" ")); } } \ No newline at end of file diff --git a/src/test-project/build.gradle.kts b/src/test-project/build.gradle.kts index 2ee3afea..dea631ca 100644 --- a/src/test-project/build.gradle.kts +++ b/src/test-project/build.gradle.kts @@ -2,7 +2,8 @@ import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType plugins { id("java") - id("org.jetbrains.intellij.platform") version ("2.0.1") + id("jacoco") + id("org.jetbrains.intellij.platform") version ("2.2.1") } group = "com.redhat.devtools.intellij" @@ -25,12 +26,11 @@ repositories { dependencies { intellijPlatform { create(IntelliJPlatformType.IntellijIdeaCommunity, platformVersion) - instrumentationTools() } testImplementation("com.redhat.devtools.intellij:intellij-common-ui-test-library") - testImplementation("org.junit.platform:junit-platform-launcher:1.8.0") - testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0") + testImplementation("org.junit.platform:junit-platform-launcher:1.10.3") + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.3") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.3") } tasks { @@ -43,6 +43,25 @@ tasks { from("idea_license_token/idea.key") into("build/idea-sandbox/config-uiTest") } + + withType { + configure { + isIncludeNoLocationClasses = true + excludes = listOf("jdk.internal.*") + } + } + + jacocoTestReport { + executionData.setFrom(fileTree(layout.buildDirectory).include("/jacoco/*.exec")) + classDirectories.setFrom(instrumentCode) + reports { + xml.required = true + } + } + + jacocoTestCoverageVerification { + classDirectories.setFrom(instrumentCode) + } } val integrationUITestUltimate by intellijPlatformTesting.testIde.registering { diff --git a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/FlatWelcomeFrameTest.java b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/FlatWelcomeFrameTest.java index 2c09429b..e6d3e837 100644 --- a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/FlatWelcomeFrameTest.java +++ b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/FlatWelcomeFrameTest.java @@ -16,9 +16,9 @@ import com.redhat.devtools.intellij.commonuitest.LibraryTestBase; import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.FlatWelcomeFrame; import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.project.NewProjectDialogWizard; +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.internalerror.IdeInternalErrorUtils; -import com.redhat.devtools.intellij.commonuitest.utils.project.CreateCloseUtils; import org.apache.commons.io.filefilter.FileFilterUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -28,7 +28,7 @@ import java.time.Duration; import static com.intellij.remoterobot.search.locators.Locators.byXpath; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * FlatWelcomeFrame test @@ -60,14 +60,14 @@ public void clearWorkspaceTest() { flatWelcomeFrame.clearExceptions(); int projectsOnDisk = getNumberOfProjectsOnDisk(); int projectLinks = getNumberOfProjectLinks(); - assertTrue(projectsOnDisk == 1, "Number of projects in the IntelliJ's project folder should be 1 but is " + projectsOnDisk + "."); - assertTrue(projectLinks == 1, "Number of projects' links in the IntelliJ's 'Welcome Frame Dialog' should be 1 but is " + projectLinks + "."); + assertEquals(1, projectsOnDisk, "Number of projects in the IntelliJ's project folder should be 1 but is " + projectsOnDisk + "."); + assertEquals(1, projectLinks, "Number of projects' links in the IntelliJ's 'Welcome Frame Dialog' should be 1 but is " + projectLinks + "."); IdeInternalErrorUtils.clearWindowsErrorsIfTheyAppear(remoteRobot); flatWelcomeFrame.clearWorkspace(); int projectCount2 = getNumberOfProjectsOnDisk(); int projectLinks2 = getNumberOfProjectLinks(); - assertTrue(projectCount2 == 0, "Number of projects in the IntelliJ's project folder should be 0 but is " + projectCount2 + "."); - assertTrue(projectLinks2 == 0, "Number of projects' links in the IntelliJ's 'Welcome Frame Dialog' should be 0 but is " + projectLinks2 + "."); + assertEquals(0, projectCount2, "Number of projects in the IntelliJ's project folder should be 0 but is " + projectCount2 + "."); + assertEquals(0, projectLinks2, "Number of projects' links in the IntelliJ's 'Welcome Frame Dialog' should be 0 but is " + projectLinks2 + "."); } @Test @@ -78,7 +78,7 @@ public void clearExceptionsTest() { } private int getNumberOfProjectsOnDisk() { - String pathToIdeaProjectsFolder = CreateCloseUtils.PROJECT_LOCATION; + String pathToIdeaProjectsFolder = ProjectLocation.PROJECT_LOCATION; File[] files = new File(pathToIdeaProjectsFolder).listFiles((FileFilter) FileFilterUtils.directoryFileFilter()); if (files != null) { return files.length; diff --git a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/CodeWithMeDialogTest.java b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/CodeWithMeDialogTest.java index e353a9cd..56395628 100644 --- a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/CodeWithMeDialogTest.java +++ b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/CodeWithMeDialogTest.java @@ -18,6 +18,7 @@ import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.project.pages.NewProjectFirstPage; import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.MainIdeWindow; import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.idestatusbar.IdeStatusBar; +import com.redhat.devtools.intellij.commonuitest.utils.constants.ProjectLocation; import com.redhat.devtools.intellij.commonuitest.utils.project.CreateCloseUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -47,7 +48,7 @@ public static void prepareProject() { newProjectFirstPage.selectNewProjectType("New Project"); newProjectFirstPage.getProjectNameTextField().click(); // Click to gain focus on newProjectFirstPage newProjectFirstPage.setProjectName(PROJECT_NAME); - newProjectFirstPage.setProjectLocation(CreateCloseUtils.PROJECT_LOCATION); + newProjectFirstPage.setProjectLocation(ProjectLocation.PROJECT_LOCATION); newProjectFirstPage.setLanguage("Java"); newProjectFirstPage.setBuildSystem("IntelliJ"); newProjectFirstPage.setProjectSdkIfAvailable("17"); diff --git a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/ProjectStructureDialogTest.java b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/ProjectStructureDialogTest.java index a4959efb..a5c0c103 100644 --- a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/ProjectStructureDialogTest.java +++ b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/ProjectStructureDialogTest.java @@ -23,6 +23,7 @@ import java.time.Duration; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -48,30 +49,30 @@ public void projectStructureDialogTest() { dialogTest(() -> { ProjectStructureDialog projectStructureDialog = remoteRobot.find(ProjectStructureDialog.class, Duration.ofSeconds(10)); projectStructureDialog.cancel(); - }, ProjectStructureDialog.class, "Project Structure"); + }); } - private void dialogTest(Runnable selectedImpl, Class dialogClass, String dialogTitle) { - makeSureDialogIsVisible(dialogClass, dialogTitle); - assertTrue(isDialogVisible(dialogClass), "The '" + dialogTitle + "' dialog should be visible but is not."); - selectedImpl.run(); - assertTrue(!isDialogVisible(dialogClass), "The '" + dialogTitle + "' dialog should be visible but is not."); + private void dialogTest(Runnable runnable) { + makeSureDialogIsVisible(); + assertTrue(isDialogVisible(), "The 'Project Structure' dialog should be visible but is not."); + runnable.run(); + assertFalse(isDialogVisible(), "The 'Project Structure' dialog should be visible but is not."); IdeStatusBar ideStatusBar = remoteRobot.find(IdeStatusBar.class, Duration.ofSeconds(10)); ideStatusBar.waitUntilAllBgTasksFinish(); } - private void makeSureDialogIsVisible(Class dialogClass, String dialogTitle) { + private void makeSureDialogIsVisible() { try { - remoteRobot.find(dialogClass, Duration.ofSeconds(10)); + remoteRobot.find((Class) ProjectStructureDialog.class, Duration.ofSeconds(10)); } catch (WaitForConditionTimeoutException e) { MainIdeWindow mainIdeWindow = remoteRobot.find(MainIdeWindow.class, Duration.ofSeconds(10)); - mainIdeWindow.invokeCmdUsingSearchEverywherePopup(dialogTitle); + mainIdeWindow.invokeCmdUsingSearchEverywherePopup("Project Structure"); } } - private boolean isDialogVisible(Class dialogClass) { + private boolean isDialogVisible() { try { - remoteRobot.find(dialogClass, Duration.ofSeconds(10)); + remoteRobot.find((Class) ProjectStructureDialog.class, Duration.ofSeconds(10)); } catch (WaitForConditionTimeoutException e) { return false; } diff --git a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/TipDialogTest.java b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/TipDialogTest.java index 40dfdd0d..51c3744f 100644 --- a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/TipDialogTest.java +++ b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/information/TipDialogTest.java @@ -25,7 +25,7 @@ import java.util.logging.Level; import static com.intellij.remoterobot.search.locators.Locators.byXpath; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.fail; /** @@ -69,7 +69,7 @@ public void dontShowTipsCheckBoxTest() { boolean checkboxStateBefore = tipDialog.dontShowTipsCheckBox().isSelected(); tipDialog.dontShowTipsCheckBox().setValue(!checkboxStateBefore); boolean checkboxStateAfter = tipDialog.dontShowTipsCheckBox().isSelected(); - assertTrue(checkboxStateAfter != checkboxStateBefore, + assertNotEquals(checkboxStateAfter, checkboxStateBefore, "The checkbox value should be '" + !checkboxStateBefore + "' but is '" + checkboxStateAfter + "'."); tipDialog.dontShowTipsCheckBox().setValue(checkboxStateBefore); tipDialog.close(); diff --git a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/project_manipulation/NewProjectDialogTest.java b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/project_manipulation/NewProjectDialogTest.java index 913abecf..7b51e21d 100644 --- a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/project_manipulation/NewProjectDialogTest.java +++ b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/project_manipulation/NewProjectDialogTest.java @@ -33,7 +33,9 @@ import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import java.time.Duration; +import java.util.Arrays; import java.util.List; +import java.util.Optional; import static com.intellij.remoterobot.search.locators.Locators.byXpath; import static com.redhat.devtools.intellij.commonuitest.utils.texttranformation.TextUtils.listOfRemoteTextToString; @@ -332,7 +334,7 @@ public void cancelButtonTest() { @Test public void setProjectSdkIfAvailableTest() { if (ideaVersionInt >= 20242 && remoteRobot.isWin()) { - newProjectFirstPage.setProjectSdkIfAvailable("Download JDK"); + newProjectFirstPage.setProjectSdkIfAvailable("Download"); try { ContainerFixture downloadJdkDialog = remoteRobot.find(ContainerFixture.class, byXpath("//div[@title='Download JDK']"), Duration.ofSeconds(10)); downloadJdkDialog.find(ActionButtonFixture.class, byXpath(XPathDefinitions.label(ButtonLabels.CANCEL_LABEL)), Duration.ofSeconds(5)).click(); @@ -340,16 +342,20 @@ public void setProjectSdkIfAvailableTest() { fail("Download JDK button was not pressed and Download JDK dialog was not found"); } } else { - newProjectFirstPage.setProjectSdkIfAvailable("11"); - ComboBoxFixture projectJdkComboBox = newProjectFirstPage.getProjectJdkComboBox(); - String currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText()); - assertTrue(currentlySelectedProjectSdk.startsWith("11"), "Selected project SDK should be Java 11 but is '" + currentlySelectedProjectSdk + "'"); - newProjectFirstPage.setProjectSdkIfAvailable("17"); - currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText()); - assertTrue(currentlySelectedProjectSdk.startsWith("17"), "Selected project SDK should be Java 17 but is '" + currentlySelectedProjectSdk + "'"); + setProjectSDKVersion("11"); + setProjectSDKVersion("17"); } } + private void setProjectSDKVersion(String version) { + newProjectFirstPage.setProjectSdkIfAvailable(version); + ComboBoxFixture projectJdkComboBox = newProjectFirstPage.getProjectJdkComboBox(); + String currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText()); + Optional optional = Arrays.stream(currentlySelectedProjectSdk.split(" ")).filter(s -> + s.startsWith(version)).findFirst(); + assertTrue(optional.isPresent(), "Selected project SDK should be Java " + version + " but is '" + currentlySelectedProjectSdk + "'"); + } + @Test public void selectNewProjectTypeTest() { newProjectFirstPage.selectNewProjectType("Empty Project"); diff --git a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/settings/SettingsDialogTest.java b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/settings/SettingsDialogTest.java index 69d5dd21..6c928c78 100644 --- a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/settings/SettingsDialogTest.java +++ b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/settings/SettingsDialogTest.java @@ -47,7 +47,6 @@ class SettingsDialogTest extends LibraryTestBase { public static void openSettingsDialog() { flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10)); flatWelcomeFrame.openSettingsDialog(); - } @AfterAll diff --git a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/mainidewindow/idestatusbar/IdeStatusBarTest.java b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/mainidewindow/idestatusbar/IdeStatusBarTest.java index 4281cfe1..671dd98d 100644 --- a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/mainidewindow/idestatusbar/IdeStatusBarTest.java +++ b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/mainidewindow/idestatusbar/IdeStatusBarTest.java @@ -18,6 +18,7 @@ import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.project.pages.NewProjectFirstPage; import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.MainIdeWindow; import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.idestatusbar.IdeStatusBar; +import com.redhat.devtools.intellij.commonuitest.utils.constants.ProjectLocation; import com.redhat.devtools.intellij.commonuitest.utils.project.CreateCloseUtils; import com.redhat.devtools.intellij.commonuitest.utils.texttranformation.TextUtils; import org.junit.jupiter.api.AfterEach; @@ -41,7 +42,7 @@ private static kotlin.Pair isProgressbarWithLabelVisible( IdeStatusBar ideStatusBar = remoteRobot.find(IdeStatusBar.class, Duration.ofSeconds(10)); List inlineProgressPanelContent = ideStatusBar.inlineProgressPanel().findAllText(); String inlineProgressPanelText = TextUtils.listOfRemoteTextToString(inlineProgressPanelContent); - return new kotlin.Pair<>(!inlineProgressPanelText.equals(""), ideStatusBar); + return new kotlin.Pair<>(!inlineProgressPanelText.isEmpty(), ideStatusBar); } @BeforeEach @@ -53,7 +54,7 @@ public void prepareProject() { newProjectFirstPage.selectNewProjectType("New Project"); newProjectFirstPage.getProjectNameTextField().click(); // Click to gain focus on newProjectFirstPage newProjectFirstPage.setProjectName(PROJECT_NAME); - newProjectFirstPage.setProjectLocation(CreateCloseUtils.PROJECT_LOCATION); + newProjectFirstPage.setProjectLocation(ProjectLocation.PROJECT_LOCATION); newProjectFirstPage.selectNewProjectType("New Project"); newProjectFirstPage.setBuildSystem("Maven"); } else { diff --git a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/mainidewindow/menubar/MenuBarTest.java b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/mainidewindow/menubar/MenuBarTest.java index 70629e3f..ddde4e49 100644 --- a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/mainidewindow/menubar/MenuBarTest.java +++ b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/mainidewindow/menubar/MenuBarTest.java @@ -11,7 +11,6 @@ package com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.menubar; import com.intellij.remoterobot.RemoteRobot; -import com.intellij.remoterobot.fixtures.ComponentFixture; import com.intellij.remoterobot.utils.WaitForConditionTimeoutException; import com.redhat.devtools.intellij.commonuitest.LibraryTestBase; import com.redhat.devtools.intellij.commonuitest.UITestRunner; @@ -29,7 +28,6 @@ import java.time.Duration; -import static com.intellij.remoterobot.search.locators.Locators.byXpath; import static org.junit.jupiter.api.Assertions.assertTrue; /** diff --git a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/utils/test/screenshot/ScreenshotUtilsTest.java b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/utils/test/screenshot/ScreenshotUtilsTest.java index e2532e5f..a288e10f 100644 --- a/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/utils/test/screenshot/ScreenshotUtilsTest.java +++ b/src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/utils/test/screenshot/ScreenshotUtilsTest.java @@ -22,7 +22,7 @@ import java.nio.file.Files; import java.time.Duration; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; /** @@ -38,7 +38,7 @@ public void takeScreenshotTest() { int numberOfScreenshotBefore = getNumberOfSavedScreenshot(); File screenshotFile = ScreenshotUtils.takeScreenshot(remoteRobot); int numberOfScreenshotAfter = getNumberOfSavedScreenshot(); - assertTrue(numberOfScreenshotAfter == numberOfScreenshotBefore + 1, "Screenshot should be already saved but is not."); + assertEquals(numberOfScreenshotAfter, numberOfScreenshotBefore + 1, "Screenshot should be already saved but is not."); try { Files.delete(screenshotFile.toPath()); } catch (IOException e) {