Skip to content

Commit 66e40c8

Browse files
authored
Eliminate duplicate implementations of repeating test steps, refactor (#49)
1 parent 0fc5984 commit 66e40c8

File tree

11 files changed

+260
-159
lines changed

11 files changed

+260
-159
lines changed

src/main/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixtures/mainIdeWindow/menuBar/MenuBar.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import com.intellij.remoterobot.RemoteRobot;
1414
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
15-
import com.intellij.remoterobot.fixtures.ContainerFixture;
1615
import com.intellij.remoterobot.fixtures.JButtonFixture;
1716
import com.intellij.remoterobot.fixtures.JPopupMenuFixture;
1817
import com.redhat.devtools.intellij.commonUiTestLibrary.UITestRunner;
@@ -64,11 +63,6 @@ public void navigateTo(String... path) {
6463
lastContextMenu.findText((path[path.length - 1])).click();
6564
}
6665

67-
/**
68-
* Create fixture for main menu item
69-
*
70-
* @param label label text
71-
*/
7266
private JButtonFixture mainMenuItem(String label) {
7367
if (remoteRobot.isMac()) {
7468
return null;

src/main/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixtures/mainIdeWindow/toolWindowsPane/ToolWindowsPane.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,6 @@ public JButtonFixture stripeButton(String label) {
6565
return button(byXpath("//div[@text='" + label + "']"), Duration.ofSeconds(2));
6666
}
6767

68-
/**
69-
* Create fixture for the options tree in the 'Maven' right side panel
70-
*
71-
* @return fixture for the options tree in the 'Maven' right side panel
72-
*/
73-
public JTreeFixture mavenTabTree() {
74-
return find(JTreeFixture.class, byXpath("//div[@class='SimpleTree']"));
75-
}
76-
77-
/**
78-
* Create fixture for the options tree in the 'Gradle' right side panel
79-
*
80-
* @return fixture for the options tree in the 'Gradle' right side panel
81-
*/
82-
public JTreeFixture gradleTabTree() {
83-
return find(JTreeFixture.class, byXpath("//div[@class='ExternalProjectTree']"));
84-
}
85-
8668
/**
8769
* Build the project
8870
*
@@ -120,7 +102,7 @@ public void buildProject(ToolToBuildProject toolToBuildProject) {
120102
* @param path path to navigate to
121103
* @return true if the given file exists on the given path in the project
122104
*/
123-
public boolean isAProjectFilePresent(String... path) {
105+
public boolean isProjectFilePresent(String... path) {
124106
try {
125107
navigateThroughProjectTree(ActionToPerform.HIGHLIGHT, path);
126108
} catch (NoSuchElementException e) {
@@ -157,15 +139,18 @@ public String toString() {
157139
}
158140
}
159141

160-
/**
161-
* Create fixture for the ProjectViewTree
162-
*
163-
* @return fixture for the ProjectViewTree
164-
*/
165-
public JTreeFixture projectViewTree() {
142+
private JTreeFixture projectViewTree() {
166143
return find(JTreeFixture.class, JTreeFixture.Companion.byType(), Duration.ofSeconds(10));
167144
}
168145

146+
private JTreeFixture mavenTabTree() {
147+
return find(JTreeFixture.class, byXpath("//div[@class='SimpleTree']"));
148+
}
149+
150+
private JTreeFixture gradleTabTree() {
151+
return find(JTreeFixture.class, byXpath("//div[@class='ExternalProjectTree']"));
152+
}
153+
169154
private void expandMavenTargetTreeIfNecessary() {
170155
ToolWindowsPane toolWindowsPane = remoteRobot.find(ToolWindowsPane.class, Duration.ofSeconds(10));
171156
try {

src/test-project/src/test/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixturesTest/dialogs/FlatWelcomeFrameTest.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
import com.intellij.remoterobot.fixtures.JListFixture;
1414
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
1515
import com.redhat.devtools.intellij.commonUiTestLibrary.LibraryTestBase;
16+
import com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.dialogs.projectManipulation.NewProjectDialog;
1617
import com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.mainIdeWindow.MainIdeWindow;
1718
import com.redhat.devtools.intellij.commonUiTestLibrary.utils.testExtension.ScreenshotAfterTestFailExtension;
1819
import com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.dialogs.FlatWelcomeFrame;
1920
import org.apache.commons.io.filefilter.FileFilterUtils;
20-
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.AfterEach;
2122
import org.junit.jupiter.api.Test;
2223
import org.junit.jupiter.api.extension.ExtendWith;
2324

@@ -36,18 +37,25 @@
3637
@ExtendWith(ScreenshotAfterTestFailExtension.class)
3738
class FlatWelcomeFrameTest extends LibraryTestBase {
3839
private final String projectName = "welcome_frame_java_project";
40+
private FlatWelcomeFrame flatWelcomeFrame;
3941

40-
@BeforeEach
41-
public void prepareProject() {
42-
createNewProject(projectName, "Java");
42+
@AfterEach
43+
public void cleanUp() {
44+
flatWelcomeFrame.clearWorkspace();
4345
}
4446

4547
@Test
46-
public void flatWelcomeFrameTest() {
47-
MainIdeWindow mainIdeWindow = remoteRobot.find(MainIdeWindow.class, Duration.ofSeconds(10));
48-
mainIdeWindow.closeProject();
48+
public void createNewProjectLinkTest() {
49+
flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10));
50+
flatWelcomeFrame.createNewProject();
51+
NewProjectDialog newProjectDialog = remoteRobot.find(NewProjectDialog.class, Duration.ofSeconds(10));
52+
newProjectDialog.cancel();
53+
}
4954

50-
FlatWelcomeFrame flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10));
55+
@Test
56+
public void clearWorkspaceTest() {
57+
prepareWorkspace();
58+
flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10));
5159
int projectsOnDisk = getNumberOfProjectsOnDisk();
5260
int projectLinks = getNumberOfProjectLinksInFlatWelcomeFrame();
5361
assertTrue(projectsOnDisk == 1, "Number of projects in the IntelliJ's project folder should be 1 but is " + projectsOnDisk + ".");
@@ -59,6 +67,19 @@ public void flatWelcomeFrameTest() {
5967
assertTrue(projectLinks2 == 0, "Number of projects' links in the IntelliJ's 'Welcome Frame Dialog' should be 0 but is " + projectLinks2 + ".");
6068
}
6169

70+
@Test
71+
public void clearExceptionsTest() {
72+
prepareWorkspace();
73+
flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10));
74+
flatWelcomeFrame.clearExceptions();
75+
}
76+
77+
private void prepareWorkspace() {
78+
createNewProject(projectName, "Java");
79+
MainIdeWindow mainIdeWindow = remoteRobot.find(MainIdeWindow.class, Duration.ofSeconds(10));
80+
mainIdeWindow.closeProject();
81+
}
82+
6283
private int getNumberOfProjectsOnDisk() {
6384
String pathToIdeaProjectsFolder = System.getProperty("user.home") + File.separator + "IdeaProjects";
6485
File[] files = new File(pathToIdeaProjectsFolder).listFiles((FileFilter) FileFilterUtils.directoryFileFilter());

src/test-project/src/test/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixturesTest/dialogs/navigation/ProjectStructureAndTipDialogs.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ public static void closeProject() {
4343
LibraryTestBase.closeProject();
4444
}
4545

46-
private void dialogTest(Runnable selectedImpl, Class dialogClass, String dialogTitle) {
47-
makeSureDialogIsVisible(dialogClass, dialogTitle);
48-
assertTrue(isDialogVisible(dialogClass), "The '" + dialogTitle + "' dialog should be visible but is not.");
49-
selectedImpl.run();
50-
assertTrue(!isDialogVisible(dialogClass), "The '" + dialogTitle + "' dialog should be visible but is not.");
51-
IdeStatusBar ideStatusBar = remoteRobot.find(IdeStatusBar.class, Duration.ofSeconds(10));
52-
ideStatusBar.waitUntilAllBgTasksFinish();
53-
}
54-
5546
@Test
5647
public void projectStructureDialogTest() {
5748
dialogTest(() -> {
@@ -67,6 +58,15 @@ public void tipDialogTest() {
6758
}, TipDialog.class, "Tip of the Day");
6859
}
6960

61+
private void dialogTest(Runnable selectedImpl, Class dialogClass, String dialogTitle) {
62+
makeSureDialogIsVisible(dialogClass, dialogTitle);
63+
assertTrue(isDialogVisible(dialogClass), "The '" + dialogTitle + "' dialog should be visible but is not.");
64+
selectedImpl.run();
65+
assertTrue(!isDialogVisible(dialogClass), "The '" + dialogTitle + "' dialog should be visible but is not.");
66+
IdeStatusBar ideStatusBar = remoteRobot.find(IdeStatusBar.class, Duration.ofSeconds(10));
67+
ideStatusBar.waitUntilAllBgTasksFinish();
68+
}
69+
7070
private void makeSureDialogIsVisible(Class dialogClass, String dialogTitle) {
7171
try {
7272
remoteRobot.find(dialogClass, Duration.ofSeconds(10));

src/test-project/src/test/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixturesTest/dialogs/projectManipulation/NewProjectDialogTest.java

Lines changed: 102 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,27 @@
1010
******************************************************************************/
1111
package com.redhat.devtools.intellij.commonUiTestLibrary.fixturesTest.dialogs.projectManipulation;
1212

13+
import com.intellij.remoterobot.fixtures.ComboBoxFixture;
14+
import com.intellij.remoterobot.fixtures.JLabelFixture;
15+
import com.intellij.remoterobot.fixtures.JListFixture;
1316
import com.intellij.remoterobot.fixtures.JTextFieldFixture;
17+
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
1418
import com.redhat.devtools.intellij.commonUiTestLibrary.LibraryTestBase;
19+
import com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.dialogs.FlatWelcomeFrame;
20+
import com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.mainIdeWindow.MainIdeWindow;
21+
import com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.mainIdeWindow.ideStatusBar.IdeStatusBar;
1522
import com.redhat.devtools.intellij.commonUiTestLibrary.utils.testExtension.ScreenshotAfterTestFailExtension;
1623
import com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.dialogs.projectManipulation.NewProjectDialog;
24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.BeforeEach;
1726
import org.junit.jupiter.api.Test;
1827
import org.junit.jupiter.api.extension.ExtendWith;
1928

2029
import java.time.Duration;
2130

31+
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
32+
import static com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.dialogs.information.TipDialog.closeTipDialogIfItAppears;
33+
import static com.redhat.devtools.intellij.commonUiTestLibrary.utils.textTranformation.TextUtils.listOfRemoteTextToString;
2234
import static org.junit.jupiter.api.Assertions.assertTrue;
2335

2436
/**
@@ -32,40 +44,112 @@ public class NewProjectDialogTest extends LibraryTestBase {
3244
private final String mavenProjectName = "maven_project_name_test";
3345
private final String gradleProjectName = "gradle_project_name_test";
3446

47+
private NewProjectDialog newProjectDialog;
48+
49+
@BeforeEach
50+
public void openNewProjectDialog() {
51+
openNewProjectDialogFromWelcomeDialog();
52+
newProjectDialog = remoteRobot.find(NewProjectDialog.class, Duration.ofSeconds(10));
53+
}
54+
55+
@AfterEach
56+
public void cleanUp() {
57+
try {
58+
// tests ending with opened New Project Dialog needs to close the dialog
59+
remoteRobot.find(NewProjectDialog.class, Duration.ofSeconds(10)).cancel();
60+
} catch (WaitForConditionTimeoutException e) {
61+
try {
62+
// tests ending with opened Main Ide Window needs to close the project and clear workspace
63+
remoteRobot.find(MainIdeWindow.class, Duration.ofSeconds(5));
64+
closeProject();
65+
FlatWelcomeFrame flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10));
66+
flatWelcomeFrame.clearWorkspace();
67+
} catch (WaitForConditionTimeoutException e2) {
68+
// tests ending with opened Flat Welcome Frame does not need any assistance
69+
}
70+
}
71+
}
72+
3573
@Test
36-
public void newProjectDialogJavaTest() {
37-
testProjectDialog(NewProjectType.PLAIN_JAVA, plainJavaProjectName);
74+
public void setProjectNamePlainJavaProjectTest() {
75+
testProjectNameInputField(plainJavaProjectName, NewProjectType.PLAIN_JAVA);
3876
}
3977

4078
@Test
41-
public void newProjectDialogMavenTest() {
42-
testProjectDialog(NewProjectType.MAVEN, mavenProjectName);
79+
public void setProjectNameMavenProjectTest() {
80+
testProjectNameInputField(mavenProjectName, NewProjectType.MAVEN);
4381
}
4482

4583
@Test
46-
public void newProjectDialogGradleTest() {
47-
testProjectDialog(NewProjectType.GRADLE, gradleProjectName);
84+
public void setProjectNameGradleProjectTest() {
85+
testProjectNameInputField(gradleProjectName, NewProjectType.GRADLE);
4886
}
4987

50-
private void testProjectDialog(NewProjectType newProjectType, String projectName) {
51-
openNewProjectDialogFromWelcomeDialog();
52-
NewProjectDialog newProjectDialog = remoteRobot.find(NewProjectDialog.class, Duration.ofSeconds(10));
53-
newProjectDialog.selectNewProjectType(newProjectType.toString());
88+
@Test
89+
public void nextPreviousFinishButtonTest() {
90+
newProjectDialog.selectNewProjectType("Java");
91+
newProjectDialog.setProjectSdkIfAvailable("11");
92+
newProjectDialog.next();
93+
newProjectDialog.next();
94+
boolean isProjectNameLabelPresent = newProjectDialog.findAll(JLabelFixture.class, byXpath("//div[@text='Project name:']")).size() == 1;
95+
assertTrue(isProjectNameLabelPresent, "The 'Project name:' label should be present but is not.");
96+
newProjectDialog.previous();
97+
boolean isCommandLineAppTextPresent = listOfRemoteTextToString(newProjectDialog.findAllText()).contains("Command Line App");
98+
assertTrue(isCommandLineAppTextPresent, "The 'Command Line App' text should be present but is not.");
5499
newProjectDialog.next();
100+
newProjectDialog.setProjectName(plainJavaProjectName);
101+
newProjectDialog.finish();
102+
IdeStatusBar ideStatusBar = remoteRobot.find(IdeStatusBar.class, Duration.ofSeconds(10));
103+
ideStatusBar.waitUntilProjectImportIsComplete();
104+
closeTipDialogIfItAppears(remoteRobot);
105+
MainIdeWindow mainIdeWindow = remoteRobot.find(MainIdeWindow.class, Duration.ofSeconds(5));
106+
mainIdeWindow.maximizeIdeWindow();
107+
ideStatusBar.waitUntilAllBgTasksFinish();
108+
}
109+
110+
@Test
111+
public void cancelButtonTest() {
112+
newProjectDialog.cancel();
113+
remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10));
114+
}
55115

56-
String projectNameFromInputField;
116+
@Test
117+
public void setProjectSdkIfAvailableTest() {
118+
newProjectDialog.selectNewProjectType("Java");
119+
newProjectDialog.setProjectSdkIfAvailable("8");
120+
ComboBoxFixture projectJdkComboBox = remoteRobot.find(ComboBoxFixture.class, byXpath("//div[@accessiblename='Project SDK:' and @class='JPanel']/div[@class='JdkComboBox']"), Duration.ofSeconds(10));
121+
String currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText());
122+
assertTrue(currentlySelectedProjectSdk.contains("8"), "Selected project SDK should be Java 8 but is '" + currentlySelectedProjectSdk + "'");
123+
newProjectDialog.setProjectSdkIfAvailable("11");
124+
currentlySelectedProjectSdk = listOfRemoteTextToString(projectJdkComboBox.findAllText());
125+
assertTrue(currentlySelectedProjectSdk.contains("11"), "Selected project SDK should be Java 11 but is '" + currentlySelectedProjectSdk + "'");
126+
}
127+
128+
@Test
129+
public void selectNewProjectTypeTest() {
130+
newProjectDialog.selectNewProjectType("Empty Project");
131+
boolean isEmptyProjectLabelVisible = !newProjectDialog.findAll(JListFixture.class, byXpath("//div[@visible_text='Empty Project']")).isEmpty();
132+
assertTrue(isEmptyProjectLabelVisible, "The 'Empty Project' label should be visible but is not.");
133+
134+
newProjectDialog.selectNewProjectType("Java FX");
135+
boolean isJavaFXApplicationLabelVisible = !newProjectDialog.findAll(JListFixture.class, byXpath("//div[@visible_text='JavaFX Application']")).isEmpty();
136+
assertTrue(isJavaFXApplicationLabelVisible, "The 'Java FX' label should be visible but is not.");
137+
}
138+
139+
private void navigateToSetProjectNamePage(NewProjectType newProjectType) {
140+
newProjectDialog.selectNewProjectType(newProjectType.toString());
141+
newProjectDialog.next();
57142
if (newProjectType == NewProjectType.PLAIN_JAVA) {
58143
newProjectDialog.next();
59144
}
145+
}
146+
147+
private void testProjectNameInputField(String projectName, NewProjectType newProjectType) {
148+
navigateToSetProjectNamePage(newProjectType);
149+
NewProjectDialog newProjectDialog = remoteRobot.find(NewProjectDialog.class, Duration.ofSeconds(10));
60150
newProjectDialog.setProjectName(projectName);
61-
projectNameFromInputField = remoteRobot.findAll(JTextFieldFixture.class, JTextFieldFixture.Companion.byType()).get(0).getText();
151+
String projectNameFromInputField = remoteRobot.findAll(JTextFieldFixture.class, JTextFieldFixture.Companion.byType()).get(0).getText();
62152
assertTrue(projectName.equals(projectNameFromInputField), "Project name in the input field (" + projectNameFromInputField + ") is different from the expected project name (" + projectName + ").");
63-
64-
newProjectDialog.previous();
65-
if (newProjectType == NewProjectType.PLAIN_JAVA) {
66-
newProjectDialog.previous();
67-
}
68-
newProjectDialog.cancel();
69153
}
70154

71155
private enum NewProjectType {

src/test-project/src/test/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixturesTest/mainIdeWindow/ideStatusBar/IdeStatusBarTest.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.dialogs.projectManipulation.NewProjectDialog;
1818
import com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.mainIdeWindow.ideStatusBar.IdeStatusBar;
1919
import org.junit.jupiter.api.AfterEach;
20+
import org.junit.jupiter.api.BeforeEach;
2021
import org.junit.jupiter.api.Test;
2122
import org.junit.jupiter.api.extension.ExtendWith;
2223

@@ -36,33 +37,35 @@
3637
class IdeStatusBarTest extends LibraryTestBase {
3738
private final String projectName = "ide_status_bar_java_project";
3839

39-
@AfterEach
40-
public void closeCurrentProject() {
41-
super.closeProject();
42-
}
43-
44-
@Test
45-
public void ideStatusBarTest() {
40+
@BeforeEach
41+
public void prepareProject() {
4642
openNewProjectDialogFromWelcomeDialog();
4743
NewProjectDialog newProjectDialog = remoteRobot.find(NewProjectDialog.class, Duration.ofSeconds(10));
4844
newProjectDialog.selectNewProjectType("Maven");
4945
newProjectDialog.next();
5046
newProjectDialog.setProjectName(projectName);
5147
newProjectDialog.finish();
48+
}
5249

53-
waitFor(Duration.ofSeconds(60), Duration.ofSeconds(1), "The progress bar in status bar did not appear in 60 seconds.", () -> isProgressbarWithLabelVisible());
54-
IdeStatusBar ideStatusBar = remoteRobot.find(IdeStatusBar.class, Duration.ofSeconds(10));
50+
@AfterEach
51+
public void closeCurrentProject() {
52+
super.closeProject();
53+
}
54+
55+
@Test
56+
public void progressBarTest() {
57+
IdeStatusBar ideStatusBar = waitFor(Duration.ofSeconds(60), Duration.ofSeconds(1), "The progress bar in status bar did not appear in 60 seconds.", () -> isProgressbarWithLabelVisible());
5558
ideStatusBar.waitUntilProjectImportIsComplete();
5659
closeTipDialogIfItAppears(remoteRobot);
5760
MainIdeWindow mainIdeWindow = remoteRobot.find(MainIdeWindow.class, Duration.ofSeconds(5));
5861
mainIdeWindow.maximizeIdeWindow();
5962
ideStatusBar.waitUntilAllBgTasksFinish();
6063
}
6164

62-
private static boolean isProgressbarWithLabelVisible() {
65+
private static kotlin.Pair<Boolean, IdeStatusBar> isProgressbarWithLabelVisible() {
6366
IdeStatusBar ideStatusBar = remoteRobot.find(IdeStatusBar.class, Duration.ofSeconds(10));
6467
List<RemoteText> inlineProgressPanelContent = ideStatusBar.inlineProgressPanel().findAllText();
6568
String inlineProgressPanelText = listOfRemoteTextToString(inlineProgressPanelContent);
66-
return !inlineProgressPanelText.equals("");
69+
return new kotlin.Pair(!inlineProgressPanelText.equals(""), ideStatusBar);
6770
}
6871
}

0 commit comments

Comments
 (0)