Skip to content

Commit

Permalink
chore: fix integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Stephane Bouchet <sbouchet@redhat.com>
  • Loading branch information
sbouchet committed Jan 9, 2025
1 parent 0ed465c commit 68f4e3f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ build/
target/
pom.xml

/src/test-project/.intellijPlatform/self-update.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,11 @@ public static RemoteRobot runIde(IntelliJVersion ideaVersion, int port) {
UITestRunner.ideaVersion = ideaVersion;

acceptAllTermsAndConditions();
if (ideaVersion.isUltimate()) {
activateEvaluateForFree();
}

String fileExtension = OS_NAME.contains("windows") ? ".bat" : "";
String[] platformTypeVersion = generatePlatformTypeVersion();

ProcessBuilder pb = null;
ProcessBuilder pb;

if (ideaVersion.toInt() < 20242) {
pb = new ProcessBuilder("." + File.separator + "gradlew" + fileExtension, "runIdeForUiTests", "-PideaVersion=" + ideaVersion, "-Drobot-server.port=" + port);
Expand Down Expand Up @@ -176,18 +173,14 @@ public static RemoteRobot getRemoteRobotConnection(int port) {

private static void acceptAllTermsAndConditions() {
String osxPlistSourceLocation;
if (ideaVersion.isUltimate()) {
osxPlistSourceLocation = "plist/ultimate_all/com.apple.java.util.prefs.plist";
} else if (ideaVersion.toInt() <= 20213) {
if (ideaVersion.toInt() <= 20213) {
osxPlistSourceLocation = "plist/2021_3_and_older/com.apple.java.util.prefs.plist";
} else {
osxPlistSourceLocation = "plist/2022_1/com.apple.java.util.prefs.plist";
}

String linuxPrefsXmlSourceLocation;
if (ideaVersion.isUltimate()) {
linuxPrefsXmlSourceLocation = "prefs_xml/ultimate_all/prefs.xml";
} else if (ideaVersion.toInt() <= 20213) {
if (ideaVersion.toInt() <= 20213) {
linuxPrefsXmlSourceLocation = "prefs_xml/2021_3_and_older/prefs.xml";
} else {
linuxPrefsXmlSourceLocation = "prefs_xml/2022_1/prefs.xml";
Expand Down Expand Up @@ -259,18 +252,6 @@ private static void acceptAllTermsAndConditions() {
}
}

private static void activateEvaluateForFree() {
String targetEvaluationKeysDir = System.getProperty("user.dir") + "/build/idea-sandbox/config-uiTest/eval/";
createDirectoryHierarchy(targetEvaluationKeysDir);

for (String ideaVersionSubstring : new String[]{"202", "203", "211", "212"}) {
String keyFilename = "idea" + ideaVersionSubstring + ".evaluation.key";
String sourcePathToKey = "evaluate_for_free_keys/" + keyFilename;
String targetPathToKey = targetEvaluationKeysDir + keyFilename;
copyFileFromJarResourceDir(sourcePathToKey, targetPathToKey);
}
}

private static void waitUntilIntelliJStarts(int port) {
waitFor(Duration.ofSeconds(600), Duration.ofSeconds(3), "The IntelliJ Idea did not start in 10 minutes.", () -> isIntelliJUIVisible(port));
}
Expand Down Expand Up @@ -308,14 +289,16 @@ private static void createDirectoryHierarchy(String location) {
}

private static void copyFileFromJarResourceDir(String sourceFileLocation, String destFileLocation) {
InputStream resourceStream = UITestRunner.class.getClassLoader().getResourceAsStream(sourceFileLocation);
try (OutputStream outStream = new FileOutputStream(new File(destFileLocation))) {
byte[] buffer = new byte[resourceStream.available()];
int count = resourceStream.read(buffer);
if (count == 0) {
throw new UITestException("Reading from buffer was unsuccessful.");
try (OutputStream outStream = new FileOutputStream(destFileLocation);
InputStream resourceStream = UITestRunner.class.getClassLoader().getResourceAsStream(sourceFileLocation)) {
if (resourceStream != null) {
byte[] buffer = new byte[resourceStream.available()];
int count = resourceStream.read(buffer);
if (count == 0) {
throw new UITestException("Reading from buffer was unsuccessful.");
}
outStream.write(buffer);
}
outStream.write(buffer);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
Expand All @@ -324,7 +307,7 @@ private static void copyFileFromJarResourceDir(String sourceFileLocation, String
/**
* Redirect stdout and stderr of running subprocess to files
*
* @param pb Process builder of running subprocess
* @param pb Process builder of running subprocess
*/
private static void redirectProcessOutputs(ProcessBuilder pb) {
String outDir = System.getProperty("user.dir") + File.separator + "intellij_debug";
Expand All @@ -346,7 +329,7 @@ private static void redirectProcessOutputs(ProcessBuilder pb) {
*/
private static String[] generatePlatformTypeVersion() {
String[] platformTypeVersion = ideaVersion.toString().split("-", 2);
if (2 > platformTypeVersion.length){
if (2 > platformTypeVersion.length) {
throw new UITestException("ideaVersion is not recognized.");
}
return platformTypeVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@
import com.redhat.devtools.intellij.commonuitest.utils.constants.ButtonLabels;
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.runner.IntelliJVersion;
import com.redhat.devtools.intellij.commonuitest.utils.steps.SharedSteps;
import org.jetbrains.annotations.NotNull;

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.Duration;
import java.util.Comparator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;

import static com.intellij.remoterobot.search.locators.Locators.byXpath;

Expand All @@ -50,14 +52,12 @@ public class FlatWelcomeFrame extends CommonContainerFixture {
private static final String PROJECTS_BUTTON = "Projects";
private static final String TIP_OF_THE_DAY = "Tip of the Day";
private final RemoteRobot remoteRobot;
private final IntelliJVersion intelliJVersion;
private final int ideaVersion;

public FlatWelcomeFrame(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
super(remoteRobot, remoteComponent);
this.remoteRobot = remoteRobot;
this.intelliJVersion = UITestRunner.getIdeaVersion();
this.ideaVersion = intelliJVersion.toInt();
this.ideaVersion = UITestRunner.getIdeaVersion().toInt();
}

/**
Expand Down Expand Up @@ -100,11 +100,16 @@ public void clearWorkspace() {
// Remove projects on disk
try {
String pathToDirToMakeEmpty = CreateCloseUtils.PROJECT_LOCATION;
boolean doesProjectDirExists = Files.exists(Paths.get(pathToDirToMakeEmpty));
Path path = Paths.get(pathToDirToMakeEmpty);
boolean doesProjectDirExists = Files.exists(path);
if (doesProjectDirExists) {
Files.delete(new File(pathToDirToMakeEmpty).toPath());
try (Stream<Path> pathStream = Files.walk(new File(pathToDirToMakeEmpty).toPath())) {
pathStream.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
}
} else {
Files.createDirectories(Paths.get(pathToDirToMakeEmpty));
Files.createDirectories(path);
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package com.redhat.devtools.intellij.commonuitest.utils.constants;

import com.redhat.devtools.intellij.commonuitest.exceptions.UITestException;
import org.intellij.lang.annotations.Language;

/**
* XPath definitions
Expand Down Expand Up @@ -39,10 +40,15 @@ public class XPathDefinitions {
public static final String IDE_FATAL_ERRORS_DIALOG = "//div[@accessiblename='IDE Fatal Errors' and @class='MyDialog']";
public static final String PROJECT_STRUCTURE_DIALOG = "//div[@accessiblename='Project Structure' and @class='MyDialog']";
public static final String TIP_DIALOG = "//div[@accessiblename='Tip of the Day' and @class='MyDialog']";
@Language("XPath")
public static final String TIP_DIALOG_2 = "//div[@text='Tip of the Day']";
@Language("XPath")
public static final String RECENT_PROJECTS = "//div[@accessiblename='Recent Projects']";
@Language("XPath")
public static final String RECENT_PROJECT_PANEL_NEW = "//div[@class='NewRecentProjectPanel']";
@Language("XPath")
public static final String RECENT_PROJECT_PANEL_NEW_2 = "//div[@class='JBViewport']/*";
@Language("XPath")
public static final String IDE_ERROR_ICON = "//div[@class='IdeErrorsIcon']";
public static final String BUILD_VIEW_EDITOR = "//div[@accessiblename='Editor']";
public static final String JCOMBOBOX = "//div[@class='JComboBox']";
Expand All @@ -51,7 +57,9 @@ public class XPathDefinitions {
public static final String HEAVY_WEIGHT_WINDOW = "//div[@class='HeavyWeightWindow']";
public static final String JDK_COMBOBOX = "//div[@class='JdkComboBox']";
public static final String JDK_COMBOBOX_PROJECT_WIZARD = "//div[@class='ProjectWizardJdkComboBox']"; // works for IntelliJ Idea 2024.1 and higher
@Language("XPath")
public static final String MY_DIALOG = "//div[@class='MyDialog']";
@Language("XPath")
public static final String TREE = "//div[@class='Tree']";
public static final String TOOLTIP_TEXT_PROJECT = "//div[@tooltiptext='Project']";
public static final String TOOLTIP_TEXT_HIDE = "//div[contains(@myvisibleactions, 'View),')]//div[@tooltiptext='Hide']";
Expand All @@ -68,8 +76,11 @@ public class XPathDefinitions {
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']";
@Language("XPath")
public static final String JBLIST = "//div[@class='JBList']";
@Language("XPath")
public static final String DIALOG_PANEL = "//div[@class='DialogPanel']";
@Language("XPath")
public static final String MY_LIST = "//div[@class='MyList']";
public static final String CODE_WITH_ME_JPANEL = "//div[@class='Wrapper'][.//div[@class='JBLabel']]//div[@class='JPanel']";
public static final String BREAD_CRUMBS = "//div[@class='Breadcrumbs']";
Expand All @@ -81,6 +92,7 @@ public class XPathDefinitions {
public static final String COLLAPSIBLE_TITLED_SEPARATOR_NEW_SIBLINGS = COLLAPSIBLE_TITLED_SEPARATOR_NEW + "/../*";
public static final String EXTENDABLE_TEXT_FIELD = "//div[@class='ExtendableTextField']";
public static final String JBTEXT_FIELD = "//div[@class='JBTextField']";
@Language("XPath")
public static final String REMOVE_PROJECT_BUTTON = "//div[contains(@text.key, 'button.remove')]";
public static final String SET_LANGUAGE = "//div[@class='SegmentedButtonComponent'][.//div[contains(@action.key, 'language.groovy')]]";
public static final String SET_BUILD_SYSTEM = "//div[@class='SegmentedButtonComponent'][.//div[@action.key='buildsystem.type.intellij']]";
Expand All @@ -89,6 +101,7 @@ public class XPathDefinitions {
public static final String GET_SET_MODULE_NAME_2024_2_AND_NEWER = "//div[@accessiblename='Module name:' and @class='JBTextField']";
public static final String GET_SET_CONTENT_ROOT = "//div[@accessiblename='Content root:' and @class='ExtendableTextField']";
public static final String GET_SET_MODULE_FILE_LOCATION = "//div[@accessiblename='Module file location:' and @class='ExtendableTextField']";
@Language("XPath")
public static final String CREATE_NEW_PROJECT = "//div[@defaulticon='createNewProjectTab.svg']"; // works for IntelliJ Idea 2024.1 and higher

private XPathDefinitions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,17 @@ public enum IntelliJVersion {
COMMUNITY_V_2023_2("IC-2023.2"),
COMMUNITY_V_2024_1("IC-2024.1"),
COMMUNITY_V_2024_2("IC-2024.2"),
ULTIMATE_V_2020_2("IU-2020.2"),
ULTIMATE_V_2020_3("IU-2020.3"),
ULTIMATE_V_2021_1("IU-2021.1"),
ULTIMATE_V_2021_2("IU-2021.2"),
ULTIMATE_V_2023_2("IU-2023.2"),
ULTIMATE_V_2024_1("IU-2024.1"),
ULTIMATE_V_2024_2("IU-2024.2");
COMMUNITY_V_2024_3("IC-2024.3");

private final String ideaVersionStringRepresentation;
private final int ideaVersionIntRepresentation;
private final boolean isIdeaUltimate;

IntelliJVersion(String ideaVersionStringRepresentation) {
this.ideaVersionStringRepresentation = ideaVersionStringRepresentation;

String ideaVersionString = this.ideaVersionStringRepresentation.substring(3).replace(".", "");
this.ideaVersionIntRepresentation = Integer.parseInt(ideaVersionString);

this.isIdeaUltimate = this.ideaVersionStringRepresentation.charAt(1) == 'U';
}

@Override
Expand All @@ -58,7 +50,4 @@ public int toInt() {
return this.ideaVersionIntRepresentation;
}

public boolean isUltimate() {
return this.isIdeaUltimate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.junit.jupiter.api.extension.ExtendWith;

import java.time.Duration;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
Expand All @@ -33,25 +32,16 @@
public class LibraryTestBase {
protected static final Logger LOGGER = Logger.getLogger(LibraryTestBase.class.getName());
private static final IntelliJVersion communityIdeaVersion = IntelliJVersion.COMMUNITY_V_2024_2;
private static final IntelliJVersion ultimateIdeaVersion = IntelliJVersion.ULTIMATE_V_2024_2;
protected static RemoteRobot remoteRobot;
protected static int ideaVersionInt;
private static boolean intelliJHasStarted = false;
private static final int port = 8580;
private static final int TEST_RUNNER_PORT = 8580;

@BeforeAll
protected static void startIntelliJ() {
if (!intelliJHasStarted) {
String taskName = System.getProperty("task.name");
if (taskName != null && taskName.equalsIgnoreCase("integrationUITestUltimate")) {
// Run UI tests for ultimate version
ideaVersionInt = ultimateIdeaVersion.toInt();
remoteRobot = UITestRunner.runIde(ultimateIdeaVersion, port);
} else {
// Run UI tests for community version
ideaVersionInt = communityIdeaVersion.toInt();
remoteRobot = UITestRunner.runIde(communityIdeaVersion, port);
}
ideaVersionInt = communityIdeaVersion.toInt();
remoteRobot = UITestRunner.runIde(communityIdeaVersion, TEST_RUNNER_PORT);

intelliJHasStarted = true;
Runtime.getRuntime().addShutdownHook(new CloseIntelliJBeforeQuit());
Expand Down

0 comments on commit 68f4e3f

Please sign in to comment.