Skip to content

Commit

Permalink
Add support for IntelliJ CE 2022.2 (#141)
Browse files Browse the repository at this point in the history
Fixes #140

Signed-off-by: Zbynek Cervinka <[email protected]>
  • Loading branch information
zcervink authored Aug 4, 2022
1 parent f00e91f commit 1984371
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,8 @@ public void clickOnLink(String label) {
* Clear the workspace by deleting the content of the IdeaProjects folder and clearing all the projects' links in the 'Welcome to IntelliJ IDEA' dialog
*/
public void clearWorkspace() {
List<JListFixture> jListFixtures = jLists(byXpath(XPathDefinitions.RECENT_PROJECTS));
for (int i = 0; i < projectsCount(); i++) {
JListFixture recentProjectsList = jListFixtures.get(0);
recentProjectsList.runJs("const horizontal_offset = component.getWidth()-22;\n" +
"robot.click(component, new Point(horizontal_offset, 22), MouseButton.LEFT_BUTTON, 1);");
// Code for IntelliJ Idea 2020.3 or newer
if (ideaVersion >= 20203) {
List<JPopupMenuFixture> jPopupMenuFixtures = jPopupMenus(JPopupMenuFixture.Companion.byType());
if (!jPopupMenuFixtures.isEmpty()) {
JPopupMenuFixture contextMenu = jPopupMenuFixtures.get(0);
contextMenu.select("Remove from Recent Projects");
}
}
removeTopProjectFromRecentProjects();
}

try {
Expand Down Expand Up @@ -227,18 +216,27 @@ public void switchToProjectsPage() {
}

private int projectsCount() {
try {
ContainerFixture projectWrapper = find(ContainerFixture.class, byXpath(XPathDefinitions.NEW_RECENT_PROJECT_PANEL));
JListFixture projectList = projectWrapper.find(JListFixture.class, byXpath(XPathDefinitions.MY_LIST));
return projectList.collectItems().size();
} catch (WaitForConditionTimeoutException e) {
return 0;
if (ideaVersion >= 20222) {
try {
JTreeFixture projects = remoteRobot.findAll(JTreeFixture.class, byXpath(XPathDefinitions.RECENT_PROJECT_PANEL_NEW_2)).get(0);
return projects.findAllText().size() / 2;
} catch (IndexOutOfBoundsException e) {
return 0;
}
} else {
try {
ContainerFixture projectWrapper = find(ContainerFixture.class, byXpath(XPathDefinitions.RECENT_PROJECT_PANEL_NEW));
JListFixture projectList = projectWrapper.find(JListFixture.class, byXpath(XPathDefinitions.MY_LIST));
return projectList.collectItems().size();
} catch (WaitForConditionTimeoutException e) {
return 0;
}
}
}

// Works for IntelliJ Idea 2020.3+
private JButtonFixture welcomeFrameLink(String label) {
if (UtilsKt.hasAnyComponent(this, byXpath(XPathDefinitions.NEW_RECENT_PROJECT_PANEL))) {
if (UtilsKt.hasAnyComponent(this, byXpath(XPathDefinitions.RECENT_PROJECT_PANEL_NEW))) {
return button(byXpath(XPathDefinitions.jBOptionButton(label)), Duration.ofSeconds(2));
}
return button(byXpath(XPathDefinitions.nonOpaquePanel(label)), Duration.ofSeconds(2));
Expand All @@ -247,4 +245,30 @@ private JButtonFixture welcomeFrameLink(String label) {
private ComponentFixture ideErrorsIcon() {
return find(ComponentFixture.class, byXpath(XPathDefinitions.IDE_ERROR_ICON), Duration.ofSeconds(10));
}

private void removeTopProjectFromRecentProjects() {
ComponentFixture recentProjects;
if (ideaVersion >= 20222) {
recentProjects = remoteRobot.findAll(JTreeFixture.class, byXpath(XPathDefinitions.RECENT_PROJECT_PANEL_NEW_2)).get(0);
} else {
recentProjects = jLists(byXpath(XPathDefinitions.RECENT_PROJECTS)).get(0);
}

recentProjects.runJs("const horizontal_offset = component.getWidth()-22;\n" +
"robot.click(component, new Point(horizontal_offset, 22), MouseButton.LEFT_BUTTON, 1);");

// Code for IntelliJ Idea 2020.3 or newer
if (ideaVersion >= 20203) {
List<JPopupMenuFixture> jPopupMenuFixtures = jPopupMenus(JPopupMenuFixture.Companion.byType());
if (!jPopupMenuFixtures.isEmpty()) {
JPopupMenuFixture contextMenu = jPopupMenuFixtures.get(0);
if (ideaVersion >= 20222) {
contextMenu.select("Remove from Recent Projects" + '\u2026');
button(byXpath(XPathDefinitions.REMOVE_PROJECT_BUTTON)).click();
} else {
contextMenu.select("Remove from Recent Projects");
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected AbstractNewProjectFinalPage(@NotNull RemoteRobot remoteRobot, @NotNull
*/
public String getProjectName() {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
return textFields(byXpath("//div[@class='JBTextField']")).get(0).getText();
return textFields(byXpath(XPathDefinitions.JBTEXT_FIELD)).get(0).getText();
} else {
return textFields(JTextFieldFixture.Companion.byType()).get(0).getText();
}
Expand All @@ -59,7 +59,7 @@ public String getProjectName() {
*/
public void setProjectName(String projectName) {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
textFields(byXpath("//div[@class='JBTextField']")).get(0).setText(projectName);
textFields(byXpath(XPathDefinitions.JBTEXT_FIELD)).get(0).setText(projectName);
} else {
textFields(JTextFieldFixture.Companion.byType()).get(0).setText(projectName);
}
Expand All @@ -72,7 +72,7 @@ public void setProjectName(String projectName) {
*/
public String getProjectLocation() {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
return find(JTextFieldFixture.class, byXpath("//div[@class='ExtendableTextField']")).getText();
return find(JTextFieldFixture.class, byXpath(XPathDefinitions.EXTENDABLE_TEXT_FIELD)).getText();
} else {
return textFields(JTextFieldFixture.Companion.byType()).get(1).getText();
}
Expand All @@ -85,7 +85,7 @@ public String getProjectLocation() {
*/
public void setProjectLocation(String projectLocation) {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
find(JTextFieldFixture.class, byXpath("//div[@class='ExtendableTextField']")).setText(projectLocation);
find(JTextFieldFixture.class, byXpath(XPathDefinitions.EXTENDABLE_TEXT_FIELD )).setText(projectLocation);
} else {
textFields(JTextFieldFixture.Companion.byType()).get(1).setText(projectLocation);
}
Expand All @@ -96,7 +96,11 @@ public void setProjectLocation(String projectLocation) {
*/
public void openAdvanceSettings() {
if (!isAdvancedSettingsOpened()) {
find(ComponentFixture.class, byXpath("//div[@class='CollapsibleTitledSeparator']")).click();
if (UITestRunner.getIdeaVersionInt() >= 20222) {
find(ComponentFixture.class, byXpath(XPathDefinitions.COLLAPSIBLE_TITLED_SEPARATOR_NEW)).click();
} else {
find(ComponentFixture.class, byXpath(XPathDefinitions.COLLAPSIBLE_TITLED_SEPARATOR)).click();
}
}
}

Expand All @@ -105,15 +109,26 @@ public void openAdvanceSettings() {
*/
public void closeAdvanceSettings() {
if (isAdvancedSettingsOpened()) {
find(ComponentFixture.class, byXpath("//div[@class='CollapsibleTitledSeparator']")).click();
if (UITestRunner.getIdeaVersionInt() >= 20222) {
find(ComponentFixture.class, byXpath(XPathDefinitions.COLLAPSIBLE_TITLED_SEPARATOR_NEW)).click();
} else {
find(ComponentFixture.class, byXpath(XPathDefinitions.COLLAPSIBLE_TITLED_SEPARATOR)).click();
}
}
}

private boolean isAdvancedSettingsOpened() {
List<ComponentFixture> ss = findAll(ComponentFixture.class, byXpath("//div[@class='CollapsibleTitledSeparator']/../*"));
for (int i = 0; i < ss.size(); i++) {
if (listOfRemoteTextToString(ss.get(i).findAllText()).contains("Advanced Settings")) {
return i != ss.size() - 1;
List<ComponentFixture> cf;

if (UITestRunner.getIdeaVersionInt() >= 20222) {
cf = findAll(ComponentFixture.class, byXpath(XPathDefinitions.COLLAPSIBLE_TITLED_SEPARATOR_NEW_SIBLINGS));
} else {
cf = findAll(ComponentFixture.class, byXpath(XPathDefinitions.COLLAPSIBLE_TITLED_SEPARATOR_SIBLINGS));
}

for (int i = 0; i < cf.size(); i++) {
if (listOfRemoteTextToString(cf.get(i).findAllText()).contains("Advanced Settings")) {
return i != cf.size() - 1;
}
}
throw new UITestException("Wizard does not contain 'Advanced Settings' section.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void closeMoreSettings() {
*/
public String getModuleName() {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
return find(JTextFieldFixture.class, byXpath("//div[@accessiblename='Module name:' and @accessiblename.key='label.project.wizard.new.project.module.name' and @class='JBTextField']")).getText();
return find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_MODULE_NAME)).getText();
} else {
return textField("Module name:", true).getText();
}
Expand All @@ -84,7 +84,7 @@ public String getModuleName() {
*/
public void setModuleName(String moduleName) {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
find(JTextFieldFixture.class, byXpath("//div[@accessiblename='Module name:' and @accessiblename.key='label.project.wizard.new.project.module.name' and @class='JBTextField']")).setText(moduleName);
find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_MODULE_NAME)).setText(moduleName);
} else {
textField("Module name:", true).setText(moduleName);
}
Expand All @@ -97,7 +97,7 @@ public void setModuleName(String moduleName) {
*/
public String getContentRoot() {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
return find(JTextFieldFixture.class, byXpath("//div[@accessiblename='Content root:' and @accessiblename.key='label.project.wizard.new.project.content.root' and @class='ExtendableTextField']")).getText();
return find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_CONTENT_ROOT)).getText();
} else {
return textField("Content root:", true).getText();
}
Expand All @@ -110,7 +110,7 @@ public String getContentRoot() {
*/
public void setContentRoot(String contentRoot) {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
find(JTextFieldFixture.class, byXpath("//div[@accessiblename='Content root:' and @accessiblename.key='label.project.wizard.new.project.content.root' and @class='ExtendableTextField']")).setText(contentRoot);
find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_CONTENT_ROOT)).setText(contentRoot);
} else {
textField("Content root:", true).setText(contentRoot);
}
Expand All @@ -123,7 +123,7 @@ public void setContentRoot(String contentRoot) {
*/
public String getModuleFileLocation() {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
return find(JTextFieldFixture.class, byXpath("//div[@accessiblename='Module file location:' and @accessiblename.key='label.project.wizard.new.project.module.file.location' and @class='ExtendableTextField']")).getText();
return find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_MODULE_FILE_LOCATION)).getText();
} else {
return textField("Module file location:", true).getText();
}
Expand All @@ -136,7 +136,7 @@ public String getModuleFileLocation() {
*/
public void setModuleFileLocation(String moduleFileLocation) {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
find(JTextFieldFixture.class, byXpath("//div[@accessiblename='Module file location:' and @accessiblename.key='label.project.wizard.new.project.module.file.location' and @class='ExtendableTextField']")).setText(moduleFileLocation);
find(JTextFieldFixture.class, byXpath(XPathDefinitions.GET_SET_MODULE_FILE_LOCATION)).setText(moduleFileLocation);
} else {
textField("Module file location:", true).setText(moduleFileLocation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void selectNewProjectType(String projectType) {
*/
@Override
public void setProjectName(String projectName) {
find(JTextFieldFixture.class, byXpath("//div[@class='JBTextField']")).setText(projectName);
find(JTextFieldFixture.class, byXpath(XPathDefinitions.JBTEXT_FIELD)).setText(projectName);
}

/**
Expand All @@ -76,7 +76,7 @@ public void setProjectName(String projectName) {
* @param language project language
*/
public void setLanguage(String language) {
findAll(JLabelFixture.class, byXpath("//div[@class='SegmentedButtonComponent'][.//div[contains(@action.key, 'language.groovy')]]")).get(0).findText(language).click();
findAll(JLabelFixture.class, byXpath(XPathDefinitions.SET_LANGUAGE)).get(0).findText(language).click();
}

/**
Expand All @@ -85,7 +85,7 @@ public void setLanguage(String language) {
* @param buildSystem build system type
*/
public void setBuildSystem(String buildSystem) {
find(JLabelFixture.class, byXpath("//div[@class='SegmentedButtonComponent'][.//div[@action.key='buildsystem.type.intellij']]")).findText(buildSystem).click();
find(JLabelFixture.class, byXpath(XPathDefinitions.SET_BUILD_SYSTEM)).findText(buildSystem).click();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ private JButtonFixture mainMenuItem(String label) {
CommonContainerFixture cf;
if (remoteRobot.isLinux()) {
cf = remoteRobot.find(CommonContainerFixture.class, byXpath(XPathDefinitions.LINUX_MAIN_MENU), Duration.ofSeconds(10));
} else if (remoteRobot.isWin() && ideaVersion.toInt() >= 20222) {
cf = remoteRobot.find(CommonContainerFixture.class, byXpath(XPathDefinitions.WINDOWS_MAIN_MENU_2022_2_AND_NEWER), Duration.ofSeconds(10));
} else if (remoteRobot.isWin() && ideaVersion.toInt() >= 20203) {
cf = remoteRobot.find(CommonContainerFixture.class, byXpath(XPathDefinitions.WINDOWS_MAIN_MENU_2020_3_AND_NEWER), Duration.ofSeconds(10));
cf = remoteRobot.find(CommonContainerFixture.class, byXpath(XPathDefinitions.WINDOWS_MAIN_MENU_2020_3_TO_2022_1), Duration.ofSeconds(10));
} else {
cf = remoteRobot.find(CommonContainerFixture.class, byXpath(XPathDefinitions.WINDOWS_MAIN_MENU_2020_2_AND_OLDER), Duration.ofSeconds(10));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane.buildtoolpane.GradleBuildToolPane;
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane.buildtoolpane.MavenBuildToolPane;
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;
Expand Down Expand Up @@ -98,12 +99,12 @@ public void closeGradleBuildToolPane() {
public JButtonFixture stripeButton(String label, boolean isPaneOpened) {
if (isPaneOpened) {
if (label.equals(ButtonLabels.MAVEN_STRIPE_BUTTON_LABEL) || label.equals(ButtonLabels.GRADLE_STRIPE_BUTTON_LABEL)) {
return button(byXpath("//div[@disabledicon='toolWindow" + label + ".svg']"), Duration.ofSeconds(2));
return button(byXpath(XPathDefinitions.toolWindowSvg(label)), Duration.ofSeconds(2));
} else if (label.equals(ButtonLabels.PROJECT_STRIPE_BUTTON_LABEL)) {
return button(byXpath("//div[@tooltiptext='Project']"), Duration.ofSeconds(2));
return button(byXpath(XPathDefinitions.TOOLTIP_TEXT_PROJECT), Duration.ofSeconds(2));
}
}
return button(byXpath("//div[@text='" + label + "']"), Duration.ofSeconds(2));
return button(byXpath(XPathDefinitions.label(label)), Duration.ofSeconds(2));
}

protected <T extends Fixture> T togglePane(String label, Class<T> fixtureClass, boolean openPane) {
Expand Down
Loading

0 comments on commit 1984371

Please sign in to comment.