Skip to content

Commit d9a7059

Browse files
authored
Integrate the remote-robot step logging solution (#60)
* Integrate the remote-robot step logging solution Fixes #44 Signed-off-by: Zbynek Cervinka <[email protected]>
1 parent 6fa0b20 commit d9a7059

File tree

29 files changed

+240
-172
lines changed

29 files changed

+240
-172
lines changed

.github/workflows/linux.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ jobs:
3737
name: ${{ runner.os }}-screenshots
3838
path: src/test-project/build/screenshots/*
3939
if: always()
40+
- name: Archiving StepLogger logs
41+
uses: actions/upload-artifact@v2
42+
with:
43+
name: ${{ runner.os }}-steplogger-logs
44+
path: src/test-project/build/test-results/*
45+
if: always()

.github/workflows/mac.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ jobs:
3535
name: ${{ runner.os }}-screenshots
3636
path: src/test-project/build/screenshots/*
3737
if: always()
38+
- name: Archiving StepLogger logs
39+
uses: actions/upload-artifact@v2
40+
with:
41+
name: ${{ runner.os }}-steplogger-logs
42+
path: src/test-project/build/test-results/*
43+
if: always()

.github/workflows/windows.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ jobs:
3636
name: ${{ runner.os }}-screenshots
3737
path: src\test-project\build\screenshots\*
3838
if: always()
39+
- name: Archiving StepLogger logs
40+
uses: actions/upload-artifact@v2
41+
with:
42+
name: ${{ runner.os }}-steplogger-logs
43+
path: src\test-project\build\test-results\*
44+
if: always()

src/main/java/com/redhat/devtools/intellij/commonUiTestLibrary/UITestRunner.java

Lines changed: 98 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
package com.redhat.devtools.intellij.commonUiTestLibrary;
1212

1313
import com.intellij.remoterobot.RemoteRobot;
14+
import com.intellij.remoterobot.stepsProcessing.StepLogger;
15+
import com.intellij.remoterobot.stepsProcessing.StepWorker;
1416
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
1517
import com.redhat.devtools.intellij.commonUiTestLibrary.fixtures.dialogs.FlatWelcomeFrame;
1618

@@ -27,6 +29,7 @@
2729
import java.nio.file.Paths;
2830
import java.time.Duration;
2931

32+
import static com.intellij.remoterobot.stepsProcessing.StepWorkerKt.step;
3033
import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitFor;
3134

3235
/**
@@ -48,23 +51,27 @@ public class UITestRunner {
4851
* @return instance of the RemoteRobot
4952
*/
5053
public static RemoteRobot runIde(IdeaVersion ideaVersion, int port) {
51-
UITestRunner.ideaVersion = ideaVersion;
52-
makeSureAllTermsAndConditionsAreAccepted();
54+
StepWorker.registerProcessor(new StepLogger());
5355

54-
String osName = System.getProperty("os.name").toLowerCase();
55-
String fileExtension = osName.contains("windows") ? ".bat" : "";
56-
ProcessBuilder pb = new ProcessBuilder("." + File.separator + "gradlew" + fileExtension, "runIdeForUiTests", "-PideaVersion=" + ideaVersion.toString(), "-Drobot-server.port=" + port);
56+
return step("Start IntelliJ Idea ('" + ideaVersion.toString() + "') listening on port " + port, () -> {
57+
UITestRunner.ideaVersion = ideaVersion;
58+
makeSureAllTermsAndConditionsAreAccepted();
5759

58-
try {
59-
ideProcess = pb.start();
60-
waitUntilIntelliJStarts(port);
61-
remoteRobot = getRemoteRobotConnection(port);
62-
} catch (IOException | InterruptedException e) {
63-
e.printStackTrace();
64-
}
60+
String osName = System.getProperty("os.name").toLowerCase();
61+
String fileExtension = osName.contains("windows") ? ".bat" : "";
62+
ProcessBuilder pb = new ProcessBuilder("." + File.separator + "gradlew" + fileExtension, "runIdeForUiTests", "-PideaVersion=" + ideaVersion.toString(), "-Drobot-server.port=" + port);
6563

66-
remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10)).clearWorkspace();
67-
return remoteRobot;
64+
try {
65+
ideProcess = pb.start();
66+
waitUntilIntelliJStarts(port);
67+
remoteRobot = getRemoteRobotConnection(port);
68+
} catch (IOException | InterruptedException e) {
69+
e.printStackTrace();
70+
}
71+
72+
remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10)).clearWorkspace();
73+
return remoteRobot;
74+
});
6875
}
6976

