-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ff2487
commit a0df2e1
Showing
9 changed files
with
277 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...est/java/org/itallcode/openfasttrace/intelijplugin/remoterobot/RemoteRobotProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.itallcode.openfasttrace.intelijplugin.remoterobot; | ||
|
||
public final class RemoteRobotProperties { | ||
private RemoteRobotProperties () { | ||
// prevent class instantiation. | ||
} | ||
|
||
final public static int ROBOT_PORT = Integer.parseInt(System.getProperty("robot-server.port")); | ||
final public static String ROBOT_HOST = System.getProperty("robot-server.host.public", "localhost"); | ||
final public static String ROBOT_BASE_URL = "http://" + ROBOT_HOST + ":" + ROBOT_PORT; | ||
} |
58 changes: 58 additions & 0 deletions
58
src/test/java/org/itallcode/openfasttrace/intelijplugin/uitest/PluginUiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.itallcode.openfasttrace.intelijplugin.uitest; | ||
|
||
import com.intellij.remoterobot.RemoteRobot; | ||
import com.intellij.remoterobot.fixtures.ComponentFixture; | ||
|
||
import static com.intellij.remoterobot.search.locators.Locators.byXpath; | ||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assumptions.assumeFalse; | ||
|
||
import com.intellij.remoterobot.fixtures.JMenuBarFixture; | ||
import org.itallcode.openfasttrace.intelijplugin.uitest.pages.IdeFrameFixture; | ||
import org.itallcode.openfasttrace.intelijplugin.uitest.pages.NewProjectDialogFixture; | ||
import org.itallcode.openfasttrace.intelijplugin.uitest.pages.WelcomeFrameFixture; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import java.nio.file.Path; | ||
import java.time.Duration; | ||
|
||
import static org.itallcode.openfasttrace.intelijplugin.remoterobot.RemoteRobotProperties.*; | ||
|
||
class PluginUiTest { | ||
final static Duration WITH_PATIENCE = Duration.ofSeconds(10); | ||
@TempDir | ||
static Path projectTempDir; | ||
|
||
@Test | ||
void testOftMenuEntryExists() { | ||
assumeNotRunningInCiBUild(); | ||
final RemoteRobot robot = new RemoteRobot(ROBOT_BASE_URL); | ||
final WelcomeFrameFixture welcomeFrame = robot.find(WelcomeFrameFixture.class, WITH_PATIENCE); | ||
welcomeFrame.createNewProjectLink().click(); | ||
final NewProjectDialogFixture project = robot.find(NewProjectDialogFixture.class, WITH_PATIENCE); | ||
project.projectTypes().clickItem("Empty Project", true); | ||
project.projectLocation().setText(projectTempDir.toAbsolutePath().toString()); | ||
project.finish().click(); | ||
final IdeFrameFixture ide = robot.find(IdeFrameFixture.class, WITH_PATIENCE); | ||
waitUntilMenuBarIsReady(); | ||
final JMenuBarFixture menuBar = ide.menuBar(); | ||
menuBar.select("Help"); | ||
assertDoesNotThrow(() -> robot.find(ComponentFixture.class, | ||
byXpath("//div[@class='ActionMenu']//div[@text='OpenFastTrace User Guide']"))); | ||
} | ||
|
||
private static void assumeNotRunningInCiBUild() { | ||
assumeFalse(Boolean.parseBoolean(System.getenv("CI"))); | ||
} | ||
|
||
@SuppressWarnings("java:S2925") | ||
private void waitUntilMenuBarIsReady() { | ||
try { | ||
Thread.sleep(5000); | ||
} catch (InterruptedException exception) { | ||
Thread.currentThread().interrupt(); | ||
throw new RuntimeException(exception); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/java/org/itallcode/openfasttrace/intelijplugin/uitest/pages/IdeFrameFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.itallcode.openfasttrace.intelijplugin.uitest.pages; | ||
|
||
import com.intellij.remoterobot.RemoteRobot; | ||
import com.intellij.remoterobot.data.RemoteComponent; | ||
import com.intellij.remoterobot.fixtures.*; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.time.Duration; | ||
|
||
import static com.intellij.remoterobot.search.locators.Locators.byXpath; | ||
|
||
/** | ||
* The IDE Frame is the main container window (or page if you prefer that) for the IntelliJ IDEA. | ||
*/ | ||
@DefaultXpath(by = "IdeFrameImpl type", xpath = "//div[@class='IdeFrameImpl']") | ||
@FixtureName(name = "IDE Frame") | ||
public class IdeFrameFixture extends CommonContainerFixture { | ||
public IdeFrameFixture(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) { | ||
super(remoteRobot, remoteComponent); | ||
} | ||
|
||
public JMenuBarFixture menuBar() { | ||
return find(JMenuBarFixture.class, byXpath("//div[@class='LinuxIdeMenuBar']"), Duration.ofSeconds(20)); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
.../java/org/itallcode/openfasttrace/intelijplugin/uitest/pages/NewProjectDialogFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.itallcode.openfasttrace.intelijplugin.uitest.pages; | ||
|
||
import com.intellij.remoterobot.RemoteRobot; | ||
import com.intellij.remoterobot.data.RemoteComponent; | ||
import com.intellij.remoterobot.fixtures.*; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static com.intellij.remoterobot.search.locators.Locators.byXpath; | ||
|
||
@DefaultXpath(by = "NewProjectDialog type", xpath = "//*[contains(@title.key, 'title.new.project')]") | ||
@FixtureName(name = "New Project Dialog") | ||
public class NewProjectDialogFixture extends CommonContainerFixture { | ||
public NewProjectDialogFixture(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) { | ||
super(remoteRobot, remoteComponent); | ||
} | ||
|
||
public JListFixture projectTypes() { | ||
return find(JListFixture.class, byXpath("//div[@class='JBList']")); | ||
} | ||
|
||
public JTextFieldFixture projectLocation() { | ||
return find(JTextFieldFixture.class, byXpath("//div[@class='FieldPanel']/div[1]")); | ||
} | ||
|
||
public JButtonFixture finish() { | ||
return find(JButtonFixture.class, byXpath("//div[@text.key='button.finish']")); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...test/java/org/itallcode/openfasttrace/intelijplugin/uitest/pages/WelcomeFrameFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.itallcode.openfasttrace.intelijplugin.uitest.pages; | ||
|
||
import com.intellij.remoterobot.RemoteRobot; | ||
import com.intellij.remoterobot.data.RemoteComponent; | ||
import com.intellij.remoterobot.fixtures.*; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static com.intellij.remoterobot.search.locators.Locators.byXpath; | ||
|
||
/** | ||
* The Welcome Frame is the container window (or page if you prefer that) for everything that happens before IntelliJ | ||
* opens the actual IDE window. | ||
* <p> | ||
* Displaying a welcome message is the smaller part of that job. The main reason is that the IDE needs a project context | ||
* to work with and that context does not exist with a fresh installation. That is also why the welcome screen contains | ||
* the means of opening, importing or creating projects in a sub dialog. | ||
* </p> | ||
*/ | ||
@DefaultXpath(by = "FlatWelcomeFrame type", xpath = "//div[@class='FlatWelcomeFrame']") | ||
@FixtureName(name = "Welcome Frame") | ||
public class WelcomeFrameFixture extends CommonContainerFixture { | ||
public WelcomeFrameFixture(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) { | ||
super(remoteRobot, remoteComponent); | ||
} | ||
|
||
public JButtonFixture createNewProjectLink() { | ||
// The button style changes from an icon to a text button if a project already exists. To make things worse, | ||
// In case of the icon the button is followed by a label that has the same text on it as the link-style button. | ||
// We need a bit of XPath complexity, to pick either of the clickable items. | ||
return find(JButtonFixture.class, byXpath("(//div[@defaulticon='createNewProjectTab.svg']" + | ||
"|//div[@visible_text='New Project'])[1]")); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...est/java/org/itallcode/openfasttrace/intelijplugin/wait/RobotServerReadyWaitStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.itallcode.openfasttrace.intelijplugin.wait; | ||
|
||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
import java.io.IOException; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import static org.itallcode.openfasttrace.intelijplugin.remoterobot.RemoteRobotProperties.*; | ||
|
||
/** | ||
* This strategy waits for the Remote Robot server to become available. | ||
*/ | ||
public class RobotServerReadyWaitStrategy { | ||
private static final long RETRY_DELAY_MILLIS = 1000; | ||
private final Duration timeout; | ||
|
||
/** | ||
* Wait for the Remote Robot server to become available. | ||
* | ||
* @param timeout maximum time to wait for the server to become available | ||
* @throws TimeoutException if the given timeout is reached without being able to connect to the robot server | ||
*/ | ||
public static void wait(final Duration timeout) throws TimeoutException { | ||
final RobotServerReadyWaitStrategy strategy = new RobotServerReadyWaitStrategy(timeout); | ||
strategy.waitUntilReady(); | ||
} | ||
|
||
private RobotServerReadyWaitStrategy(final Duration timeout) { | ||
this.timeout = timeout; | ||
} | ||
|
||
private void waitUntilReady() throws TimeoutException { | ||
final OkHttpClient client = new OkHttpClient.Builder() | ||
.connectTimeout(timeout) | ||
.retryOnConnectionFailure(true) | ||
.build(); | ||
poll(client, ROBOT_BASE_URL); | ||
client.dispatcher().executorService().shutdown(); | ||
} | ||
|
||
private void poll(final OkHttpClient client, final String url) throws TimeoutException { | ||
final Request request = new Request.Builder().url(url).build(); | ||
final Instant until = Instant.now().plus(this.timeout); | ||
do { | ||
try (final Response response = client.newCall(request).execute()) { | ||
if (response.isSuccessful()) { | ||
return; | ||
} | ||
} catch (IOException exception) { | ||
// keep trying. | ||
try { | ||
delayPollingRetry(); | ||
} catch (InterruptedException interruptedException) { | ||
Thread.currentThread().interrupt(); | ||
throw new RuntimeException(interruptedException); | ||
} | ||
} | ||
} while (Instant.now().isBefore(until)); | ||
throw new TimeoutException("Timed out waiting for Remote Robot server to become available"); | ||
} | ||
|
||
@SuppressWarnings("java:S2925") | ||
private static void delayPollingRetry() throws InterruptedException { | ||
Thread.sleep(RETRY_DELAY_MILLIS); | ||
} | ||
} |