Skip to content

Commit 9e097f8

Browse files
authored
Merge pull request #275 from martinszuc/issue-273
feat: create EMPTY PROJECT methods #273
2 parents 3b31379 + 95a2da4 commit 9e097f8

File tree

5 files changed

+71
-10
lines changed

5 files changed

+71
-10
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,23 @@ runIdeForUiTests {
6565
systemProperty "robot-server.port", System.getProperty("robot-server.port")
6666
}
6767
```
68-
### STEP #5: Test project location
68+
## Additional Features
69+
70+
### Creating a Project
71+
72+
**Creating an Empty Project:**
73+
Use the following method to create an empty project with a specified name:
74+
75+
```java
76+
CreateCloseUtils.createEmptyProject(remoteRobot, "empty-test-project");
77+
```
78+
**Creating a New Project with a Specific Type:**
79+
You can also create a new project with a specific type, such as Java, Maven, or Gradle:
80+
```java
81+
CreateCloseUtils.createNewProject(remoteRobot, "new-test-project", CreateCloseUtils.NewProjectType.PLAIN_JAVA);
82+
```
83+
### Test project location
84+
Default test project location is `/home/user/IdeaProjects/intellij-ui-test-projects/`.
6985
Developers can specify the location where the test project will be created by providing a system property called `testProjectLocation`. For example:
7086
```
7187
task integrationTest(type: Test) {

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

Lines changed: 2 additions & 2 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() >= 20232) { // Code for IntelliJ version 2023.2 and newer
102+
if (UITestRunner.getIdeaVersionInt() >= 20223) { // Code for IntelliJ version 2022.3 and newer
103103
return button(byXpath(XPathDefinitions.toolWindowButton(label)), Duration.ofSeconds(2));
104-
} else { // Code for IntelliJ versions 2023.1 and older
104+
} else { // Code for IntelliJ versions 2022.2 and older
105105
return button(byXpath(XPathDefinitions.toolWindowSvg(label)), Duration.ofSeconds(2));
106106
}
107107
} else if (label.equals(ButtonLabels.PROJECT_STRIPE_BUTTON_LABEL)) {

src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/ButtonLabels.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class ButtonLabels {
3636
public static final String LEARN_INTELLIJ_IDEA_LABEL = "Learn IntelliJ IDEA";
3737
public static final String LEARN_LABEL = "Learn";
3838
public static final String REMOVE_FROM_LIST_LABEL = "Remove From List";
39+
public static final String NEW_PROJECT = "New Project";
3940

4041
private ButtonLabels() {
4142
throw new UITestException("Utility class with static methods.");

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ public static void createNewProject(RemoteRobot remoteRobot, String projectName,
9090
waitAfterOpeningProject(remoteRobot);
9191
}
9292

93+
/**
94+
* Create new empty type project with given project name
95+
*
96+
* @param remoteRobot reference to the RemoteRobot instance
97+
* @param projectName name of new project
98+
*/
99+
public static void createEmptyProject(RemoteRobot remoteRobot, String projectName) {
100+
NewProjectDialogWizard newProjectDialogWizard = openNewProjectDialogFromWelcomeDialog(remoteRobot);
101+
NewProjectFirstPage newProjectFirstPage = newProjectDialogWizard.find(NewProjectFirstPage.class, Duration.ofSeconds(10));
102+
103+
newProjectFirstPage.selectNewProjectType(NewProjectType.EMPTY_PROJECT.toString());
104+
105+
newProjectFirstPage.setProjectName(projectName);
106+
newProjectFirstPage.setProjectLocation(PROJECT_LOCATION);
107+
108+
newProjectDialogWizard.finish();
109+
waitAfterOpeningProject(remoteRobot);
110+
}
111+
93112
/**
94113
* Wait after opening project for a complete import, also maximizing window
95114
*
@@ -166,7 +185,8 @@ public static AbstractNewProjectFinalPage getFinalPage(NewProjectDialogWizard ne
166185
public enum NewProjectType {
167186
PLAIN_JAVA("Java"),
168187
MAVEN("Maven"),
169-
GRADLE("Gradle");
188+
GRADLE("Gradle"),
189+
EMPTY_PROJECT("Empty Project");
170190

171191
private final String projectType;
172192

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void cleanUp() {
8282
} else {
8383
try {
8484
// tests ending with opened New Project Dialog needs to close the dialog
85-
newProjectDialogWizard.cancel();
85+
remoteRobot.find(NewProjectDialogWizard.class).cancel();
8686
} catch (WaitForConditionTimeoutException e) {
8787
// tests ending with opened Flat Welcome Frame does not need any assistance
8888
}
@@ -359,11 +359,7 @@ JListFixture.class, byXpath(XPathDefinitions.EMPTY_PROJECT)
359359
}
360360
assertTrue(isEmptyProjectPageDisplayed, "The 'Empty Project' page should be displayed but is not.");
361361

362-
if (UITestRunner.getIdeaVersionInt() >= 20221) {
363-
newProjectFirstPage.selectNewProjectType("New Project");
364-
} else {
365-
newProjectFirstPage.selectNewProjectType("Java");
366-
}
362+
selectJavaNewProjectType();
367363

368364
boolean isProjectSDKLabelVisible;
369365
if (UITestRunner.getIdeaVersionInt() >= 20221) {
@@ -374,6 +370,34 @@ JListFixture.class, byXpath(XPathDefinitions.EMPTY_PROJECT)
374370
assertTrue(isProjectSDKLabelVisible, "The 'Project SDK:' label should be visible but is not.");
375371
}
376372

373+
private void selectJavaNewProjectType() {
374+
newProjectFirstPage = remoteRobot.find(NewProjectFirstPage.class, Duration.ofSeconds(10));
375+
if (UITestRunner.getIdeaVersionInt() >= 20221) {
376+
newProjectFirstPage.selectNewProjectType("New Project");
377+
} else {
378+
newProjectFirstPage.selectNewProjectType("Java");
379+
}
380+
}
381+
382+
@Test
383+
public void createEmptyProjectTest() {
384+
cleanUp();
385+
String projectName = "empty-test-project";
386+
CreateCloseUtils.createEmptyProject(remoteRobot, projectName);
387+
mainIdeWindow = remoteRobot.find(MainIdeWindow.class, Duration.ofSeconds(60));
388+
assertTrue(mainIdeWindow.isShowing(), "The Main IDE Window should be open after creating an empty project.");
389+
390+
mainIdeWindow.closeProject();
391+
mainIdeWindow = null;
392+
393+
// IntelliJ remembers the last chosen project language, for continuity with other tests select Java project
394+
FlatWelcomeFrame flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10));
395+
flatWelcomeFrame.clearWorkspace();
396+
flatWelcomeFrame.createNewProject();
397+
selectJavaNewProjectType();
398+
remoteRobot.find(NewProjectDialogWizard.class).cancel();
399+
}
400+
377401
private void navigateToSetProjectNamePage(CreateCloseUtils.NewProjectType newProjectType) {
378402
if (UITestRunner.getIdeaVersionInt() >= 20221) {
379403
newProjectFirstPage.setBuildSystem(newProjectType.toString().equals("Java") ? "IntelliJ" : newProjectType.toString());

0 commit comments

Comments
 (0)