Skip to content

Commit

Permalink
Merge pull request #275 from martinszuc/issue-273
Browse files Browse the repository at this point in the history
feat: create EMPTY PROJECT methods #273
  • Loading branch information
martinszuc authored Jul 30, 2024
2 parents 3b31379 + 95a2da4 commit 9e097f8
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 10 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,23 @@ runIdeForUiTests {
systemProperty "robot-server.port", System.getProperty("robot-server.port")
}
```
### STEP #5: Test project location
## Additional Features

### Creating a Project

**Creating an Empty Project:**
Use the following method to create an empty project with a specified name:

```java
CreateCloseUtils.createEmptyProject(remoteRobot, "empty-test-project");
```
**Creating a New Project with a Specific Type:**
You can also create a new project with a specific type, such as Java, Maven, or Gradle:
```java
CreateCloseUtils.createNewProject(remoteRobot, "new-test-project", CreateCloseUtils.NewProjectType.PLAIN_JAVA);
```
### Test project location
Default test project location is `/home/user/IdeaProjects/intellij-ui-test-projects/`.
Developers can specify the location where the test project will be created by providing a system property called `testProjectLocation`. For example:
```
task integrationTest(type: Test) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ 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)) {
if (UITestRunner.getIdeaVersionInt() >= 20232) { // Code for IntelliJ version 2023.2 and newer
if (UITestRunner.getIdeaVersionInt() >= 20223) { // Code for IntelliJ version 2022.3 and newer
return button(byXpath(XPathDefinitions.toolWindowButton(label)), Duration.ofSeconds(2));
} else { // Code for IntelliJ versions 2023.1 and older
} else { // Code for IntelliJ versions 2022.2 and older
return button(byXpath(XPathDefinitions.toolWindowSvg(label)), Duration.ofSeconds(2));
}
} else if (label.equals(ButtonLabels.PROJECT_STRIPE_BUTTON_LABEL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ButtonLabels {
public static final String LEARN_INTELLIJ_IDEA_LABEL = "Learn IntelliJ IDEA";
public static final String LEARN_LABEL = "Learn";
public static final String REMOVE_FROM_LIST_LABEL = "Remove From List";
public static final String NEW_PROJECT = "New Project";

private ButtonLabels() {
throw new UITestException("Utility class with static methods.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ public static void createNewProject(RemoteRobot remoteRobot, String projectName,
waitAfterOpeningProject(remoteRobot);
}

/**
* Create new empty type project with given project name
*
* @param remoteRobot reference to the RemoteRobot instance
* @param projectName name of new project
*/
public static void createEmptyProject(RemoteRobot remoteRobot, String projectName) {
NewProjectDialogWizard newProjectDialogWizard = openNewProjectDialogFromWelcomeDialog(remoteRobot);
NewProjectFirstPage newProjectFirstPage = newProjectDialogWizard.find(NewProjectFirstPage.class, Duration.ofSeconds(10));

newProjectFirstPage.selectNewProjectType(NewProjectType.EMPTY_PROJECT.toString());

newProjectFirstPage.setProjectName(projectName);
newProjectFirstPage.setProjectLocation(PROJECT_LOCATION);

newProjectDialogWizard.finish();
waitAfterOpeningProject(remoteRobot);
}

/**
* Wait after opening project for a complete import, also maximizing window
*
Expand Down Expand Up @@ -166,7 +185,8 @@ public static AbstractNewProjectFinalPage getFinalPage(NewProjectDialogWizard ne
public enum NewProjectType {
PLAIN_JAVA("Java"),
MAVEN("Maven"),
GRADLE("Gradle");
GRADLE("Gradle"),
EMPTY_PROJECT("Empty Project");

private final String projectType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void cleanUp() {
} else {
try {
// tests ending with opened New Project Dialog needs to close the dialog
newProjectDialogWizard.cancel();
remoteRobot.find(NewProjectDialogWizard.class).cancel();
} catch (WaitForConditionTimeoutException e) {
// tests ending with opened Flat Welcome Frame does not need any assistance
}
Expand Down Expand Up @@ -359,11 +359,7 @@ JListFixture.class, byXpath(XPathDefinitions.EMPTY_PROJECT)
}
assertTrue(isEmptyProjectPageDisplayed, "The 'Empty Project' page should be displayed but is not.");

if (UITestRunner.getIdeaVersionInt() >= 20221) {
newProjectFirstPage.selectNewProjectType("New Project");
} else {
newProjectFirstPage.selectNewProjectType("Java");
}
selectJavaNewProjectType();

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

private void selectJavaNewProjectType() {
newProjectFirstPage = remoteRobot.find(NewProjectFirstPage.class, Duration.ofSeconds(10));
if (UITestRunner.getIdeaVersionInt() >= 20221) {
newProjectFirstPage.selectNewProjectType("New Project");
} else {
newProjectFirstPage.selectNewProjectType("Java");
}
}

@Test
public void createEmptyProjectTest() {
cleanUp();
String projectName = "empty-test-project";
CreateCloseUtils.createEmptyProject(remoteRobot, projectName);
mainIdeWindow = remoteRobot.find(MainIdeWindow.class, Duration.ofSeconds(60));
assertTrue(mainIdeWindow.isShowing(), "The Main IDE Window should be open after creating an empty project.");

mainIdeWindow.closeProject();
mainIdeWindow = null;

// IntelliJ remembers the last chosen project language, for continuity with other tests select Java project
FlatWelcomeFrame flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10));
flatWelcomeFrame.clearWorkspace();
flatWelcomeFrame.createNewProject();
selectJavaNewProjectType();
remoteRobot.find(NewProjectDialogWizard.class).cancel();
}

private void navigateToSetProjectNamePage(CreateCloseUtils.NewProjectType newProjectType) {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
newProjectFirstPage.setBuildSystem(newProjectType.toString().equals("Java") ? "IntelliJ" : newProjectType.toString());
Expand Down

0 comments on commit 9e097f8

Please sign in to comment.