Skip to content

Commit

Permalink
Added: custom test-project project location (#185)
Browse files Browse the repository at this point in the history
Updated README

Signed-off-by: Martin Szuc <mszuc@redhat.com>
  • Loading branch information
martinszuc committed Feb 14, 2024
1 parent c9d89aa commit 90dc3b9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ runIdeForUiTests {
systemProperty "robot-server.port", System.getProperty("robot-server.port")
}
```
### STEP #5: Test project location
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) {
...
systemProperties['testProjectLocation'] = '/home/user/IdeaProjects/intellij-ui-test-projects/'
...
}
```
Or add the location as a paramater for gradlew command which runs the test. For example:
```
systemProperties['testProjectLocation'] = project.hasProperty('testProjectLocation') ? project.property('testProjectLocation') : null
./gradlew integrationTest -PtestProjectLocation=${env.HOME}/IdeaProjects/intellij-ui-test-projects/
```

## Start and quit IntelliJ IDEA
Use the following code to start IntelliJ before running the first UI test. The runIde() method not only starts the IDE for UI tests, it also returns reference to the Remote-Robot instance which will be useful later to access UI elements such as buttons, inputs etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.MainIdeWindow;
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.idestatusbar.IdeStatusBar;

import java.io.File;
import java.time.Duration;
import java.util.Optional;

/**
* Project creation utilities
*
* @author zcervink@redhat.com
*/
public class CreateCloseUtils {
public static final String PROJECT_LOCATION = Optional.ofNullable(System.getProperty("testProjectLocation")) // For more info on testProjectLocation please check README
.filter(s -> !s.isEmpty())
.orElseGet(() -> System.getProperty("user.home") + File.separator + "IdeaProjects" + File.separator + "intellij-ui-test-projects");

/**
* Create new project with given project name according to given project type
*
Expand Down Expand Up @@ -62,6 +68,7 @@ public static void createNewProject(RemoteRobot remoteRobot, String projectName,

if (UITestRunner.getIdeaVersionInt() >= 20221) {
newProjectFirstPage.setProjectName(projectName);
newProjectFirstPage.setProjectLocation(PROJECT_LOCATION);
} else {
newProjectDialogWizard.next();
// Plain java project has more pages in the 'New project' dialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.project.NewProjectDialogWizard;
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
import com.redhat.devtools.intellij.commonuitest.utils.internalerror.IdeInternalErrorUtils;
import com.redhat.devtools.intellij.commonuitest.utils.project.CreateCloseUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -77,9 +78,13 @@ public void clearExceptionsTest() {
}

private int getNumberOfProjectsOnDisk() {
String pathToIdeaProjectsFolder = System.getProperty("user.home") + File.separator + "IdeaProjects";
String pathToIdeaProjectsFolder = CreateCloseUtils.PROJECT_LOCATION;
File[] files = new File(pathToIdeaProjectsFolder).listFiles((FileFilter) FileFilterUtils.directoryFileFilter());
return files.length;
if (files != null) {
return files.length;
} else {
return 0; // files is null (e.g., folder doesn't exist)
}
}

private int getNumberOfProjectLinks() {
Expand Down

0 comments on commit 90dc3b9

Please sign in to comment.