Skip to content

Commit 091863d

Browse files
richardkocianmartinszucLukas Grossmann
authored
feat: Added openProjectFromWelcomeDialog method for reopening project (#208)
* fix: open tip dialog for IJ 2022.1+ also added SharedSteps class with waitForComponentByXpath Signed-off-by: Martin Szuc <[email protected]> * fix: OpenFileTest correctly verifies opened file for IJ 2023.2 Signed-off-by: Martin Szuc <[email protected]> * fix: selectNewProjectTypeTest correctly verifies isEmptyProjectPageDisplayed chore: up java version for jdk selection in tests Signed-off-by: Martin Szuc <[email protected]> * fix: stripeButton for Maven/Gradle for IJ 2023.2+ Signed-off-by: Martin Szuc <[email protected]> * feat: Added openProjectFromWelcomeDialog method for reopening project * test: Added closeAndReopenProjectTest rh-pre-commit.version: 2.1.0 rh-pre-commit.check-secrets: ENABLED * fix: Removed unused code Signed-off-by: Richard Kocian <[email protected]> rh-pre-commit.version: 2.1.0 rh-pre-commit.check-secrets: ENABLED * test: Added GHA job workflow for menubar tests Signed-off-by: Richard Kocian <[email protected]> rh-pre-commit.version: 2.1.0 rh-pre-commit.check-secrets: ENABLED * fix: Changed xpath for reopening project from welcome screen Signed-off-by: Richard Kocian <[email protected]> rh-pre-commit.version: 2.1.0 rh-pre-commit.check-secrets: ENABLED * Removing files Signed-off-by: Lukas Grossmann <[email protected]> --------- Signed-off-by: Martin Szuc <[email protected]> Signed-off-by: Lukas Grossmann <[email protected]> Co-authored-by: Martin Szuc <[email protected]> Co-authored-by: Lukas Grossmann <[email protected]>
1 parent 90dc3b9 commit 091863d

File tree

7 files changed

+201
-36
lines changed

7 files changed

+201
-36
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# This workflow will build a Java project with Gradle
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
3+
4+
name: Java CI with Gradle - mainidewindow.menubar
5+
6+
on:
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
12+
jobs:
13+
build-linux:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up JDK 17
19+
uses: actions/setup-java@v1
20+
with:
21+
java-version: 17
22+
- name: Run integration tests
23+
run: |
24+
export DISPLAY=:99.0
25+
Xvfb -ac :99 -screen 0 1920x1080x24 &
26+
cd src/test-project
27+
chmod +x gradlew
28+
./gradlew clean test --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.menubar.*
29+
- uses: actions/upload-artifact@v2
30+
with:
31+
name: ${{ runner.os }}-test-reports
32+
path: src/test-project/build/reports/tests/test
33+
if: always()
34+
- name: Archiving screenshots
35+
uses: actions/upload-artifact@v2
36+
with:
37+
name: ${{ runner.os }}-screenshots
38+
path: src/test-project/build/screenshots/*
39+
if: always()
40+
- name: Archiving StepLogger logs
41+
uses: actions/upload-artifact@v2
42+
with:
43+
name: ${{ runner.os }}-steplogger-logs
44+
path: src/test-project/build/test-results/*
45+
if: always()
46+
47+
48+
build-macos:
49+
runs-on: macos-11
50+
51+
steps:
52+
- uses: actions/checkout@v2
53+
- name: Set up JDK 17
54+
uses: actions/setup-java@v1
55+
with:
56+
java-version: 17
57+
- name: Run integration tests
58+
run: |
59+
cd src/test-project
60+
chmod +x gradlew
61+
./gradlew clean test --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.menubar.*
62+
- uses: actions/upload-artifact@v2
63+
with:
64+
name: ${{ runner.os }}-test-reports
65+
path: src/test-project/build/reports/tests/test
66+
if: always()
67+
- name: Archiving screenshots
68+
uses: actions/upload-artifact@v2
69+
with:
70+
name: ${{ runner.os }}-screenshots
71+
path: src/test-project/build/screenshots/*
72+
if: always()
73+
- name: Archiving StepLogger logs
74+
uses: actions/upload-artifact@v2
75+
with:
76+
name: ${{ runner.os }}-steplogger-logs
77+
path: src/test-project/build/test-results/*
78+
if: always()
79+
80+
81+
build-windows:
82+
runs-on: windows-latest
83+
84+
steps:
85+
- uses: actions/checkout@v2
86+
- name: Set up JDK 17
87+
uses: actions/setup-java@v1
88+
with:
89+
java-version: 17
90+
- name: Run integration tests
91+
run: |
92+
cd src\test-project
93+
chmod +x gradlew.bat
94+
.\gradlew.bat clean test --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.menubar.*
95+
shell: powershell
96+
- uses: actions/upload-artifact@v2
97+
with:
98+
name: ${{ runner.os }}-test-reports
99+
path: src\test-project\build\reports\tests\test
100+
if: always()
101+
- name: Archiving screenshots
102+
uses: actions/upload-artifact@v2
103+
with:
104+
name: ${{ runner.os }}-screenshots
105+
path: src\test-project\build\screenshots\*
106+
if: always()
107+
- name: Archiving StepLogger logs
108+
uses: actions/upload-artifact@v2
109+
with:
110+
name: ${{ runner.os }}-steplogger-logs
111+
path: src\test-project\build\test-results\*
112+
if: always()

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/FlatWelcomeFrame.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.settings.pages.NotificationsPage;
2323
import com.redhat.devtools.intellij.commonuitest.utils.constants.ButtonLabels;
2424
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
25-
import com.redhat.devtools.intellij.commonuitest.utils.internalerror.IdeInternalErrorUtils;
2625
import com.redhat.devtools.intellij.commonuitest.utils.runner.IntelliJVersion;
2726
import com.redhat.devtools.intellij.commonuitest.utils.steps.SharedSteps;
2827
import org.apache.commons.io.FileUtils;
@@ -69,6 +68,16 @@ public void createNewProject() {
6968
clickOnLink("New Project");
7069
}
7170

71+
/**
72+
* CLick on existing project from the Welcome Dialog
73+
*
74+
* @param projectName name of existing project
75+
*/
76+
public void openProject(String projectName) {
77+
JTreeFixture existingProjectFixture = find(JTreeFixture.class, byXpath("//div[contains(@visible_text, '" + projectName + "')]"), Duration.ofSeconds(2));
78+
existingProjectFixture.clickRow(0);
79+
}
80+
7281
/**
7382
* Click on the link according to given label
7483
*
@@ -150,28 +159,23 @@ public void openSettingsDialog() {
150159
* @return fixture for the 'Tip Of the Day' dialog
151160
*/
152161
public TipDialog openTipDialog() {
153-
if (ideaVersion <= 20202) { // IJ 2020.2 and older
162+
if (ideaVersion >= 20211) {
163+
FlatWelcomeFrame flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(2));
164+
if (ideaVersion >= 20223) { // COMMUNITY_V_2022_3 and higher version have different labels for Learn button
165+
flatWelcomeFrame.findText(ButtonLabels.LEARN_LABEL).click();
166+
} else {
167+
flatWelcomeFrame.findText(ButtonLabels.LEARN_INTELLIJ_IDEA_LABEL).click();
168+
}
169+
SharedSteps.waitForComponentByXpath(remoteRobot, 2, 1, byXpath(XPathDefinitions.TIP_DIALOG_2));
170+
flatWelcomeFrame.findText(TIP_OF_THE_DAY).click();
171+
} else if (ideaVersion <= 20202) {
154172
clickOnLink("Get Help");
155173
HeavyWeightWindowFixture heavyWeightWindowFixture = find(HeavyWeightWindowFixture.class, Duration.ofSeconds(5));
156174
heavyWeightWindowFixture.findText(TIP_OF_THE_DAY).click();
157175
} else if (ideaVersion == 20203) { // IJ 2020.3
158176
actionLink("Help").click();
159177
HeavyWeightWindowFixture heavyWeightWindowFixture = find(HeavyWeightWindowFixture.class, Duration.ofSeconds(5));
160178
heavyWeightWindowFixture.findText(TIP_OF_THE_DAY).click();
161-
} else if (ideaVersion <= 20212) { // IJ 2021.1 - IJ 2021.2
162-
JListFixture jListFixture = remoteRobot.find(JListFixture.class, byXpath(XPathDefinitions.JBLIST));
163-
jListFixture.findText(ButtonLabels.LEARN_LABEL).click();
164-
remoteRobot.find(JLabelFixture.class, byXpath(XPathDefinitions.TIP_DIALOG_2)).click();
165-
} else { // IJ 2021.3 and newer
166-
IdeInternalErrorUtils.clearWindowsErrorsIfTheyAppear(remoteRobot);
167-
FlatWelcomeFrame flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(2));
168-
if (ideaVersion >= 20223) { // learn label for IJ 2022.3 and newer
169-
flatWelcomeFrame.findText(ButtonLabels.LEARN_LABEL).click();
170-
} else { // learn label for IJ 2022.2 and older
171-
flatWelcomeFrame.findText(ButtonLabels.LEARN_INTELLIJ_IDEA_LABEL).click();
172-
}
173-
SharedSteps.waitForComponentByXpath(remoteRobot, 2, 1, byXpath(XPathDefinitions.TIP_DIALOG_2));
174-
flatWelcomeFrame.findText(TIP_OF_THE_DAY).click();
175179
}
176180

177181
return remoteRobot.find(TipDialog.class, Duration.ofSeconds(10));
@@ -273,4 +277,4 @@ private void removeTopProjectFromRecentProjects() {
273277
}
274278
}
275279
}
276-
}
280+
}

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/toolwindowspane/AbstractToolWinPane.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public void closeGradleBuildToolPane() {
9999
public JButtonFixture stripeButton(String label, boolean isPaneOpened) {
100100
if (isPaneOpened) {
101101
if (label.equals(ButtonLabels.MAVEN_STRIPE_BUTTON_LABEL) || label.equals(ButtonLabels.GRADLE_STRIPE_BUTTON_LABEL)) {
102-
if (UITestRunner.getIdeaVersionInt() >= 20221) { // Code for IntelliJ version 2022.1 and newer
102+
if (UITestRunner.getIdeaVersionInt() >= 20232) { // Code for IntelliJ version 2023.2 and newer
103103
return button(byXpath(XPathDefinitions.toolWindowButton(label)), Duration.ofSeconds(2));
104-
} else { // Code for IntelliJ versions 2021.3 and older
104+
} else { // Code for IntelliJ versions 2023.1 and older
105105
return button(byXpath(XPathDefinitions.toolWindowSvg(label)), Duration.ofSeconds(2));
106106
}
107107
} else if (label.equals(ButtonLabels.PROJECT_STRIPE_BUTTON_LABEL)) {
@@ -158,4 +158,4 @@ private boolean isStripeButtonAvailable(String label, boolean isPaneOpened) {
158158
}
159159
return true;
160160
}
161-
}
161+
}

src/main/java/com/redhat/devtools/intellij/commonuitest/utils/project/CreateCloseUtils.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ public static void createNewProject(RemoteRobot remoteRobot, String projectName,
8181

8282
newProjectDialogWizard.finish();
8383

84+
waitAfterOpeningProject(remoteRobot);
85+
}
86+
87+
/**
88+
* Wait after opening project for a complete import, also maximizing window
89+
*
90+
* @param remoteRobot reference to the RemoteRobot instance
91+
*/
92+
public static void waitAfterOpeningProject(RemoteRobot remoteRobot) {
8493
IdeStatusBar ideStatusBar = remoteRobot.find(IdeStatusBar.class, Duration.ofSeconds(10));
8594
ideStatusBar.waitUntilProjectImportIsComplete();
8695
MainIdeWindow mainIdeWindow = remoteRobot.find(MainIdeWindow.class, Duration.ofSeconds(5));
@@ -113,6 +122,19 @@ public static void closeProject(RemoteRobot remoteRobot) {
113122
remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10));
114123
}
115124

125+
/**
126+
* Open existing project from the Welcome Dialog
127+
*
128+
* @param remoteRobot reference to the RemoteRobot instance
129+
* @param projectName name of existing project
130+
*/
131+
public static void openProjectFromWelcomeDialog(RemoteRobot remoteRobot, String projectName) {
132+
FlatWelcomeFrame flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10));
133+
flatWelcomeFrame.openProject(projectName);
134+
135+
waitAfterOpeningProject(remoteRobot);
136+
}
137+
116138
/**
117139
* Get appropriate final page instance
118140
*

src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/project_manipulation/NewProjectDialogTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,16 @@ public void setProjectSdkIfAvailableTest() {
346346
public void selectNewProjectTypeTest() {
347347
newProjectFirstPage.selectNewProjectType("Empty Project");
348348
boolean isEmptyProjectPageDisplayed;
349-
if (ideaVersionInt < 20213) { // IJ 2021.2 and older
350-
isEmptyProjectPageDisplayed = !newProjectFirstPage.findAll(JListFixture.class, byXpath(XPathDefinitions.EMPTY_PROJECT)).isEmpty();
351-
} else if (ideaVersionInt < 20221) { // IJ 2021.3
352-
isEmptyProjectPageDisplayed = newProjectFirstPage.hasText("Simple project with one module");
353-
} else if (ideaVersionInt < 20231) { // IJ 2022.1-2022.3
354-
isEmptyProjectPageDisplayed = newProjectFirstPage.hasText("A basic project that allows working with separate files and compiling Java and Kotlin classes.");
355-
} else { // IJ 2023.1 and newer
349+
if (ideaVersionInt >= 20231) { // For IntelliJ IDEA version 2023.1 and newer
356350
isEmptyProjectPageDisplayed = newProjectFirstPage.hasText("A basic project with free structure.");
351+
} else if (ideaVersionInt >= 20221) { // For IntelliJ IDEA version 2022.1 and newer
352+
isEmptyProjectPageDisplayed = newProjectFirstPage.hasText("A basic project that allows working with separate files and compiling Java and Kotlin classes.");
353+
} else if (ideaVersionInt == 20213) { // For IntelliJ IDEA version 2021.3
354+
isEmptyProjectPageDisplayed = newProjectFirstPage.hasText("Simple project with one module");
355+
} else { // For IntelliJ IDEA version 2021.2 and older
356+
isEmptyProjectPageDisplayed = !newProjectFirstPage.findAll(
357+
JListFixture.class, byXpath(XPathDefinitions.EMPTY_PROJECT)
358+
).isEmpty();
357359
}
358360
assertTrue(isEmptyProjectPageDisplayed, "The 'Empty Project' page should be displayed but is not.");
359361

src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/mainidewindow/menubar/MenuBarTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@
1111
package com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.menubar;
1212

1313
import com.intellij.remoterobot.RemoteRobot;
14+
import com.intellij.remoterobot.fixtures.ComponentFixture;
1415
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
1516
import com.redhat.devtools.intellij.commonuitest.LibraryTestBase;
17+
import com.redhat.devtools.intellij.commonuitest.UITestRunner;
1618
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.information.TipDialog;
1719
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.menubar.MenuBar;
20+
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane.AbstractToolWinPane;
21+
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane.ProjectExplorer;
22+
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane.ToolWindowPane;
23+
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane.ToolWindowsPane;
1824
import com.redhat.devtools.intellij.commonuitest.utils.constants.ButtonLabels;
1925
import com.redhat.devtools.intellij.commonuitest.utils.project.CreateCloseUtils;
2026
import org.junit.jupiter.api.AfterAll;
@@ -23,6 +29,7 @@
2329

2430
import java.time.Duration;
2531

32+
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
2633
import static org.junit.jupiter.api.Assertions.assertTrue;
2734

2835
/**
@@ -33,6 +40,8 @@
3340
class MenuBarTest extends LibraryTestBase {
3441
private static final String PROJECT_NAME = "project_view_tree_java_project";
3542

43+
private static ProjectExplorer projectExplorer;
44+
3645
@BeforeAll
3746
public static void prepareProject() {
3847
CreateCloseUtils.createNewProject(remoteRobot, PROJECT_NAME, CreateCloseUtils.NewProjectType.PLAIN_JAVA);
@@ -52,6 +61,22 @@ public void openTipDialogUsingMenuBarTest() {
5261
}
5362
}
5463

64+
@Test
65+
public void closeAndReopenProjectTest() {
66+
CreateCloseUtils.closeProject(remoteRobot);
67+
CreateCloseUtils.openProjectFromWelcomeDialog(remoteRobot, PROJECT_NAME);
68+
69+
AbstractToolWinPane toolWinPane;
70+
if (UITestRunner.getIdeaVersionInt() >= 20221) {
71+
toolWinPane = remoteRobot.find(ToolWindowPane.class, Duration.ofSeconds(10));
72+
} else {
73+
toolWinPane = remoteRobot.find(ToolWindowsPane.class, Duration.ofSeconds(10));
74+
}
75+
toolWinPane.openProjectExplorer();
76+
projectExplorer = toolWinPane.find(ProjectExplorer.class, Duration.ofSeconds(10));
77+
assertTrue(projectExplorer.isItemPresent(PROJECT_NAME), "The project should be back open, but it is not");
78+
}
79+
5580
private boolean isTipDialogVisible(RemoteRobot remoteRobot) {
5681
try {
5782
remoteRobot.find(TipDialog.class, Duration.ofSeconds(10));

src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/mainidewindow/toolwindowspane/ProjectExplorerTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ public void isItemPresentTest() {
7979
@Test
8080
public void openFileTest() {
8181
projectExplorer.openFile(PROJECT_NAME, PROJECT_NAME + ".iml");
82-
83-
if (ideaVersionInt <= 20223) { // Code for IJ 2022.3 and older
82+
if (ideaVersionInt >= 20231) { // Code for IJ 2023.1+
83+
String projectLabelXpath = "//div[@accessiblename='" + PROJECT_NAME + ".iml' and @class='EditorTabLabel']//div[@class='ActionPanel']";
84+
try { // Verify file is opened by finding its tab in the editor
85+
remoteRobot.find(ComponentFixture.class, byXpath(projectLabelXpath));
86+
} catch (Exception e) {
87+
fail("The '" + PROJECT_NAME + ".iml' file should be opened but is not.");
88+
}
89+
} else {
8490
List<ContainerFixture> cfs = remoteRobot.findAll(ContainerFixture.class, byXpath(XPathDefinitions.SINGLE_HEIGHT_LABEL));
8591
ContainerFixture cf = cfs.get(cfs.size() - 1);
8692
String allText = TextUtils.listOfRemoteTextToString(cf.findAllText());
8793
boolean isFileOpened = allText.contains(PROJECT_NAME + ".iml");
8894
assertTrue(isFileOpened, "The '" + PROJECT_NAME + ".iml' file should be opened but is not.");
89-
} else { // Code for IJ 2023.1 and newer
90-
try {
91-
SharedSteps.waitForComponentByXpath(remoteRobot, 20, 1, byXpath(XPathDefinitions.editorTabLabel(PROJECT_NAME + ".iml")));
92-
} catch (Exception e) {
93-
fail("The '" + PROJECT_NAME + ".iml' file should be opened but is not.");
94-
}
9595
}
9696
}
9797

@@ -152,4 +152,4 @@ public void openSettingsPopupTest() {
152152
fail(e.getMessage());
153153
}
154154
}
155-
}
155+
}

0 commit comments

Comments
 (0)