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

feat: added IU-2024.2 to IntelliJVersion #302

Merged
merged 11 commits into from
Oct 8, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.List;
Expand Down Expand Up @@ -150,7 +149,46 @@ public void openSettingsDialog() {
} else {
JTreeFixture jTreeFixture = remoteRobot.find(JTreeFixture.class, byXpath(XPathDefinitions.TREE));
jTreeFixture.findText("Customize").click();
remoteRobot.find(ContainerFixture.class, byXpath(XPathDefinitions.DIALOG_PANEL)).findText("All settings" + '\u2026').click();

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

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
*/
private void resizeWelcomeWindow(RemoteRobot remoteRobot, 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;
}
}
resized;
""", newHeight));
Thread.sleep(5000);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to resize the Welcome window: " + e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public void closeMoreSettings() {
* @return name of the module currently inserted in the input field
*/
public String getModuleName() {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
if (UITestRunner.getIdeaVersionInt() >= 20242) {
return find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_MODULE_NAME_2024_2_AND_NEWER)).getText();
}
else if (UITestRunner.getIdeaVersionInt() >= 20221) {
return find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_MODULE_NAME)).getText();
} else {
return textField("Module name:", true).getText();
Expand All @@ -83,7 +86,10 @@ public String getModuleName() {
* @param moduleName name of the module that will be set into the input field
*/
public void setModuleName(String moduleName) {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
if (UITestRunner.getIdeaVersionInt() >= 20242) {
find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_MODULE_NAME_2024_2_AND_NEWER)).setText(moduleName);
}
else if (UITestRunner.getIdeaVersionInt() >= 20221) {
find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_MODULE_NAME)).setText(moduleName);
} else {
textField("Module name:", true).setText(moduleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void setLanguage(String language) {
*/
public void setBuildSystem(String buildSystem) {
if (ideaVersion >= 20241) {
find(JLabelFixture.class, byXpath(XPathDefinitions.SET_BUILD_SYSTEM_2024_1_AND_NEWER)).findText(buildSystem).click();
find(JLabelFixture.class, byXpath(XPathDefinitions.SET_BUILD_SYSTEM_2024_2_AND_NEWER)).findText(buildSystem).click();
} else {
find(JLabelFixture.class, byXpath(XPathDefinitions.SET_BUILD_SYSTEM)).findText(buildSystem).click();
}
Expand All @@ -121,12 +121,21 @@ public ComboBoxFixture getProjectJdkComboBox() {
* @param targetSdkName name of the SDK to which will be changed the current settings
*/
public void setProjectSdkIfAvailable(String targetSdkName) {
step("Select the '" + targetSdkName + "' as new project SDK", () -> {
ComboBoxFixture projectJdkComboBox = getProjectJdkComboBox();
String currentlySelectedProjectSdk = TextUtils.listOfRemoteTextToString(projectJdkComboBox.findAllText());
if (currentlySelectedProjectSdk.contains(targetSdkName)) {
return;
}
step("Select the '" + targetSdkName + "' as new project SDK", () -> {

waitFor(
Duration.ofSeconds(20),
Duration.ofSeconds(5),
"Waiting for 'resolving jdk' dialog to disappear.",
() -> "Expected exactly one dialog but found " + remoteRobot.findAll(CommonContainerFixture.class, byXpath(XPathDefinitions.MY_DIALOG)).size(),
() -> remoteRobot.findAll(CommonContainerFixture.class, byXpath(XPathDefinitions.MY_DIALOG)).size() == 1
);

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

if (UITestRunner.getIdeaVersionInt() >= 20221) {
projectJdkComboBox.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.menubar;

import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.fixtures.ActionButtonFixture;
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
import com.intellij.remoterobot.fixtures.JButtonFixture;
import com.intellij.remoterobot.fixtures.JPopupMenuFixture;
Expand Down Expand Up @@ -47,10 +48,18 @@ public void navigateTo(String... path) {
if (path.length == 0) {
return;
}
if (UITestRunner.getIdeaVersionInt() >= 20242) {
remoteRobot.find(ActionButtonFixture.class, byXpath(XPathDefinitions.MAIN_MENU)).click();
}

JButtonFixture mainMenuFirstItem = mainMenuItem(path[0]);
if (mainMenuFirstItem != null) {
mainMenuFirstItem.click();
if (UITestRunner.getIdeaVersionInt() >= 20242) {
mainMenuFirstItem.moveMouse();
} else {
mainMenuFirstItem.click();
}

// Wait for the JPopupMenuFixture to appear
waitFor(Duration.ofSeconds(5), Duration.ofSeconds(1), "JPopupMenu to appear", () ->
!remoteRobot.findAll(JPopupMenuFixture.class, JPopupMenuFixture.Companion.byType()).isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,58 @@ private boolean isPaneOpened(Class<? extends Fixture> fixtureClass) {
}

private void clickOnStripeButton(String label, boolean isPaneOpened) {
waitFor(Duration.ofSeconds(30), Duration.ofSeconds(2), "The '" + label + "' stripe button is not available.", () -> isStripeButtonAvailable(label, isPaneOpened));
if (UITestRunner.getIdeaVersionInt() >= 20221) {
remoteRobot.find(ToolWindowPane.class, Duration.ofSeconds(10)).stripeButton(label, isPaneOpened).click();
waitFor(Duration.ofSeconds(30), Duration.ofSeconds(2),
"The '" + label + "' stripe button is not available.",
() -> isStripeButtonAvailable(label, isPaneOpened));

if (UITestRunner.getIdeaVersionInt() >= 20242) {
// For IntelliJ IDEA 2024.2 and newer
if (isRightToolbarButton(label)) {
ToolWindowRightToolbar toolWindowRightToolbar = remoteRobot.find(ToolWindowRightToolbar.class, Duration.ofSeconds(10));
toolWindowRightToolbar.clickStripeButton(label);
} else {
ToolWindowLeftToolbar toolWindowLeftToolbar = remoteRobot.find(ToolWindowLeftToolbar.class, Duration.ofSeconds(10));
toolWindowLeftToolbar.clickStripeButton(label);
}
} else if (UITestRunner.getIdeaVersionInt() >= 20221) {
// For IntelliJ IDEA 2022.1 to 2024.1
ToolWindowPane toolWindowPane = remoteRobot.find(ToolWindowPane.class, Duration.ofSeconds(10));
toolWindowPane.stripeButton(label, isPaneOpened).click();
} else {
remoteRobot.find(ToolWindowsPane.class, Duration.ofSeconds(10)).stripeButton(label, isPaneOpened).click();
// For older versions
ToolWindowsPane toolWindowsPane = remoteRobot.find(ToolWindowsPane.class, Duration.ofSeconds(10));
toolWindowsPane.stripeButton(label, isPaneOpened).click();
}
}

private boolean isStripeButtonAvailable(String label, boolean isPaneOpened) {
try {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
remoteRobot.find(ToolWindowPane.class, Duration.ofSeconds(2)).stripeButton(label, isPaneOpened);
if (UITestRunner.getIdeaVersionInt() >= 20242) {
// For IntelliJ IDEA 2024.2 and newer
if (isRightToolbarButton(label)) {
ToolWindowRightToolbar toolWindowRightToolbar = remoteRobot.find(ToolWindowRightToolbar.class, Duration.ofSeconds(2));
toolWindowRightToolbar.findStripeButton(label);
} else {
ToolWindowLeftToolbar toolWindowLeftToolbar = remoteRobot.find(ToolWindowLeftToolbar.class, Duration.ofSeconds(2));
toolWindowLeftToolbar.findStripeButton(label);
}
} else if (UITestRunner.getIdeaVersionInt() >= 20221) {
// For IntelliJ IDEA 2022.1 to 2024.1
ToolWindowPane toolWindowPane = remoteRobot.find(ToolWindowPane.class, Duration.ofSeconds(2));
toolWindowPane.stripeButton(label, isPaneOpened);
} else {
remoteRobot.find(ToolWindowsPane.class, Duration.ofSeconds(2)).stripeButton(label, isPaneOpened);
// For older versions
ToolWindowsPane toolWindowsPane = remoteRobot.find(ToolWindowsPane.class, Duration.ofSeconds(2));
toolWindowsPane.stripeButton(label, isPaneOpened);
}
return true;
} catch (WaitForConditionTimeoutException e) {
return false;
}
return true;
}

private boolean isRightToolbarButton(String label) {
return label.equals(ButtonLabels.MAVEN_STRIPE_BUTTON_LABEL) ||
label.equals(ButtonLabels.GRADLE_STRIPE_BUTTON_LABEL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.intellij.remoterobot.fixtures.JPopupMenuFixture;
import com.intellij.remoterobot.fixtures.JTreeFixture;
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
import com.redhat.devtools.intellij.commonuitest.UITestRunner;
import com.redhat.devtools.intellij.commonuitest.exceptions.UITestException;
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -86,7 +87,8 @@ public JPopupMenuFixture openContextMenuOn(String... path) {
* @return Views popup fixture
*/
public JPopupMenuFixture openViewsPopup() {
actionButton(byXpath(XPathDefinitions.CONTENT_COMBO_LABEL), Duration.ofSeconds(2)).click();
projectViewTree().moveMouse();
actionButton(byXpath(XPathDefinitions.CONTENT_COMBO_LABEL), Duration.ofSeconds(5)).click();
try {
return remoteRobot.find(JPopupMenuFixture.class, byXpath(XPathDefinitions.HEAVY_WEIGHT_WINDOW), Duration.ofSeconds(10));
} catch (WaitForConditionTimeoutException e) {
Expand All @@ -98,21 +100,32 @@ public JPopupMenuFixture openViewsPopup() {
* Locate and select opened file
*/
public void selectOpenedFile() {
actionButton(byXpath(XPathDefinitions.MY_ICON_LOCATE_SVG), Duration.ofSeconds(2)).click();
projectViewTree().moveMouse();
actionButton(byXpath(XPathDefinitions.MY_ICON_LOCATE_SVG), Duration.ofSeconds(5)).click();
}

/**
* Expand all
*/
public void expandAll() {
actionButton(byXpath(XPathDefinitions.MY_ICON_EXPAND_ALL), Duration.ofSeconds(2)).click();
projectViewTree().moveMouse();
if (UITestRunner.getIdeaVersionInt() >= 20242) {
actionButton(byXpath(XPathDefinitions.MY_ICON_EXPAND_ALL_2024_2), Duration.ofSeconds(5)).click();
} else {
actionButton(byXpath(XPathDefinitions.MY_ICON_EXPAND_ALL), Duration.ofSeconds(5)).click();
}
}

/**
* Collapse all
*/
public void collapseAll() {
actionButton(byXpath(XPathDefinitions.MY_ICON_COLLAPSE_ALL), Duration.ofSeconds(2)).click();
projectViewTree().moveMouse();
if (UITestRunner.getIdeaVersionInt() >= 20242) {
actionButton(byXpath(XPathDefinitions.MY_ICON_COLLAPSE_ALL_2024_2), Duration.ofSeconds(5)).click();
} else {
actionButton(byXpath(XPathDefinitions.MY_ICON_COLLAPSE_ALL), Duration.ofSeconds(5)).click();
}
}

/**
Expand All @@ -121,7 +134,12 @@ public void collapseAll() {
* @return settings popup fixture
*/
public JPopupMenuFixture openSettingsPopup() {
actionButton(byXpath(XPathDefinitions.MY_ICON_GEAR_PLAIN), Duration.ofSeconds(2)).click();
projectViewTree().moveMouse();
if (UITestRunner.getIdeaVersionInt() >= 20242) {
actionButton(byXpath(XPathDefinitions.MY_ICON_MORE_VERTICAL), Duration.ofSeconds(5)).click();
} else {
actionButton(byXpath(XPathDefinitions.MY_ICON_GEAR_PLAIN), Duration.ofSeconds(5)).click();
}
try {
return remoteRobot.find(JPopupMenuFixture.class, byXpath(XPathDefinitions.HEAVY_WEIGHT_WINDOW), Duration.ofSeconds(10));
} catch (WaitForConditionTimeoutException e) {
Expand All @@ -133,7 +151,8 @@ public JPopupMenuFixture openSettingsPopup() {
* Hide Project Explorer
*/
public void hide() {
actionButton(byXpath(XPathDefinitions.TOOLTIP_TEXT_HIDE), Duration.ofSeconds(2)).click();
projectViewTree().moveMouse();
actionButton(byXpath(XPathDefinitions.TOOLTIP_TEXT_HIDE), Duration.ofSeconds(5)).click();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane;

import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.data.RemoteComponent;
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
import com.intellij.remoterobot.fixtures.DefaultXpath;
import com.intellij.remoterobot.fixtures.FixtureName;
import com.intellij.remoterobot.fixtures.JButtonFixture;
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;

@DefaultXpath(by = "ToolWindowLeftToolbar type", xpath = "//div[@class='ToolWindowLeftToolbar']")
@FixtureName(name = "Tool Window Left Toolbar")
public class ToolWindowLeftToolbar extends CommonContainerFixture {

public ToolWindowLeftToolbar(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
super(remoteRobot, remoteComponent);
}

public JButtonFixture stripeButton(String label) {
// For IntelliJ IDEA 2024.2 and newer, use the tooltiptext attribute
return button(byXpath(XPathDefinitions.toolWindowButton(label)), Duration.ofSeconds(2));
}

public void clickStripeButton(String label) {
stripeButton(label).click();
}

public void findStripeButton(String label) {
stripeButton(label);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane;

import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.data.RemoteComponent;
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
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")
public class ToolWindowRightToolbar extends CommonContainerFixture {

public ToolWindowRightToolbar(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
super(remoteRobot, remoteComponent);
}

public JButtonFixture stripeButton(String label) {
return button(byXpath(XPathDefinitions.toolWindowButton(label)), Duration.ofSeconds(2));
}

public void clickStripeButton(String label) {
stripeButton(label).click();
}

public void findStripeButton(String label) {
stripeButton(label);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,22 @@ public void reloadAllGradleProjects() {
* Expand all
*/
public void expandAll() {
actionButton(byXpath(XPathDefinitions.MY_ICON_EXPAND_ALL_IDE), Duration.ofSeconds(2)).click();
if (UITestRunner.getIdeaVersionInt() >= 20242) { // Code for IntelliJ version 2024.2 and newer
actionButton(byXpath(XPathDefinitions.MY_ICON_EXPAND_ALL_2024_2), Duration.ofSeconds(2)).click();
} else { // Code for IntelliJ version 2024.1 and older
actionButton(byXpath(XPathDefinitions.MY_ICON_EXPAND_ALL_IDE), Duration.ofSeconds(2)).click();
}
}

/**
* Collapse all
*/
public void collapseAll() {
actionButton(byXpath(XPathDefinitions.MY_ICON_COLLAPSE_ALL_IDE), Duration.ofSeconds(2)).click();
if (UITestRunner.getIdeaVersionInt() >= 20242) { // Code for IntelliJ version 2024.2 and newer
actionButton(byXpath(XPathDefinitions.MY_ICON_COLLAPSE_ALL_2024_2), Duration.ofSeconds(2)).click();
} else { // Code for IntelliJ version 2024.1 and older
actionButton(byXpath(XPathDefinitions.MY_ICON_COLLAPSE_ALL_IDE), Duration.ofSeconds(2)).click();
}
}

/**
Expand Down
Loading
Loading