7077
/**
@@ -81,12 +88,14 @@ public static RemoteRobot runIde(IdeaVersion ideaVersion) {
8188
* Close the IntelliJ Idea IDE from the 'Welcome to IntelliJ IDEA' dialog
8289
*/
8390
public static void closeIde() {
84-
if (remoteRobot.isWin()) {
85-
remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10)).runJs("const horizontal_offset = component.getWidth() - 24;\n" +
86-
"robot.click(component, new Point(horizontal_offset, 14), MouseButton.LEFT_BUTTON, 2);");
87-
} else {
88-
ideProcess.destroy();
89-
}
91+
step("Close IntelliJ Idea", () -> {
92+
if (remoteRobot.isWin()) {
93+
remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10)).runJs("const horizontal_offset = component.getWidth() - 24;\n" +
94+
"robot.click(component, new Point(horizontal_offset, 14), MouseButton.LEFT_BUTTON, 2);");
95+
} else {
96+
ideProcess.destroy();
97+
}
98+
});
9099
}
91100

92101
/**
@@ -115,16 +124,22 @@ public static RemoteRobot getRemoteRobot() {
115124
* @throws InterruptedException may be thrown in Thread.sleep()
116125
*/
117126
public static RemoteRobot getRemoteRobotConnection(int port) throws InterruptedException {
118-
RemoteRobot remoteRobot = new RemoteRobot("http://127.0.0.1:" + port);
119-
for (int i = 0; i < 60; i++) {
120-
try {
121-
remoteRobot.find(FlatWelcomeFrame.class);
122-
} catch (WaitForConditionTimeoutException e) {
123-
Thread.sleep(1000);
127+
return step("Create an instance of the RemoteRobot listening on port " + port, () -> {
128+
RemoteRobot remoteRobot = new RemoteRobot("http://127.0.0.1:" + port);
129+
for (int i = 0; i < 60; i++) {
130+
try {
131+
remoteRobot.find(FlatWelcomeFrame.class);
132+
} catch (WaitForConditionTimeoutException e) {
133+
try {
134+
Thread.sleep(1000);
135+
} catch (InterruptedException e2) {
136+
e2.printStackTrace();
137+
}
138+
}
124139
}
125-
}
126140

127-
return remoteRobot;
141+
return remoteRobot;
142+
});
128143
}
129144

130145
/**
@@ -155,51 +170,63 @@ private static void makeSureAllTermsAndConditionsAreAccepted() {
155170
String osName = System.getProperty("os.name").toLowerCase();
156171

157172
if (osName.contains("linux")) {
158-
String prefsXmlSourceLocation = "prefs.xml";
159-
String prefsXmlDir = System.getProperty("user.home") + "/.java/.userPrefs/jetbrains/_!(!!cg\"p!(}!}@\"j!(k!|w\"w!'8!b!\"p!':!e@==";
160-
createDirectoryHierarchy(prefsXmlDir);
161-
copyFileFromJarResourceDir(prefsXmlSourceLocation, prefsXmlDir + "/prefs.xml");
162-
163-
String acceptedSourceLocation = "accepted";
164-
String acceptedDir = System.getProperty("user.home") + "/.local/share/JetBrains/consentOptions";
165-
createDirectoryHierarchy(acceptedDir);
166-
copyFileFromJarResourceDir(acceptedSourceLocation, acceptedDir + "/accepted");
173+
step("Copy the 'prefs.xml' file to the appropriate location", () -> {
174+
String prefsXmlSourceLocation = "prefs.xml";
175+
String prefsXmlDir = System.getProperty("user.home") + "/.java/.userPrefs/jetbrains/_!(!!cg\"p!(}!}@\"j!(k!|w\"w!'8!b!\"p!':!e@==";
176+
createDirectoryHierarchy(prefsXmlDir);
177+
copyFileFromJarResourceDir(prefsXmlSourceLocation, prefsXmlDir + "/prefs.xml");
178+
});
179+
180+
step("Copy the 'accepted' file to the appropriate location", () -> {
181+
String acceptedSourceLocation = "accepted";
182+
String acceptedDir = System.getProperty("user.home") + "/.local/share/JetBrains/consentOptions";
183+
createDirectoryHierarchy(acceptedDir);
184+
copyFileFromJarResourceDir(acceptedSourceLocation, acceptedDir + "/accepted");
185+
});
167186
} else if (osName.contains("os x")) {
168-
String plistSourceLocation = "com.apple.java.util.prefs.plist";
169-
String plistDir = System.getProperty("user.home") + "/Library/Preferences";
170-
copyFileFromJarResourceDir(plistSourceLocation, plistDir + "/com.apple.java.util.prefs.plist");
171-
172-
String acceptedSourceLocation = "accepted";
173-
String acceptedDir = System.getProperty("user.home") + "/Library/Application Support/JetBrains/consentOptions";
174-
createDirectoryHierarchy(acceptedDir);
175-
copyFileFromJarResourceDir(acceptedSourceLocation, acceptedDir + "/accepted");
176-
177-
// run the 'killall cfprefsd' cmd to force OS X to reload preferences files
178-
ProcessBuilder pb = new ProcessBuilder("killall", "cfprefsd");
179-
try {
180-
Process p = pb.start();
181-
p.waitFor();
182-
} catch (IOException | InterruptedException e) {
183-
e.printStackTrace();
184-
}
187+
step("Copy the 'com.apple.java.util.prefs.plist' file to the appropriate location", () -> {
188+
String plistSourceLocation = "com.apple.java.util.prefs.plist";
189+
String plistDir = System.getProperty("user.home") + "/Library/Preferences";
190+
copyFileFromJarResourceDir(plistSourceLocation, plistDir + "/com.apple.java.util.prefs.plist");
191+
});
192+
193+
step("Copy the 'accepted' file to the appropriate location", () -> {
194+
String acceptedSourceLocation = "accepted";
195+
String acceptedDir = System.getProperty("user.home") + "/Library/Application Support/JetBrains/consentOptions";
196+
createDirectoryHierarchy(acceptedDir);
197+
copyFileFromJarResourceDir(acceptedSourceLocation, acceptedDir + "/accepted");
198+
199+
// run the 'killall cfprefsd' cmd to force OS X to reload preferences files
200+
ProcessBuilder pb = new ProcessBuilder("killall", "cfprefsd");
201+
try {
202+
Process p = pb.start();
203+
p.waitFor();
204+
} catch (IOException | InterruptedException e) {
205+
e.printStackTrace();
206+
}
207+
});
185208
} else if (osName.contains("windows")) {
186-
String acceptedSourceLocation = "accepted";
187-
String acceptedDir = System.getProperty("user.home") + "\\AppData\\Roaming\\JetBrains\\consentOptions";
188-
createDirectoryHierarchy(acceptedDir);
189-
copyFileFromJarResourceDir(acceptedSourceLocation, acceptedDir + "\\accepted");
190-
191-
String registryPath = "HKCU:\\Software\\JavaSoft\\Prefs\\jetbrains\\privacy_policy";
192-
ProcessBuilder pb1 = new ProcessBuilder("powershell.exe", "New-Item", "-Path", registryPath, "-Force");
193-
ProcessBuilder pb2 = new ProcessBuilder("powershell.exe", "New-ItemProperty", "-Path", registryPath, "-Name", "accepted_version", "-Value", "'2.1'");
194-
195-
try {
196-
Process p1 = pb1.start();
197-
p1.waitFor();
198-
Process p2 = pb2.start();
199-
p2.waitFor();
200-
} catch (IOException | InterruptedException e) {
201-
e.printStackTrace();
202-
}
209+
step("Copy the 'accepted' file to the appropriate location", () -> {
210+
String acceptedSourceLocation = "accepted";
211+
String acceptedDir = System.getProperty("user.home") + "\\AppData\\Roaming\\JetBrains\\consentOptions";
212+
createDirectoryHierarchy(acceptedDir);
213+
copyFileFromJarResourceDir(acceptedSourceLocation, acceptedDir + "\\accepted");
214+
});
215+
216+
step("Create appropriate registry entries", () -> {
217+
String registryPath = "HKCU:\\Software\\JavaSoft\\Prefs\\jetbrains\\privacy_policy";
218+
ProcessBuilder pb1 = new ProcessBuilder("powershell.exe", "New-Item", "-Path", registryPath, "-Force");
219+
ProcessBuilder pb2 = new ProcessBuilder("powershell.exe", "New-ItemProperty", "-Path", registryPath, "-Name", "accepted_version", "-Value", "'2.1'");
220+
221+
try {
222+
Process p1 = pb1.start();
223+
p1.waitFor();
224+
Process p2 = pb2.start();
225+
p2.waitFor();
226+
} catch (IOException | InterruptedException e) {
227+
e.printStackTrace();
228+
}
229+
});
203230
}
204231
}
205232

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public void createNewProject() {
6363
* @param label label of the link to click on
6464
*/
6565
public void clickOnLink(String label) {
66-
// Code for IntelliJ Idea 2020.3 or newer
66+
// Code for IntelliJ IDEA 2020.3 or newer
6767
if (intelliJVersion.toInt() >= 20203) {
6868
welcomeFrameLink(label).click();
6969
}
70-
// Code for IntelliJ Idea 2020.2 or earlier
70+
// Code for IntelliJ IDEA 2020.2 or earlier
7171
else {
7272
actionLink(label).click();
7373
}
@@ -77,7 +77,6 @@ public void clickOnLink(String label) {
7777
* Clear the workspace by deleting the content of the IdeaProjects folder and clearing all the projects' links in the 'Welcome to IntelliJ IDEA' dialog
7878
*/
7979
public void clearWorkspace() {
80-
// delete all the projects' links from the 'Welcome to IntelliJ IDEA' dialog
8180
List<JListFixture> jListFixtures = jLists(byXpath("//div[@accessiblename='Recent Projects']"));
8281
while (!jListFixtures.isEmpty() && jListFixtures.get(0).findAllText().size() != 1) {
8382
JListFixture recentProjectsList = jListFixtures.get(0);
@@ -90,7 +89,6 @@ public void clearWorkspace() {
9089
}
9190
}
9291

93-
// delete all the files and folders in the IdeaProjects folder
9492
try {
9593
String pathToDirToMakeEmpty = System.getProperty("user.home") + File.separator + "IdeaProjects";
9694
boolean doesProjectDirExists = Files.exists(Paths.get(pathToDirToMakeEmpty));
@@ -119,11 +117,11 @@ public void clearExceptions() {
119117
}
120118

121119
// Works for IntelliJ Idea 2020.3+
122-
private JButtonFixture welcomeFrameLink(String text) {
120+
private JButtonFixture welcomeFrameLink(String label) {
123121
if (UtilsKt.hasAnyComponent(this, byXpath("//div[@class='NewRecentProjectPanel']"))) {
124-
return button(byXpath("//div[@class='JBOptionButton' and @text='" + text + "']"), Duration.ofSeconds(2));
122+
return button(byXpath("//div[@class='JBOptionButton' and @text='" + label + "']"), Duration.ofSeconds(2));
125123
}
126-
return button(byXpath("//div[@class='NonOpaquePanel'][./div[@text='" + text + "']]"), Duration.ofSeconds(2));
124+
return button(byXpath("//div[@class='NonOpaquePanel'][./div[@text='" + label + "']]"), Duration.ofSeconds(2));
127125
}
128126

129127
private ComponentFixture ideErrorsIcon() {

src/main/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixtures/dialogs/navigation/SearchEverywherePopup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitFor;
3333

3434
/**
35-
* Search everywhere popup fixture
35+
* Search Everywhere popup fixture
3636
*
3737
3838
*/

src/main/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixtures/dialogs/project/pages/JavaNewProjectFinalPage.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.time.Duration;
2424

2525
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
26+
import static com.intellij.remoterobot.stepsProcessing.StepWorkerKt.step;
2627

2728
/**
2829
* New Project dialog java project third page fixture
@@ -32,31 +33,32 @@
3233
@DefaultXpath(by = "MyDialog type", xpath = "//div[@class='DialogRootPane']")
3334
@FixtureName(name = "New Project Dialog")
3435
public class JavaNewProjectFinalPage extends AbstractNewProjectFinalPage {
35-
private RemoteRobot remoteRobot;
36-
3736
public JavaNewProjectFinalPage(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
3837
super(remoteRobot, remoteComponent);
39-
this.remoteRobot = remoteRobot;
4038
}
4139

4240
/**
4341
* Open the 'More settings' options
4442
*/
4543
public void openMoreSettings() {
46-
boolean isAlreadyOpened = isMoreSettingOpened();
47-
if (!isAlreadyOpened) {
48-
jLabel(ButtonLabels.moreSettings).click();
49-
}
44+
step("Open the 'More settings' options", () -> {
45+
boolean isAlreadyOpened = isMoreSettingOpened();
46+
if (!isAlreadyOpened) {
47+
jLabel(ButtonLabels.moreSettings).click();
48+
}
49+
});
5050
}
5151

5252
/**
5353
* Close the 'More settings' options
5454
*/
5555
public void closeMoreSettings() {
56-
boolean isAlreadyOpened = isMoreSettingOpened();
57-
if (isAlreadyOpened) {
58-
jLabel(ButtonLabels.moreSettings).click();
59-
}
56+
step("Close the 'More settings' options", () -> {
57+
boolean isAlreadyOpened = isMoreSettingOpened();
58+
if (isAlreadyOpened) {
59+
jLabel(ButtonLabels.moreSettings).click();
60+
}
61+
});
6062
}
6163

6264
/**

src/main/java/com/redhat/devtools/intellij/commonUiTestLibrary/fixtures/dialogs/project/pages/MavenGradleNewProjectFinalPage.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222

2323
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
24+
import static com.intellij.remoterobot.stepsProcessing.StepWorkerKt.step;
2425

2526
/**
2627
* New Project dialog maven project second page fixture
@@ -38,18 +39,22 @@ public MavenGradleNewProjectFinalPage(@NotNull RemoteRobot remoteRobot, @NotNull
3839
* Open the 'Artifact Coordinates' options
3940
*/
4041
public void openArtifactCoordinates() {
41-
if (!isArtifactCoordinatesOpened()) {
42-
jLabel(ButtonLabels.artifactCoordinates).click();
43-
}
42+
step("Open the 'Artifact Coordinates' options", () -> {
43+
if (!isArtifactCoordinatesOpened()) {
44+
jLabel(ButtonLabels.artifactCoordinates).click();
45+
}
46+
});
4447
}
4548

4649
/**
4750
* Close the 'Artifact Coordinates' options
4851
*/
4952
public void closeArtifactCoordinates() {
50-
if (isArtifactCoordinatesOpened()) {
51-
jLabel(ButtonLabels.artifactCoordinates).click();
52-
}
53+
step("Close the 'Artifact Coordinates' options", () -> {
54+
if (isArtifactCoordinatesOpened()) {
55+
jLabel(ButtonLabels.artifactCoordinates).click();
56+
}
57+
});
5358
}
5459

5560
/**

0 commit comments

Comments
 (0)