Skip to content

Commit 90dc3b9

Browse files
authored
Added: custom test-project project location (#185)
Updated README Signed-off-by: Martin Szuc <[email protected]>
1 parent c9d89aa commit 90dc3b9

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ runIdeForUiTests {
6565
systemProperty "robot-server.port", System.getProperty("robot-server.port")
6666
}
6767
```
68+
### STEP #5: Test project location
69+
Developers can specify the location where the test project will be created by providing a system property called `testProjectLocation`. For example:
70+
```
71+
task integrationTest(type: Test) {
72+
...
73+
systemProperties['testProjectLocation'] = '/home/user/IdeaProjects/intellij-ui-test-projects/'
74+
...
75+
}
76+
```
77+
Or add the location as a paramater for gradlew command which runs the test. For example:
78+
```
79+
systemProperties['testProjectLocation'] = project.hasProperty('testProjectLocation') ? project.property('testProjectLocation') : null
80+
81+
./gradlew integrationTest -PtestProjectLocation=${env.HOME}/IdeaProjects/intellij-ui-test-projects/
82+
```
6883

6984
## Start and quit IntelliJ IDEA
7085
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.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.io.File;
3232
import java.io.IOException;
3333
import java.nio.file.Files;
34+
import java.nio.file.NoSuchFileException;
3435
import java.nio.file.Paths;
3536
import java.time.Duration;
3637
import java.util.List;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@
2323
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.MainIdeWindow;
2424
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.idestatusbar.IdeStatusBar;
2525

26+
import java.io.File;
2627
import java.time.Duration;
28+
import java.util.Optional;
2729

2830
/**
2931
* Project creation utilities
3032
*
3133
3234
*/
3335
public class CreateCloseUtils {
36+
public static final String PROJECT_LOCATION = Optional.ofNullable(System.getProperty("testProjectLocation")) // For more info on testProjectLocation please check README
37+
.filter(s -> !s.isEmpty())
38+
.orElseGet(() -> System.getProperty("user.home") + File.separator + "IdeaProjects" + File.separator + "intellij-ui-test-projects");
39+
3440
/**
3541
* Create new project with given project name according to given project type
3642
*
@@ -62,6 +68,7 @@ public static void createNewProject(RemoteRobot remoteRobot, String projectName,
6268

6369
if (UITestRunner.getIdeaVersionInt() >= 20221) {
6470
newProjectFirstPage.setProjectName(projectName);
71+
newProjectFirstPage.setProjectLocation(PROJECT_LOCATION);
6572
} else {
6673
newProjectDialogWizard.next();
6774
// Plain java project has more pages in the 'New project' dialog

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.project.NewProjectDialogWizard;
1919
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
2020
import com.redhat.devtools.intellij.commonuitest.utils.internalerror.IdeInternalErrorUtils;
21+
import com.redhat.devtools.intellij.commonuitest.utils.project.CreateCloseUtils;
2122
import org.apache.commons.io.filefilter.FileFilterUtils;
2223
import org.junit.jupiter.api.AfterEach;
2324
import org.junit.jupiter.api.Test;
@@ -77,9 +78,13 @@ public void clearExceptionsTest() {
7778
}
7879

7980
private int getNumberOfProjectsOnDisk() {
80-
String pathToIdeaProjectsFolder = System.getProperty("user.home") + File.separator + "IdeaProjects";
81+
String pathToIdeaProjectsFolder = CreateCloseUtils.PROJECT_LOCATION;
8182
File[] files = new File(pathToIdeaProjectsFolder).listFiles((FileFilter) FileFilterUtils.directoryFileFilter());
82-
return files.length;
83+
if (files != null) {
84+
return files.length;
85+
} else {
86+
return 0; // files is null (e.g., folder doesn't exist)
87+
}
8388
}
8489

8590
private int getNumberOfProjectLinks() {

0 commit comments

Comments
 (0)