How to Write and Execute UI Tests in IntelliJ IDEA Using Remote-Robot

Jul 8, 2023 | Programming

Welcome! In this guide, we will explore how to use the Remote-Robot library to write and execute UI tests for your plugins in IntelliJ IDEA. Whether you’re developing your first plugin or looking to enhance your testing skills, you’re in the right place!

Quick Start

The first step in testing is to launch your IDE. Since the runIdeForUiTests task is blocking, you will execute it as an asynchronous process:

.gradlew ui-test-example:clean ui-test-example:runIdeForUiTests

Once the IDE is up, you can proceed to start your tests. Ensure that the Welcome Frame is visible on your screen with the following command:

.gradlew ui-test-example:test

If you prefer to run all tasks at once, you can combine the commands:

.gradlew ui-test-example:clean ui-test-example:runIdeForUiTests  .gradlew ui-test-example:test

Understanding Remote-Robot

Think of Remote-Robot as a skilled puppet master controlling different actor puppets in a theater (your IDE). This library allows you to send commands (like cues) to the robot-server plugin (the stage where the puppets perform) to execute your UI tests seamlessly. The communication happens via a magic string (HTTP protocol), allowing your IDE to be launched on remote machines or Docker containers—sort of like performing in multiple theaters across town!

Setup

To begin, ensure you have the latest version of Remote-Robot, which is 0.11.23. In your test project, configure the dependencies:

groovy
repositories {
    maven { url = "https://packages.jetbrains.team/maven/pijintellij-dependencies" }
}
dependencies {
    testImplementation("com.intellij.remoterobot:remote-robot:$REMOTE-ROBOT_VERSION")
}

In your plugin project, you will also need the following settings:

groovy
runIdeForUiTests {
    systemProperty "robot-server.port", 8082 // default port 8580
}
downloadRobotServerPlugin(version = REMOTE-ROBOT_VERSION)

Launching the Tests

There are two methods for launching IntelliJ IDEA and your UI tests:

  • Using IntelliJ Gradle Plugin: Similar to the previous setup, you can run the blocking task using:
  • .gradlew ui-test-example:clean ui-test-example:runIdeForUiTests
  • Using ide-launcher: This approach calls for direct interaction from the test. You just need to add the ide-launcher dependency.
  • groovy
    dependencies {
        testImplementation("com.intellij.remoterobot:ide-launcher:$REMOTE-ROBOT_VERSION")
    }
    

Finding Components

Once you’ve initiated Remote-Robot, searching components is a breeze! You can use XPath queries to locate components just like you would on a website.

You can find a component using:

java
Locator loginToGitHubLocator = byXpath("div[@class='MainButton' and @text='Log in to GitHub...']");
ComponentFixture loginToGitHub = remoteRobot.find(ComponentFixture.class, loginToGitHubLocator);

Troubleshooting

If you encounter issues during testing, here are some troubleshooting tips:

  • Ensure that your Welcome Frame is visible.
  • Check your port settings; if the port is public, make sure to enable it in the task settings.
  • If using Docker, verify the configurations to ensure proper connections.
  • For parsing errors with XPath, use the built-in XPath generator provided in the UI.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Conclusion

With the Remote-Robot library, testing your IntelliJ plugins can be streamlined and efficient. Leverage the power of UI testing to ensure your plugins are user-ready and embody the quality that developers seek!

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox