Refactor UI tests workflow: streamline configurations, add Linux and macOS compatibility, enhance test logging, and integrate new UI testing class.

This commit is contained in:
Jonathan Gafner 2025-08-16 11:16:51 +03:00
parent 03a31b46c3
commit 369aca6ca5
12 changed files with 1104 additions and 224 deletions

View File

@ -1,6 +1,6 @@
# GitHub Actions Workflow for launching UI tests on Linux, Windows, and Mac in the following steps:
# - Prepare and launch IDE with your plugin and robot-server plugin, which is needed to interact with the UI.
# - Wait for IDE to start.
# GitHub Actions Workflow for launching UI tests on Linux and Mac in the following steps:
# - Prepare and launch IDE with your plugin and robot-server plugin, which is necessary to interact with the UI.
# - Wait for IDE to start
# - Run UI tests with a separate Gradle task.
#
# Please check https://github.com/JetBrains/intellij-ui-test-robot for information about UI tests with IntelliJ Platform.
@ -12,28 +12,30 @@ on:
workflow_dispatch
jobs:
# UI Test Jobs (one per OS/test combination)
testUI:
runs-on: ${{ matrix.os }}
name: Run UI Test (${{ matrix.osName }} - ${{ matrix.test }})
runs-on: ${{ matrix.runner }}
permissions:
contents: write
checks: write
pull-requests: write
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
runIde: |
export DISPLAY=:99.0
Xvfb -ac :99 -screen 0 1920x1080x16 &
gradle runIdeForUiTests &
- os: windows-latest
runIde: start gradlew.bat runIdeForUiTests
- os: macos-latest
runIde: ./gradlew runIdeForUiTests &
# Linux test
- runner: ubuntu-latest
osName: Linux
test: org.jetbrains.plugins.template.ui.MyProjectUITest
# macOS test
- runner: macos-latest
osName: macOS
test: org.jetbrains.plugins.template.ui.MyProjectUITest
steps:
# Check out the current repository
- name: Fetch Sources
uses: actions/checkout@v4
uses: actions/checkout@v5
# Set up the Java environment for the next steps
- name: Setup Java
@ -44,22 +46,101 @@ jobs:
# Setup Gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
uses: gradle/actions/setup-gradle@v4.2.2
with:
cache-read-only: true
# Run IDEA prepared for UI testing
- name: Run IDE
run: ${{ matrix.runIde }}
# Set up Xvfb for Linux headless mode
- name: Setup Xvfb for Linux
if: runner.os == 'Linux'
run: |
sudo apt-get update -y
sudo apt-get install -y xvfb x11-utils libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0
export DISPLAY=:99.0
Xvfb -ac :99 -screen 0 1920x1080x16 &
sleep 3
echo "DISPLAY=:99.0" >> $GITHUB_ENV
# Wait for IDEA to be started
- name: Health Check
uses: jtalk/url-health-check-action@v4
# Run UI test with IDE Starter framework
- name: Run UI Test ${{ matrix.test }}
env:
CODECOV_API_TOKEN: ${{ secrets.CODECOV_API_TOKEN }}
LICENSE_KEY: ${{ secrets.LICENSE_KEY }}
UI_BRANCH_NAME: "${{ matrix.osName }}-${{ github.ref_name }}"
DISPLAY: ${{ runner.os == 'Linux' && ':99.0' || '' }}
run: |
echo "Running UI test ${{ matrix.test }} on ${{ matrix.osName }}"
echo "UI on ${{ matrix.osName }} run #: ${{ github.run_number }} and id: ${{ github.run_id }}"
./gradlew uiTest --tests "${{ matrix.test }}" --info
timeout-minutes: 30
# List build directory for debugging
- name: List build directory structure
if: always()
shell: bash
run: |
echo "=== Build directory structure ==="
if [ -d "build" ]; then
find build -type d -name "log" -o -name "screenshots" -o -name "ui-hierarchy" 2>/dev/null | head -20 || true
echo "=== Looking for IDE test output ==="
find build -type d -path "*/ide-tests/*" 2>/dev/null | head -20 || true
else
echo "Build directory not found"
fi
- name: Collect Test Results
if: always()
uses: actions/upload-artifact@v4.6.2
with:
url: http://127.0.0.1:8082
max-attempts: 15
retry-delay: 30s
name: tests-result-${{ matrix.test }}-${{ matrix.osName }}
path: |
build/reports/
build/test-results/
build/out/
build/idea-sandbox/
build/**/*.log
build/**/screenshots/
build/**/ui-hierarchy/
if-no-files-found: warn
continue-on-error: true
# Run tests
- name: Tests
run: ./gradlew test
- name: Collect Test Report XML
if: always()
uses: actions/upload-artifact@v4.6.2
with:
name: test-report-${{ matrix.test }}-${{ matrix.osName }}
path: ${{ github.workspace }}/build/test-results/uiTest/*.xml
# Test report job using dorny/test-reporter
test-report:
name: UI Test Report
needs: testUI
runs-on: ubuntu-latest
if: always()
permissions:
contents: write
checks: write
pull-requests: write
actions: read
steps:
- name: Fetch Sources
uses: actions/checkout@v5
with:
token: '${{ secrets.GITHUB_TOKEN }}'
- name: Download all test reports
uses: actions/download-artifact@v5.0.0
with:
pattern: test-report-*
path: test-reports
merge-multiple: true
- name: Generate Test Report
uses: dorny/test-reporter@v2.1.1
if: success() || failure()
with:
name: UI Test Report Dashboard
reporter: java-junit
fail-on-error: 'true'
path: 'test-reports/*.xml'

24
.run/Run UI Tests.run.xml Normal file
View File

@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run UI Tests" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="uiTest" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>

View File

@ -7,14 +7,21 @@
### Added
- Add `platformBundledModules` to `gradle.properties` along with `bundledModules()` helper to the Gradle build file
- UI Test support using IntelliJ IDE Starter framework
- New `uiTest` source set with example UI test demonstrating project creation
- GitHub Actions workflow for running UI tests on Linux and macOS
- UI test configuration with proper dependencies and Gradle task
### Changed
- Dependencies - upgrade `org.jetbrains.intellij.platform` to `2.7.1`
- Dependencies - upgrade `org.jetbrains.intellij.platform` to `2.7.2`
- Update documentation to reference IntelliJ IDE Starter instead of UI Test Robot framework
- Simplified repository configuration, removing unnecessary Maven repositories
### Fixed
- GitHub: Fixed the missing `$RELEASE_NOTE ` parent directory in the Release workflow
- UI Test: Added initialization check to prevent `UninitializedPropertyAccessException` in test teardown
## [2.3.0] - 2025-08-09

442
README.md
View File

@ -12,14 +12,18 @@
> Click the <kbd>Use this template</kbd> button and clone it in IntelliJ IDEA.
<!-- Plugin description -->
**IntelliJ Platform Plugin Template** is a repository that provides a pure template to make it easier to create a new plugin project (check the [Creating a repository from a template][gh:template] article).
**IntelliJ Platform Plugin Template** is a repository that provides a pure template to make it easier to create a new
plugin project (check the [Creating a repository from a template][gh:template] article).
The main goal of this template is to speed up the setup phase of plugin development for both new and experienced developers by preconfiguring the project scaffold and CI, linking to the proper documentation pages, and keeping everything organized.
The main goal of this template is to speed up the setup phase of plugin development for both new and experienced
developers by preconfiguring the project scaffold and CI, linking to the proper documentation pages, and keeping
everything organized.
[gh:template]: https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template
<!-- Plugin description end -->
If you're still not quite sure what this is all about, read our introduction: [What is the IntelliJ Platform?][docs:intro]
If you're still not quite sure what this is all about, read our
introduction: [What is the IntelliJ Platform?][docs:intro]
> [!NOTE]
> Click the <kbd>Watch</kbd> button on the top to be notified about releases containing new features and fixes.
@ -33,73 +37,86 @@ In this README, we will highlight the following elements of template-project cre
- [Plugin template structure](#plugin-template-structure)
- [Plugin configuration file](#plugin-configuration-file)
- [Sample code](#sample-code):
- listeners project lifecycle listener
- services project and application-level services
- listeners project lifecycle listener
- services project and application-level services
- [Testing](#testing)
- [Functional tests](#functional-tests)
- [Code coverage](#code-coverage)
- [UI tests](#ui-tests)
- [Functional tests](#functional-tests)
- [Code coverage](#code-coverage)
- [UI tests](#ui-tests)
- [Qodana integration](#qodana-integration)
- [Predefined Run/Debug configurations](#predefined-rundebug-configurations)
- [Continuous integration](#continuous-integration) based on GitHub Actions
- [Dependencies management](#dependencies-management) with Dependabot
- [Changelog maintenance](#changelog-maintenance) with the Gradle Changelog Plugin
- [Release flow](#release-flow) using GitHub Releases
- [Plugin signing](#plugin-signing) with your private certificate
- [Publishing the plugin](#publishing-the-plugin) with the IntelliJ Platform Gradle Plugin
- [Dependencies management](#dependencies-management) with Dependabot
- [Changelog maintenance](#changelog-maintenance) with the Gradle Changelog Plugin
- [Release flow](#release-flow) using GitHub Releases
- [Plugin signing](#plugin-signing) with your private certificate
- [Publishing the plugin](#publishing-the-plugin) with the IntelliJ Platform Gradle Plugin
- [FAQ](#faq)
- [Useful links](#useful-links)
## Getting started
Before we dive into plugin development and everything related to it, it's worth mentioning the benefits of using GitHub Templates.
Before we dive into plugin development and everything related to it, it's worth mentioning the benefits of using GitHub
Templates.
By creating a new project using the current template, you start with no history or reference to this repository.
This allows you to create a new repository easily without copying and pasting previous content, clone repositories, or clearing the history manually.
This allows you to create a new repository easily without copying and pasting previous content, clone repositories, or
clearing the history manually.
All you have to do is click the <kbd>Use this template</kbd> button (you must be logged in with your GitHub account).
![Use this template][file:use-this-template.png]
After using the template to create your blank project, the [Template Cleanup][file:template_cleanup.yml] workflow will be triggered to override or remove any template-specific configurations, such as the plugin name, current changelog, etc.
Once this is complete, open the newly created project's _Settings | Actions | General_ page and enable option _Allow GitHub Actions to create and approve pull requests_.
After using the template to create your blank project, the [Template Cleanup][file:template_cleanup.yml] workflow will
be triggered to override or remove any template-specific configurations, such as the plugin name, current changelog,
etc.
Once this is complete, open the newly created project's _Settings | Actions | General_ page and enable option _Allow
GitHub Actions to create and approve pull requests_.
Now the project is ready to be cloned to your local environment and opened with [IntelliJ IDEA][jb:download-ij].
The most convenient way for getting your new project from GitHub is the <kbd>Get from VCS</kbd> action available on the Welcome Screen, where you can filter your GitHub repository by its name.
The most convenient way for getting your new project from GitHub is the <kbd>Get from VCS</kbd> action available on the
Welcome Screen, where you can filter your GitHub repository by its name.
![Get from Version Control][file:get-from-version-control]
The next step, after opening your project in IntelliJ IDEA, is to set the proper <kbd>SDK</kbd> to Java in version `17` within the [Project Structure settings][docs:project-structure-settings].
The next step, after opening your project in IntelliJ IDEA, is to set the proper <kbd>SDK</kbd> to Java in version `17`
within the [Project Structure settings][docs:project-structure-settings].
![Project Structure — SDK][file:project-structure-sdk.png]
For the last step, you have to manually review the configuration variables described in the [`gradle.properties`][file:gradle.properties] file and *optionally* move sources from the *com.github.username.repository* package to the one that works best for you.
For the last step, you have to manually review the configuration variables described in the [
`gradle.properties`][file:gradle.properties] file and *optionally* move sources from the
*com.github.username.repository* package to the one that works best for you.
Then you can get to work implementing your ideas.
> [!NOTE]
> To use Java in your plugin, create the `/src/main/java` directory.
## Gradle configuration
The recommended method for plugin development involves using the [Gradle][gradle] setup with the [intellij-platform-gradle-plugin][gh:intellij-platform-gradle-plugin] installed.
The IntelliJ Platform Gradle Plugin makes it possible to run the IDE with your plugin and publish your plugin to JetBrains Marketplace.
The recommended method for plugin development involves using the [Gradle][gradle] setup with
the [intellij-platform-gradle-plugin][gh:intellij-platform-gradle-plugin] installed.
The IntelliJ Platform Gradle Plugin makes it possible to run the IDE with your plugin and publish your plugin to
JetBrains Marketplace.
> [!NOTE]
> Make sure to always upgrade to the latest version of IntelliJ Platform Gradle Plugin.
A project built using the IntelliJ Platform Plugin Template includes a Gradle configuration already set up.
Feel free to read through the [Using Gradle][docs:using-gradle] articles to understand your build better and learn how to customize it.
Feel free to read through the [Using Gradle][docs:using-gradle] articles to understand your build better and learn how
to customize it.
The most significant parts of the current configuration are:
- Integration with the [intellij-platform-gradle-plugin][gh:intellij-platform-gradle-plugin] for smoother development.
- Configuration written with [Gradle Kotlin DSL][gradle:kotlin-dsl].
- Support for Kotlin and Java implementation.
- Integration with the [gradle-changelog-plugin][gh:gradle-changelog-plugin], which automatically patches the change notes based on the `CHANGELOG.md` file.
- Integration with the [gradle-changelog-plugin][gh:gradle-changelog-plugin], which automatically patches the change
notes based on the `CHANGELOG.md` file.
- [Plugin publishing][docs:publishing] using the token.
For more details regarding Kotlin integration, please see [Kotlin for Plugin Developers][docs:kotlin] in the IntelliJ Platform Plugin SDK documentation.
For more details regarding Kotlin integration, please see [Kotlin for Plugin Developers][docs:kotlin] in the IntelliJ
Platform Plugin SDK documentation.
### Gradle properties
@ -118,23 +135,27 @@ The project-specific configuration file [`gradle.properties`][file:gradle.proper
| `platformBundledPlugins` | Comma-separated list of dependencies to the bundled IDE plugins. |
| `gradleVersion` | Version of Gradle used for plugin development. |
The properties listed define the plugin itself or configure the [intellij-platform-gradle-plugin][gh:intellij-platform-gradle-plugin] check its documentation for more details.
The properties listed define the plugin itself or configure
the [intellij-platform-gradle-plugin][gh:intellij-platform-gradle-plugin] check its documentation for more details.
In addition, extra behaviors are configured through the [`gradle.properties`][file:gradle.properties] file, such as:
| Property name | Value | Description |
|--------------------------------------------------|---------|------------------------------------------------------------------------------------------------|
| `kotlin.stdlib.default.dependency` | `false` | Opt-out flag for bundling [Kotlin standard library][docs:kotlin-stdlib] |
| `org.gradle.configuration-cache` | `true` | Enable [Gradle Configuration Cache][gradle:configuration-cache] |
| `org.gradle.caching` | `true` | Enable [Gradle Build Cache][gradle:build-cache] |
| Property name | Value | Description |
|------------------------------------|---------|-------------------------------------------------------------------------|
| `kotlin.stdlib.default.dependency` | `false` | Opt-out flag for bundling [Kotlin standard library][docs:kotlin-stdlib] |
| `org.gradle.configuration-cache` | `true` | Enable [Gradle Configuration Cache][gradle:configuration-cache] |
| `org.gradle.caching` | `true` | Enable [Gradle Build Cache][gradle:build-cache] |
### Environment variables
Some values used for the Gradle configuration shouldn't be stored in files to avoid publishing them to the Version Control System.
Some values used for the Gradle configuration shouldn't be stored in files to avoid publishing them to the Version
Control System.
To avoid that, environment variables are introduced, which can be provided within the *Run/Debug Configuration* within the IDE, or on the CI like for GitHub: `⚙️ Settings > Secrets and variables > Actions`.
To avoid that, environment variables are introduced, which can be provided within the *Run/Debug Configuration* within
the IDE, or on the CI like for GitHub: `⚙️ Settings > Secrets and variables > Actions`.
Environment variables used by the current project are related to the [plugin signing](#plugin-signing) and [publishing](#publishing-the-plugin).
Environment variables used by the current project are related to the [plugin signing](#plugin-signing)
and [publishing](#publishing-the-plugin).
| Environment variable name | Description |
|---------------------------|--------------------------------------------------------------------------------------------------------------|
@ -145,7 +166,8 @@ Environment variables used by the current project are related to the [plugin sig
For more details on how to generate proper values, check the relevant sections mentioned above.
To configure GitHub secret environment variables, go to the `⚙️ Settings > Secrets and variables > Actions` section of your project repository:
To configure GitHub secret environment variables, go to the `⚙️ Settings > Secrets and variables > Actions` section of
your project repository:
![Settings > Secrets][file:settings-secrets.png]
@ -180,43 +202,45 @@ A generated IntelliJ Platform Plugin Template repository contains the following
└── settings.gradle.kts Gradle project settings
```
In addition to the configuration files, the most crucial part is the `src` directory, which contains our implementation and the manifest for our plugin [plugin.xml][file:plugin.xml].
In addition to the configuration files, the most crucial part is the `src` directory, which contains our implementation
and the manifest for our plugin [plugin.xml][file:plugin.xml].
> [!NOTE]
> To use Java in your plugin, create the `/src/main/java` directory.
## Plugin configuration file
The plugin configuration file is a [plugin.xml][file:plugin.xml] file located in the `src/main/resources/META-INF` directory.
The plugin configuration file is a [plugin.xml][file:plugin.xml] file located in the `src/main/resources/META-INF`
directory.
It provides general information about the plugin, its dependencies, extensions, and listeners.
```xml
<idea-plugin>
<id>org.jetbrains.plugins.template</id>
<name>Template</name>
<vendor>JetBrains</vendor>
<depends>com.intellij.modules.platform</depends>
<id>org.jetbrains.plugins.template</id>
<name>Template</name>
<vendor>JetBrains</vendor>
<resource-bundle>messages.MyBundle</resource-bundle>
<extensions defaultExtensionNs="com.intellij">
<toolWindow factoryClass="..." id="..."/>
</extensions>
<depends>com.intellij.modules.platform</depends>
<applicationListeners>
<listener class="..." topic="..."/>
</applicationListeners>
<resource-bundle>messages.MyBundle</resource-bundle>
<extensions defaultExtensionNs="com.intellij">
<toolWindow factoryClass="..." id="..."/>
</extensions>
<applicationListeners>
<listener class="..." topic="..."/>
</applicationListeners>
</idea-plugin>
```
You can read more about this file in the [Plugin Configuration File][docs:plugin.xml] section of our documentation.
## Sample code
The prepared template provides as little code as possible because it is impossible for a general scaffold to fulfill all the specific requirements for all types of plugins (language support, build tools, VCS related tools).
The prepared template provides as little code as possible because it is impossible for a general scaffold to fulfill all
the specific requirements for all types of plugins (language support, build tools, VCS related tools).
Therefore, the template contains only the following files:
```
@ -232,103 +256,142 @@ Therefore, the template contains only the following files:
These files are located in `src/main/kotlin`.
This location indicates the language being used.
So if you decide to use Java instead (or in addition to Kotlin), these sources should be located in the `src/main/java` directory.
So if you decide to use Java instead (or in addition to Kotlin), these sources should be located in the `src/main/java`
directory.
> [!TIP]
> It is possible to use the [IntelliJ Platform Icons](https://jb.gg/new-ui-icons) in your plugin.
To start with the actual implementation, you may check our [IntelliJ Platform SDK DevGuide][docs], which contains an introduction to the essential areas of the plugin development together with dedicated tutorials.
To start with the actual implementation, you may check our [IntelliJ Platform SDK DevGuide][docs], which contains an
introduction to the essential areas of the plugin development together with dedicated tutorials.
> [!WARNING]
> Remember to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`.
For those who value example codes the most, there are also available [IntelliJ SDK Code Samples][gh:code-samples] and [IntelliJ Platform Explorer][jb:ipe] a search tool for browsing Extension Points inside existing implementations of open-source IntelliJ Platform plugins.
For those who value example codes the most, there are also available [IntelliJ SDK Code Samples][gh:code-samples]
and [IntelliJ Platform Explorer][jb:ipe] a search tool for browsing Extension Points inside existing implementations
of open-source IntelliJ Platform plugins.
## Testing
[Testing plugins][docs:testing-plugins] is an essential part of the plugin development to make sure that everything works as expected between IDE releases and plugin refactorings.
[Testing plugins][docs:testing-plugins] is an essential part of the plugin development to make sure that everything
works as expected between IDE releases and plugin refactorings.
The IntelliJ Platform Plugin Template project provides integration of two testing approaches functional and UI tests.
### Functional tests
Most of the IntelliJ Platform codebase tests are model-level, run in a headless environment using an actual IDE instance.
The tests usually test a feature as a whole rather than individual functions that comprise its implementation, like in unit tests.
Most of the IntelliJ Platform codebase tests are model-level, run in a headless environment using an actual IDE
instance.
The tests usually test a feature as a whole rather than individual functions that comprise its implementation, like in
unit tests.
In `src/test/kotlin`, you will find a basic `MyPluginTest` test that utilizes `BasePlatformTestCase` and runs a few checks against the XML files to indicate an example operation of creating files on the fly or reading them from `src/test/testData/rename` test resources.
In `src/test/kotlin`, you will find a basic `MyPluginTest` test that utilizes `BasePlatformTestCase` and runs a few
checks against the XML files to indicate an example operation of creating files on the fly or reading them from
`src/test/testData/rename` test resources.
> [!NOTE]
> Run your tests using predefined *Run Tests* configuration or by invoking the `./gradlew check` Gradle task.
### Code coverage
The [Kover][gh:kover] a Gradle plugin for Kotlin code coverage agents: IntelliJ and JaCoCo is integrated into the project to provide the code coverage feature.
The [Kover][gh:kover] a Gradle plugin for Kotlin code coverage agents: IntelliJ and JaCoCo is integrated into the
project to provide the code coverage feature.
Code coverage makes it possible to measure and track the degree of plugin sources testing.
The code coverage gets executed when running the `check` Gradle task.
The final test report is sent to [CodeCov][codecov] for better results visualization.
### UI tests
If your plugin provides complex user interfaces, you should consider covering them with tests and the functionality they utilize.
If your plugin provides complex user interfaces, you should consider covering them with tests and the functionality they
utilize.
[IntelliJ UI Test Robot][gh:intellij-ui-test-robot] allows you to write and execute UI tests within the IntelliJ IDE running instance.
You can use the [XPath query language][xpath] to find components in the currently available IDE view.
Once IDE with `robot-server` has started, you can open the `http://localhost:8082` page that presents the currently available IDEA UI components hierarchy in HTML format and use a simple `XPath` generator, which can help test your plugin's interface.
This template uses the [IntelliJ IDE Starter][gh:intellij-ide-starter] framework for UI testing, which provides a modern
approach to testing IntelliJ Platform plugins through the Driver SDK.
The framework allows you to interact with IDE components programmatically and verify plugin behavior in a real IDE
environment.
> [!NOTE]
> Run IDE for UI tests by invoking the `./gradlew runIdeForUiTests` and `./gradlew check` Gradle tasks.
> Run UI tests by invoking the `./gradlew uiTest` Gradle task.
Check the UI Test Example project you can use as a reference for setting up UI testing in your plugin: [intellij-ui-test-robot/ui-test-example][gh:ui-test-example].
For comprehensive documentation on UI testing, refer to
the [IntelliJ Platform Plugin SDK documentation on UI Tests][docs:ui-tests].
Example UI test using IntelliJ IDE Starter:
```kotlin
class MyUITest {
@Test
fun simpleProjectWithToolWindowTest() {
run.driver.withContext {
welcomeScreen {
createNewProjectButton.click()
@Test
fun openAboutFromWelcomeScreen() {
val robot = RemoteRobot("http://127.0.0.1:8082")
robot.find<ComponentFixture>(byXpath("//div[@myactionlink = 'gearHover.svg']")).click()
// ...
}
newProjectDialog {
chooseProjectType("Java")
setProjectName("TestProject")
createButton.click()
}
}
ideFrame {
driver.waitForIndicators()
leftToolWindowToolbar.projectButton.open()
// Verify your plugin's UI components
}
}
}
```
![UI Testing][file:ui-testing.png]
The template includes:
A dedicated [Run UI Tests](.github/workflows/run-ui-tests.yml) workflow is available for manual triggering to run UI tests against three different operating systems: macOS, Windows, and Linux.
Due to its optional nature, this workflow isn't set as an automatic one, but this can be easily achieved by changing the `on` trigger event, like in the [Build](.github/workflows/build.yml) workflow file.
- A dedicated `uiTest` source set with example tests in `src/uiTest/kotlin`
- Test setup configuration using IntelliJ IDE Starter
- GitHub Actions workflow for running UI tests on Linux and macOS
A dedicated [Run UI Tests](.github/workflows/run-ui-tests.yml) workflow is available for manual triggering to run UI
tests against multiple operating systems: macOS and Linux.
Due to its optional nature, this workflow isn't set as an automatic one, but this can be easily achieved by changing the
`on` trigger event, like in the [Build](.github/workflows/build.yml) workflow file.
## Qodana integration
To increase the project value, the IntelliJ Platform Plugin Template got integrated with [Qodana][jb:qodana], a code quality monitoring platform that allows you to check the condition of your implementation and find any possible problems that may require enhancing.
To increase the project value, the IntelliJ Platform Plugin Template got integrated with [Qodana][jb:qodana], a code
quality monitoring platform that allows you to check the condition of your implementation and find any possible problems
that may require enhancing.
Qodana brings into your CI/CD pipelines all the smart features you love in the JetBrains IDEs and generates an HTML report with the actual inspection status.
Qodana brings into your CI/CD pipelines all the smart features you love in the JetBrains IDEs and generates an HTML
report with the actual inspection status.
Qodana inspections are accessible within the project on two levels:
- using the [Qodana IntelliJ GitHub Action][jb:qodana-github-action], run automatically within the [Build](.github/workflows/build.yml) workflow,
- with the [Gradle Qodana Plugin][gh:gradle-qodana-plugin], so you can use it on the local environment or any CI other than GitHub Actions.
- using the [Qodana IntelliJ GitHub Action][jb:qodana-github-action], run automatically within
the [Build](.github/workflows/build.yml) workflow,
- with the [Gradle Qodana Plugin][gh:gradle-qodana-plugin], so you can use it on the local environment or any CI other
than GitHub Actions.
Qodana inspection is configured with the `qodana { ... }` section in the Gradle build file and [`qodana.yml`][file:qodana.yml] YAML configuration file.
Qodana inspection is configured with the `qodana { ... }` section in the Gradle build file and [
`qodana.yml`][file:qodana.yml] YAML configuration file.
> [!NOTE]
> Qodana requires Docker to be installed and available in your environment.
To run inspections, you can use a predefined *Run Qodana* configuration, which will provide a full report on `http://localhost:8080`, or invoke the Gradle task directly with the `./gradlew runInspections` command.
To run inspections, you can use a predefined *Run Qodana* configuration, which will provide a full report on
`http://localhost:8080`, or invoke the Gradle task directly with the `./gradlew runInspections` command.
A final report is available in the `./build/reports/inspections/` directory.
![Qodana][file:qodana.png]
## Predefined Run/Debug configurations
Within the default project structure, there is a `.run` directory provided containing predefined *Run/Debug configurations* that expose corresponding Gradle tasks:
Within the default project structure, there is a `.run` directory provided containing predefined *Run/Debug
configurations* that expose corresponding Gradle tasks:
![Run/Debug configurations][file:run-debug-configurations.png]
| Configuration name | Description |
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| Run Plugin | Runs [`:runIde`][gh:intellij-platform-gradle-plugin-runIde] IntelliJ Platform Gradle Plugin task. Use the *Debug* icon for plugin debugging. |
| Run Tests | Runs [`:test`][gradle:lifecycle-tasks] Gradle task. |
| Configuration name | Description |
|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Run Plugin | Runs [`:runIde`][gh:intellij-platform-gradle-plugin-runIde] IntelliJ Platform Gradle Plugin task. Use the *Debug* icon for plugin debugging. |
| Run Tests | Runs [`:test`][gradle:lifecycle-tasks] Gradle task. |
| Run Verifications | Runs [`:verifyPlugin`][gh:intellij-platform-gradle-plugin-verifyPlugin] IntelliJ Platform Gradle Plugin task to check the plugin compatibility against the specified IntelliJ IDEs. |
> [!NOTE]
@ -336,59 +399,64 @@ Within the default project structure, there is a `.run` directory provided conta
>
> ![Run/Debug configuration logs][file:run-logs.png]
## Continuous integration
Continuous integration depends on [GitHub Actions][gh:actions], a set of workflows that make it possible to automate your testing and release process.
Thanks to such automation, you can delegate the testing and verification phases to the Continuous Integration (CI) and instead focus on development (and writing more tests).
Continuous integration depends on [GitHub Actions][gh:actions], a set of workflows that make it possible to automate
your testing and release process.
Thanks to such automation, you can delegate the testing and verification phases to the Continuous Integration (CI) and
instead focus on development (and writing more tests).
> [!NOTE]
> To ensure the "Create Pull Request" step functions correctly in the "Publish Plugin" job, make sure to enable "Read and write permissions" for actions by navigating to `⚙️ Settings > Actions > General > Workflow permissions`.
> To ensure the "Create Pull Request" step functions correctly in the "Publish Plugin" job, make sure to enable "Read
> and write permissions" for actions by navigating to `⚙️ Settings > Actions > General > Workflow permissions`.
In the `.github/workflows` directory, you can find definitions for the following GitHub Actions workflows:
- [Build](.github/workflows/build.yml)
- Triggered on `push` and `pull_request` events.
- Runs the *Gradle Wrapper Validation Action* to verify the wrapper's checksum.
- Runs the `verifyPlugin` and `test` Gradle tasks.
- Builds the plugin with the `buildPlugin` Gradle task and provides the artifact for the next jobs in the workflow.
- Verifies the plugin using the *IntelliJ Plugin Verifier* tool.
- Prepares a draft release of the GitHub Releases page for manual verification.
- Triggered on `push` and `pull_request` events.
- Runs the *Gradle Wrapper Validation Action* to verify the wrapper's checksum.
- Runs the `verifyPlugin` and `test` Gradle tasks.
- Builds the plugin with the `buildPlugin` Gradle task and provides the artifact for the next jobs in the workflow.
- Verifies the plugin using the *IntelliJ Plugin Verifier* tool.
- Prepares a draft release of the GitHub Releases page for manual verification.
- [Release](.github/workflows/release.yml)
- Triggered on `released` event.
- Updates `CHANGELOG.md` file with the content provided with the release note.
- Signs the plugin with a provided certificate before publishing.
- Publishes the plugin to JetBrains Marketplace using the provided `PUBLISH_TOKEN`.
- Sets publish channel depending on the plugin version, i.e. `1.0.0-beta` -> `beta` channel.
- Patches the Changelog and commits.
- Triggered on `released` event.
- Updates `CHANGELOG.md` file with the content provided with the release note.
- Signs the plugin with a provided certificate before publishing.
- Publishes the plugin to JetBrains Marketplace using the provided `PUBLISH_TOKEN`.
- Sets publish channel depending on the plugin version, i.e. `1.0.0-beta` -> `beta` channel.
- Patches the Changelog and commits.
- [Run UI Tests](.github/workflows/run-ui-tests.yml)
- Triggered manually.
- Runs for macOS, Windows, and Linux separately.
- Runs `runIdeForUiTests` and `test` Gradle tasks.
- Triggered manually.
- Runs for macOS, Windows, and Linux separately.
- Runs `runIdeForUiTests` and `test` Gradle tasks.
- [Template Cleanup](.github/workflows/template-cleanup.yml)
- Triggered once on the `push` event when a new template-based repository has been created.
- Overrides the scaffold with files from the `.github/template-cleanup` directory.
- Overrides JetBrains-specific sentences or package names with ones specific to the target repository.
- Removes redundant files.
- Triggered once on the `push` event when a new template-based repository has been created.
- Overrides the scaffold with files from the `.github/template-cleanup` directory.
- Overrides JetBrains-specific sentences or package names with ones specific to the target repository.
- Removes redundant files.
All the workflow files have accurate documentation, so it's a good idea to take a look through their sources.
### Dependencies management
This Template project depends on Gradle plugins and external libraries and during the development, you will add more of them.
This Template project depends on Gradle plugins and external libraries and during the development, you will add more
of them.
All plugins and dependencies used by Gradle are managed with [Gradle version catalog][gradle:version-catalog], which defines versions and coordinates of your dependencies in the [`gradle/libs.versions.toml`][file:libs.versions.toml] file.
All plugins and dependencies used by Gradle are managed with [Gradle version catalog][gradle:version-catalog], which
defines versions and coordinates of your dependencies in the [`gradle/libs.versions.toml`][file:libs.versions.toml]
file.
> [!NOTE]
> To add a new dependency to the project, in the `dependencies { ... }` block, add:
>
>
> ```kotlin
> dependencies {
> implementation(libs.annotations)
> }
> ```
>
>
> and define the dependency in the [`gradle/libs.versions.toml`][file:libs.versions.toml] file as follows:
> ```toml
> [versions]
@ -398,9 +466,12 @@ All plugins and dependencies used by Gradle are managed with [Gradle version cat
> annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" }
> ```
Keeping the project in good shape and having all the dependencies up-to-date requires time and effort, but it is possible to automate that process using [Dependabot][gh:dependabot].
Keeping the project in good shape and having all the dependencies up-to-date requires time and effort, but it is
possible to automate that process using [Dependabot][gh:dependabot].
Dependabot is a bot provided by GitHub to check the build configuration files and review any outdated or insecure dependencies of yours in case if any update is available, it creates a new pull request providing [the proper change][gh:dependabot-pr].
Dependabot is a bot provided by GitHub to check the build configuration files and review any outdated or insecure
dependencies of yours in case if any update is available, it creates a new pull request
providing [the proper change][gh:dependabot-pr].
> [!NOTE]
> Dependabot doesn't yet support checking of the Gradle Wrapper.
@ -420,6 +491,7 @@ The best way to do this is to provide release notes.
The changelog is a curated list that contains information about any new features, fixes, and deprecations.
When they're provided, these lists are available in a few different places:
- the [CHANGELOG.md](./CHANGELOG.md) file,
- the [Releases page][gh:releases],
- the *What's new* section of the JetBrains Marketplace Plugin page,
@ -428,7 +500,8 @@ When they're provided, these lists are available in a few different places:
There are many methods for handling the project's changelog.
The one used in the current template project is the [Keep a Changelog][keep-a-changelog] approach.
The [Gradle Changelog Plugin][gh:gradle-changelog-plugin] takes care of propagating information provided within the [CHANGELOG.md](./CHANGELOG.md) to the [IntelliJ Platform Gradle Plugin][gh:intellij-platform-gradle-plugin].
The [Gradle Changelog Plugin][gh:gradle-changelog-plugin] takes care of propagating information provided within
the [CHANGELOG.md](./CHANGELOG.md) to the [IntelliJ Platform Gradle Plugin][gh:intellij-platform-gradle-plugin].
You only have to take care of writing down the actual changes in proper sections of the `[Unreleased]` section.
You start with an almost empty changelog:
@ -441,10 +514,13 @@ You start with an almost empty changelog:
- Initial scaffold created from [IntelliJ Platform Plugin Template](https://github.com/JetBrains/intellij-platform-plugin-template)
```
Now proceed with providing more entries to the `Added` group, or any other one that suits your change the most (see [How do I make a good changelog?][keep-a-changelog-how] for more details).
Now proceed with providing more entries to the `Added` group, or any other one that suits your change the most (
see [How do I make a good changelog?][keep-a-changelog-how] for more details).
When releasing a plugin update, you don't have to care about bumping the `[Unreleased]` header to the upcoming version it will be handled automatically on the Continuous Integration (CI) after you publish your plugin.
GitHub Actions will swap it and provide you an empty section for the next release so that you can proceed with your development:
When releasing a plugin update, you don't have to care about bumping the `[Unreleased]` header to the upcoming version
it will be handled automatically on the Continuous Integration (CI) after you publish your plugin.
GitHub Actions will swap it and provide you an empty section for the next release so that you can proceed with your
development:
```
# YourPlugin Changelog
@ -460,12 +536,14 @@ GitHub Actions will swap it and provide you an empty section for the next releas
- One annoying bug
```
To configure how the Changelog plugin behaves, i.e., to create headers with the release date, see the [Gradle Changelog Plugin][gh:gradle-changelog-plugin] README file.
To configure how the Changelog plugin behaves, i.e., to create headers with the release date, see
the [Gradle Changelog Plugin][gh:gradle-changelog-plugin] README file.
### Release flow
The release process depends on the workflows already described above.
When your main branch receives a new pull request or a direct push, the [Build](.github/workflows/build.yml) workflow runs multiple tests on your plugin and prepares a draft release.
When your main branch receives a new pull request or a direct push, the [Build](.github/workflows/build.yml) workflow
runs multiple tests on your plugin and prepares a draft release.
![Release draft][file:draft-release.png]
@ -475,19 +553,25 @@ The changelog is provided automatically using the [gradle-changelog-plugin][gh:g
An artifact file is also built with the plugin attached.
Every new Build overrides the previous draft to keep your *Releases* page clean.
When you edit the draft and use the <kbd>Publish release</kbd> button, GitHub will tag your repository with the given version and add a new entry to the Releases tab.
Next, it will notify users who are *watching* the repository, triggering the final [Release](.github/workflows/release.yml) workflow.
When you edit the draft and use the <kbd>Publish release</kbd> button, GitHub will tag your repository with the given
version and add a new entry to the Releases tab.
Next, it will notify users who are *watching* the repository, triggering the
final [Release](.github/workflows/release.yml) workflow.
### Plugin signing
Plugin Signing is a mechanism introduced in the 2021.2 release cycle to increase security in [JetBrains Marketplace](https://plugins.jetbrains.com) and all of our IntelliJ-based IDEs.
Plugin Signing is a mechanism introduced in the 2021.2 release cycle to increase security
in [JetBrains Marketplace](https://plugins.jetbrains.com) and all of our IntelliJ-based IDEs.
JetBrains Marketplace signing is designed to ensure that plugins aren't modified over the course of the publishing and delivery pipeline.
JetBrains Marketplace signing is designed to ensure that plugins aren't modified over the course of the publishing and
delivery pipeline.
The current project provides a predefined plugin signing configuration that lets you sign and publish your plugin from the Continuous Integration (CI) and local environments.
The current project provides a predefined plugin signing configuration that lets you sign and publish your plugin from
the Continuous Integration (CI) and local environments.
All the configuration related to the signing should be provided using [environment variables](#environment-variables).
To find out how to generate signing certificates, check the [Plugin Signing][docs:plugin-signing] section in the IntelliJ Platform Plugin SDK documentation.
To find out how to generate signing certificates, check the [Plugin Signing][docs:plugin-signing] section in the
IntelliJ Platform Plugin SDK documentation.
> [!NOTE]
> Remember to encode your secret environment variables using `base64` encoding to avoid issues with multi-line values.
@ -495,23 +579,29 @@ To find out how to generate signing certificates, check the [Plugin Signing][doc
### Publishing the plugin
> [!TIP]
> Make sure to follow all guidelines listed in [Publishing a Plugin][docs:publishing] to follow all recommended and required steps.
> Make sure to follow all guidelines listed in [Publishing a Plugin][docs:publishing] to follow all recommended and
> required steps.
Releasing a plugin to [JetBrains Marketplace](https://plugins.jetbrains.com) is a straightforward operation that uses the `publishPlugin` Gradle task provided by the [intellij-platform-gradle-plugin][gh:intellij-platform-gradle-plugin-docs].
In addition, the [Release](.github/workflows/release.yml) workflow automates this process by running the task when a new release appears in the GitHub Releases section.
Releasing a plugin to [JetBrains Marketplace](https://plugins.jetbrains.com) is a straightforward operation that uses
the `publishPlugin` Gradle task provided by
the [intellij-platform-gradle-plugin][gh:intellij-platform-gradle-plugin-docs].
In addition, the [Release](.github/workflows/release.yml) workflow automates this process by running the task when a new
release appears in the GitHub Releases section.
> [!NOTE]
> Set a suffix to the plugin version to publish it in the custom repository channel, i.e. `v1.0.0-beta` will push your plugin to the `beta` [release channel][docs:release-channel].
> Set a suffix to the plugin version to publish it in the custom repository channel, i.e. `v1.0.0-beta` will push your
> plugin to the `beta` [release channel][docs:release-channel].
The authorization process relies on the `PUBLISH_TOKEN` secret environment variable, specified in the `⚙️ Settings > Secrets and variables > Actions` section of your project repository.
The authorization process relies on the `PUBLISH_TOKEN` secret environment variable, specified in the
`⚙️ Settings > Secrets and variables > Actions` section of your project repository.
You can get that token in your JetBrains Marketplace profile dashboard in the [My Tokens][jb:my-tokens] tab.
> [!WARNING]
> Before using the automated deployment process, it is necessary to manually create a new plugin in JetBrains Marketplace to specify options like the license, repository URL, etc.
> Before using the automated deployment process, it is necessary to manually create a new plugin in JetBrains
> Marketplace to specify options like the license, repository URL, etc.
> Please follow the [Publishing a Plugin][docs:publishing] instructions.
## FAQ
### How to use Java in my project?
@ -523,11 +613,13 @@ You can still replace it or add the `/src/main/java` directory to start working
### How to disable *tests* or *build* job using the `[skip ci]` commit message?
Since February 2021, GitHub Actions [support the skip CI feature][github-actions-skip-ci].
If the message contains one of the following strings: `[skip ci]`, `[ci skip]`, `[no ci]`, `[skip actions]`, or `[actions skip]` workflows will not be triggered.
If the message contains one of the following strings: `[skip ci]`, `[ci skip]`, `[no ci]`, `[skip actions]`, or
`[actions skip]` workflows will not be triggered.
### Why does the draft release no longer contain a built plugin artifact?
All the binaries created with each workflow are still available, but as an output artifact of each run together with tests and Qodana results.
All the binaries created with each workflow are still available, but as an output artifact of each run together with
tests and Qodana results.
That approach gives more possibilities for testing and debugging pre-releases, for example, in your local environment.
## Useful links
@ -547,77 +639,137 @@ That approach gives more possibilities for testing and debugging pre-releases, f
- [GitHub Actions][gh:actions]
[docs]: https://plugins.jetbrains.com/docs/intellij?from=IJPluginTemplate
[docs:intellij-platform-kotlin-oom]: https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#incremental-compilation
[docs:intro]: https://plugins.jetbrains.com/docs/intellij/intellij-platform.html?from=IJPluginTemplate
[docs:kotlin-ui-dsl]: https://plugins.jetbrains.com/docs/intellij/kotlin-ui-dsl-version-2.html?from=IJPluginTemplate
[docs:kotlin]: https://plugins.jetbrains.com/docs/intellij/using-kotlin.html?from=IJPluginTemplate
[docs:kotlin-stdlib]: https://plugins.jetbrains.com/docs/intellij/using-kotlin.html?from=IJPluginTemplate#kotlin-standard-library
[docs:plugin.xml]: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html?from=IJPluginTemplate
[docs:publishing]: https://plugins.jetbrains.com/docs/intellij/publishing-plugin.html?from=IJPluginTemplate
[docs:release-channel]: https://plugins.jetbrains.com/docs/intellij/publishing-plugin.html?from=IJPluginTemplate#specifying-a-release-channel
[docs:using-gradle]: https://plugins.jetbrains.com/docs/intellij/developing-plugins.html?from=IJPluginTemplate
[docs:plugin-signing]: https://plugins.jetbrains.com/docs/intellij/plugin-signing.html?from=IJPluginTemplate
[docs:project-structure-settings]: https://www.jetbrains.com/help/idea/project-settings-and-structure.html
[docs:testing-plugins]: https://plugins.jetbrains.com/docs/intellij/testing-plugins.html?from=IJPluginTemplate
[file:draft-release.png]: ./.github/readme/draft-release.png
[file:get-from-version-control]: ./.github/readme/get-from-version-control.png
[file:gradle.properties]: ./gradle.properties
[file:intellij-platform-plugin-template-dark]: ./.github/readme/intellij-platform-plugin-template-dark.svg#gh-dark-mode-only
[file:intellij-platform-plugin-template-light]: ./.github/readme/intellij-platform-plugin-template-light.svg#gh-light-mode-only
[file:libs.versions.toml]: ./gradle/libs.versions.toml
[file:project-structure-sdk.png]: ./.github/readme/project-structure-sdk.png
[file:plugin.xml]: ./src/main/resources/META-INF/plugin.xml
[file:qodana.png]: ./.github/readme/qodana.png
[file:qodana.yml]: ./qodana.yml
[file:run-debug-configurations.png]: ./.github/readme/run-debug-configurations.png
[file:run-logs.png]: ./.github/readme/run-logs.png
[file:settings-secrets.png]: ./.github/readme/settings-secrets.png
[file:template_cleanup.yml]: ./.github/workflows/template-cleanup.yml
[file:ui-testing.png]: ./.github/readme/ui-testing.png
[file:use-this-template.png]: ./.github/readme/use-this-template.png
[gh:actions]: https://help.github.com/en/actions
[gh:build]: https://github.com/JetBrains/intellij-platform-plugin-template/actions?query=workflow%3ABuild
[gh:code-samples]: https://github.com/JetBrains/intellij-sdk-code-samples
[gh:dependabot]: https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/keeping-your-dependencies-updated-automatically
[gh:dependabot-pr]: https://github.com/JetBrains/intellij-platform-plugin-template/pull/73
[gh:gradle-changelog-plugin]: https://github.com/JetBrains/gradle-changelog-plugin
[gh:intellij-platform-gradle-plugin]: https://github.com/JetBrains/intellij-platform-gradle-plugin
[gh:intellij-platform-gradle-plugin-docs]: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin.html
[gh:intellij-platform-gradle-plugin-runIde]: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-tasks.html#runIde
[gh:intellij-platform-gradle-plugin-verifyPlugin]: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-tasks.html#verifyPlugin
[gh:gradle-qodana-plugin]: https://github.com/JetBrains/gradle-qodana-plugin
[gh:intellij-ui-test-robot]: https://github.com/JetBrains/intellij-ui-test-robot
[gh:intellij-ide-starter]: https://github.com/JetBrains/intellij-ide-starter
[gh:kover]: https://github.com/Kotlin/kotlinx-kover
[gh:releases]: https://github.com/JetBrains/intellij-platform-plugin-template/releases
[gh:ui-test-example]: https://github.com/JetBrains/intellij-ui-test-robot/tree/master/ui-test-example
[docs:ui-tests]: https://plugins.jetbrains.com/docs/intellij/integration-tests-ui.html
[gradle]: https://gradle.org
[gradle:build-cache]: https://docs.gradle.org/current/userguide/build_cache.html
[gradle:configuration-cache]: https://docs.gradle.org/current/userguide/configuration_cache.html
[gradle:kotlin-dsl]: https://docs.gradle.org/current/userguide/kotlin_dsl.html
[gradle:kotlin-dsl-assignment]: https://docs.gradle.org/current/userguide/kotlin_dsl.html#kotdsl:assignment
[gradle:lifecycle-tasks]: https://docs.gradle.org/current/userguide/java_plugin.html#lifecycle_tasks
[gradle:releases]: https://gradle.org/releases
[gradle:version-catalog]: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
[jb:github]: https://github.com/JetBrains/.github/blob/main/profile/README.md
[jb:download-ij]: https://www.jetbrains.com/idea/download
[jb:forum]: https://intellij-support.jetbrains.com/hc/en-us/community/topics/200366979-IntelliJ-IDEA-Open-API-and-Plugin-Development
[jb:ipe]: https://jb.gg/ipe
[jb:my-tokens]: https://plugins.jetbrains.com/author/me/tokens
[jb:paid-plugins]: https://plugins.jetbrains.com/docs/marketplace/paid-plugins-marketplace.html
[jb:qodana]: https://www.jetbrains.com/help/qodana
[jb:qodana-github-action]: https://www.jetbrains.com/help/qodana/qodana-intellij-github-action.html
[jb:quality-guidelines]: https://plugins.jetbrains.com/docs/marketplace/quality-guidelines.html
[jb:slack]: https://plugins.jetbrains.com/slack
[jb:twitter]: https://twitter.com/JBPlatform
[jb:ui-guidelines]: https://jetbrains.github.io/ui
[codecov]: https://codecov.io
[github-actions-skip-ci]: https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/
[keep-a-changelog]: https://keepachangelog.com
[keep-a-changelog-how]: https://keepachangelog.com/en/1.0.0/#how
[semver]: https://semver.org
[xpath]: https://www.w3.org/TR/xpath-21/

View File

@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.changelog) // Gradle Changelog Plugin
alias(libs.plugins.qodana) // Gradle Qodana Plugin
alias(libs.plugins.kover) // Gradle Kover Plugin
idea // IntelliJ IDEA support
}
group = providers.gradleProperty("pluginGroup").get()
@ -22,6 +23,7 @@ kotlin {
// Configure project's dependencies
repositories {
mavenCentral()
maven("https://cache-redirector.jetbrains.com/packages.jetbrains.team/maven/p/ij/intellij-ide-starter")
// IntelliJ Platform Gradle Plugin Repositories Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-repositories-extension.html
intellijPlatform {
@ -29,16 +31,42 @@ repositories {
}
}
sourceSets {
create("uiTest", Action<SourceSet> {
compileClasspath += sourceSets["main"].output + sourceSets["test"].output
runtimeClasspath += sourceSets["main"].output + sourceSets["test"].output
})
}
// Configure IntelliJ IDEA to recognize uiTest as test sources
idea {
module {
testSources.from(sourceSets["uiTest"].kotlin.srcDirs)
testResources.from(sourceSets["uiTest"].resources.srcDirs)
}
}
val uiTestImplementation: Configuration by configurations.getting {
extendsFrom(configurations.testImplementation.get())
}
val uiTestRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.testRuntimeOnly.get())
}
// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
dependencies {
testImplementation(libs.junit)
testImplementation(libs.opentest4j)
// IntelliJ Platform Gradle Plugin Dependencies Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html
intellijPlatform {
create(providers.gradleProperty("platformType"), providers.gradleProperty("platformVersion"))
// Plugin Dependencies. Uses `platformBundledPlugins` property from the gradle.properties file for bundled IntelliJ Platform plugins.
val platformVersion = providers.gradleProperty("platformVersion")
val platformType = providers.gradleProperty("platformType")
create(platformType, platformVersion) {
useInstaller = false
}
bundledPlugins(providers.gradleProperty("platformBundledPlugins").map { it.split(',') })
// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file for plugin from JetBrains Marketplace.
@ -47,11 +75,46 @@ dependencies {
// Module Dependencies. Uses `platformBundledModules` property from the gradle.properties file for bundled IntelliJ Platform modules.
bundledModules(providers.gradleProperty("platformBundledModules").map { it.split(',') })
// Test framework dependencies
testFramework(TestFrameworkType.Platform)
testFramework(TestFrameworkType.JUnit5)
// UI Test framework dependencies
testFramework(TestFrameworkType.Starter, configurationName = "uiTestImplementation")
testFramework(TestFrameworkType.JUnit5, configurationName = "uiTestImplementation")
}
testImplementation(libs.junit)
testImplementation(libs.opentest4j)
// UI Test dependencies
uiTestImplementation("org.kodein.di:kodein-di-jvm:7.26.1")
uiTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
// JUnit 5 is required for UI tests
uiTestImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
uiTestRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
kotlin {
jvmToolchain {
languageVersion = JavaLanguageVersion.of(21)
@Suppress("UnstableApiUsage")
vendor = JvmVendorSpec.JETBRAINS
}
compilerOptions {
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_21)
languageVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
freeCompilerArgs.addAll(
"-Xjvm-default=all",
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
)
}
}
// Configure IntelliJ Platform Gradle Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html
intellijPlatform {
pluginConfiguration {
name = providers.gradleProperty("pluginName")
@ -99,7 +162,8 @@ intellijPlatform {
// The pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3
// Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more:
// https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel
channels = providers.gradleProperty("pluginVersion").map { listOf(it.substringAfter('-', "").substringBefore('.').ifEmpty { "default" }) }
channels = providers.gradleProperty("pluginVersion")
.map { listOf(it.substringAfter('-', "").substringBefore('.').ifEmpty { "default" }) }
}
pluginVerification {
@ -131,28 +195,81 @@ tasks {
gradleVersion = providers.gradleProperty("gradleVersion").get()
}
runIde {
systemProperties(
"ide.native.launcher" to true,
"ide.show.tips.on.startup.default.value" to false,
"jb.consents.confirmation.enabled" to false
)
}
publishPlugin {
dependsOn(patchChangelog)
}
}
intellijPlatformTesting {
runIde {
register("runIdeForUiTests") {
task {
jvmArgumentProviders += CommandLineArgumentProvider {
listOf(
"-Drobot-server.port=8082",
"-Dide.mac.message.dialogs.as.sheets=false",
"-Djb.privacy.policy.text=<!--999.999-->",
"-Djb.consents.confirmation.enabled=false",
)
}
}
plugins {
robotServerPlugin()
}
test {
useJUnitPlatform {
excludeTags("ui")
}
// Enable process-level parallelism (safer than method-level parallelism)
maxParallelForks = minOf(Runtime.getRuntime().availableProcessors() / 2, 3)
// Keep JUnit execution sequential within each process for stability
systemProperty("junit.jupiter.execution.parallel.enabled", "false")
systemProperty("idea.home.path", prepareTestSandbox.get().getDestinationDir().parentFile.absolutePath)
systemProperty("idea.force.use.core.classloader", "true")
jvmArgs = listOf(
"-Didea.trust.all.projects=true",
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.desktop/javax.swing=ALL-UNNAMED"
)
dependsOn("buildPlugin")
}
register<Test>("uiTest") {
description = "Runs only the UI tests that start the IDE"
group = "verification"
testClassesDirs = sourceSets["uiTest"].output.classesDirs
classpath = sourceSets["uiTest"].runtimeClasspath
useJUnitPlatform {
includeTags("ui")
}
// UI tests should run sequentially (not in parallel) to avoid conflicts
maxParallelForks = 1
// Increase memory for UI tests
minHeapSize = "1g"
maxHeapSize = "4g"
systemProperty("path.to.build.plugin", buildPlugin.get().archiveFile.get().asFile.absolutePath)
systemProperty("idea.home.path", prepareTestSandbox.get().getDestinationDir().parentFile.absolutePath)
systemProperty(
"allure.results.directory", project.layout.buildDirectory.get().asFile.absolutePath + "/allure-results"
)
systemProperty("uiPlatformBuildVersion", providers.gradleProperty("uiPlatformBuildVersion").get())
// Disable IntelliJ test listener that conflicts with standard JUnit
systemProperty("idea.test.cyclic.buffer.size", "0")
// Add required JVM arguments
jvmArgumentProviders += CommandLineArgumentProvider {
mutableListOf(
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.desktop/javax.swing=ALL-UNNAMED"
)
}
dependsOn(buildPlugin)
}
}

View File

@ -8,3 +8,8 @@ coverage:
patch:
default:
informational: true
ignore:
- src/test/
- src/uiTest/

View File

@ -1,34 +1,29 @@
# IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
pluginGroup = org.jetbrains.plugins.template
pluginName = IntelliJ Platform Plugin Template
pluginRepositoryUrl = https://github.com/JetBrains/intellij-platform-plugin-template
pluginGroup=org.jetbrains.plugins.template
pluginName=IntelliJ Platform Plugin Template
pluginRepositoryUrl=https://github.com/JetBrains/intellij-platform-plugin-template
# SemVer format -> https://semver.org
pluginVersion = 2.3.1
pluginVersion=2.3.2
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 243
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
platformVersion = 2024.3.6
platformType=IC
platformVersion=2024.3.6
# Intellij Platform UI Platform Build Version -> https://plugins.jetbrains.com/docs/intellij/integration-tests-ui.html
uiPlatformBuildVersion=243.26574.91
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.jetbrains.php:203.4449.22, org.intellij.scala:2023.3.27@EAP
platformPlugins =
platformPlugins=
# Example: platformBundledPlugins = com.intellij.java
platformBundledPlugins =
platformBundledPlugins=
# Example: platformBundledModules = intellij.spellchecker
platformBundledModules =
platformBundledModules=
# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 9.0.0
gradleVersion=9.0.0
# Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib
kotlin.stdlib.default.dependency = false
kotlin.stdlib.default.dependency=false
# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html
org.gradle.configuration-cache = true
org.gradle.configuration-cache=true
# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html
org.gradle.caching = true
org.gradle.caching=true

View File

@ -5,18 +5,24 @@ opentest4j = "1.3.0"
# plugins
changelog = "2.4.0"
intelliJPlatform = "2.7.1"
intelliJPlatform = "2.7.2"
kotlin = "2.2.0"
kover = "0.9.1"
qodana = "2025.1.1"
qodana = "2025.2.1"
[libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" }
opentest4j = { group = "org.opentest4j", name = "opentest4j", version.ref = "opentest4j" }
[plugins]
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
intelliJPlatform = { id = "org.jetbrains.intellij.platform", version.ref = "intelliJPlatform" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
qodana = { id = "org.jetbrains.qodana", version.ref = "qodana" }

View File

@ -0,0 +1,182 @@
package org.jetbrains.plugins.template.ui
import com.intellij.driver.sdk.ui.components.button
import com.intellij.driver.sdk.ui.components.ideFrame
import com.intellij.driver.sdk.ui.components.welcomeScreen
import com.intellij.driver.sdk.ui.shouldBe
import com.intellij.driver.sdk.wait
import com.intellij.driver.sdk.waitForIndicators
import com.intellij.ide.starter.driver.engine.BackgroundRun
import com.intellij.ide.starter.driver.engine.runIdeWithDriver
import com.intellij.ide.starter.junit5.config.UseLatestDownloadedIdeBuild
import org.jetbrains.plugins.template.MyBundle
import org.jetbrains.plugins.template.ui.toolwindow.jlabel
import org.jetbrains.plugins.template.ui.toolwindow.myToolWindow
import org.junit.jupiter.api.*
import org.junit.jupiter.api.extension.ExtendWith
import java.nio.file.Paths
import kotlin.time.Duration.Companion.seconds
/**
* Example UI test demonstrating how to test IntelliJ Platform plugins using the IDE Starter framework.
*
* This test class showcases:
* - Setting up and tearing down an IDE instance for testing
* - Creating a new project through the IDE's welcome screen
* - Interacting with custom plugin UI components (tool windows)
* - Using the Driver SDK for UI automation
*
* ## Test Lifecycle:
* 1. `@BeforeEach` - Starts a new IDE instance with the plugin installed
* 2. Test method executes - Interacts with IDE UI components
* 3. `@AfterEach` - Closes the IDE instance
* 4. `@AfterAll` - Cleans up test artifacts
*
* ## Key Annotations:
* - `@Tag("ui")` - Marks this as a UI test (excluded from regular test runs)
* - `@TestInstance(PER_METHOD)` - New instance for each test method
* - `@ExtendWith(UseLatestDownloadedIdeBuild)` - Uses the IDE version from gradle.properties
*
* @see Setup for test configuration details
* @see MyToolWindowPanelUIComponent for custom UI component definitions
*/
@Tag("ui")
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
@ExtendWith(UseLatestDownloadedIdeBuild::class)
class MyProjectUITest {
companion object {
// Generate a unique folder name for the test project to avoid conflicts
val testProjectFolder = "my-test-project-${System.currentTimeMillis()}"
/**
* Cleanup method that runs after all tests in this class.
* Removes the test project folder created during testing to keep the system clean.
*/
@JvmStatic
@AfterAll
fun cleanUpTestFolder() {
val projectPath = Paths.get(System.getProperty("user.home"), "IdeaProjects", testProjectFolder)
val projectFile = projectPath.toFile()
if (projectFile.exists()) {
projectFile.deleteRecursively()
println("Successfully deleted test folder: $projectPath")
} else {
println("Test folder does not exist, skipping cleanup: $projectPath")
}
}
}
/**
* The IDE instance running in the background.
* Initialized in @BeforeEach and closed in @AfterEach.
*/
private lateinit var run: BackgroundRun
/**
* Sets up the test environment before each test method.
*
* This method:
* 1. Creates a test context using the Setup class
* 2. Starts an IDE instance with the plugin installed
* 3. Prepares the IDE for UI interaction through the Driver SDK
*/
@BeforeEach
fun initContext() {
println("Initializing test context")
println("Test project will be created as: $testProjectFolder")
run = Setup.setupTestContext("MyProjectUITest").runIdeWithDriver()
}
/**
* Tears down the test environment after each test method.
*
* Safely closes the IDE instance if it was successfully started.
* The initialization check prevents errors if the setup failed.
*/
@AfterEach
fun closeIde() {
if (::run.isInitialized) {
println("Closing IDE")
run.closeIdeAndWait()
} else {
println("IDE was not started, skipping close")
}
}
/**
* Example test that demonstrates creating a project and interacting with a custom tool window.
*
* ## Test Flow:
* 1. Opens the IDE welcome screen
* 2. Creates a new Java project
* 3. Waits for IDE indexing to complete
* 4. Interacts with the plugin's custom tool window
* 5. Verifies UI components are present and functional
*
* ## How to Write Your Own Tests:
* - Use `welcomeScreen { }` to interact with the welcome dialog
* - Use `ideFrame { }` to interact with the main IDE window
* - Use `driver.waitForIndicators()` to wait for background tasks
* - Create custom UI component definitions (see MyToolWindowPanelUIComponent)
* - Use `shouldBe { }` for assertions on UI elements
*/
@Test
fun myProjectWithToolWindowTest() {
println("Starting my project test")
run.driver.withContext {
// === Step 1: Create a new project from the welcome screen ===
welcomeScreen {
println("Creating the new project from welcome screen")
createNewProjectButton.click()
newProjectDialog {
// Wait for the dialog to fully load
wait(1.seconds)
// Select project type - adjust based on your needs
chooseProjectType("Java")
// Verify UI state
sampleCodeLabel.isEnabled()
// Set project name to our test folder
setProjectName(testProjectFolder)
println("Set project name to: $testProjectFolder")
// Create the project
createButton.click()
println("Clicked create button")
}
}
// === Step 2: Interact with the IDE and your plugin ===
ideFrame {
// Wait for indexing and other background tasks to complete
driver.waitForIndicators(180.seconds)
// Example: Interact with the custom tool window from this template
// Replace this with your own plugin's UI components
myToolWindow {
// Find and verify a label component
jlabel("//div[@visible_text='${MyBundle.message("randomLabel", "?")}']").shouldBe {
present()
}
// Find and click a button
button(MyBundle.message("shuffle")).shouldBe {
present() && isEnabled()
}.click()
}
// Add more interactions with your plugin's UI here
// Example patterns:
// - Open menus: actionMenu("Tools").click()
// - Open dialogs: invokeAction("YourAction")
// - Verify notifications: notification { text.contains("Expected message") }
}
}
}
}

View File

@ -0,0 +1,37 @@
package org.jetbrains.plugins.template.ui
import com.intellij.driver.sdk.ui.Finder
import com.intellij.driver.sdk.ui.components.ComponentData
import com.intellij.driver.sdk.ui.components.UiComponent
import com.intellij.driver.sdk.ui.components.checkBox
import com.intellij.driver.sdk.ui.components.textField
import com.intellij.driver.sdk.ui.pasteText
import com.intellij.driver.sdk.ui.ui
/**
* This code is taken from the new version of: com.intellij.driver.sdk.ui.components.common.dialogs
* Available from version 2025.1 - so it can be remove once the pluginSinceBuild is increased.
*/
fun Finder.newProjectDialog(action: NewProjectDialogUI.() -> Unit) {
x("//div[@title='New Project']", NewProjectDialogUI::class.java).action()
}
open class NewProjectDialogUI(data: ComponentData) : UiComponent(data) {
fun setProjectName(text: String) {
nameTextField.doubleClick()
keyboard {
backspace()
driver.ui.pasteText(text)
}
}
fun chooseProjectType(projectType: String) {
projectTypeList.waitOneText(projectType).click()
}
val nameTextField = textField("//div[@accessiblename='Name:' and @class='JBTextField']")
open val createButton = x("//div[@text='Create']")
private val projectTypeList = x("//div[@class='JBList']")
val sampleCodeLabel = checkBox { byText("Add sample code") }
}

View File

@ -0,0 +1,129 @@
package org.jetbrains.plugins.template.ui
import com.intellij.ide.starter.buildTool.GradleBuildTool
import com.intellij.ide.starter.community.model.BuildType
import com.intellij.ide.starter.di.di
import com.intellij.ide.starter.ide.IDETestContext
import com.intellij.ide.starter.ide.IdeProductProvider
import com.intellij.ide.starter.models.TestCase
import com.intellij.ide.starter.path.GlobalPaths
import com.intellij.ide.starter.plugins.PluginConfigurator
import com.intellij.ide.starter.project.NoProject
import com.intellij.ide.starter.runner.Starter
import com.intellij.ide.starter.utils.Git
import com.intellij.openapi.util.SystemInfo
import org.kodein.di.DI
import org.kodein.di.bindSingleton
import java.nio.file.Paths
/**
* Custom GlobalPaths implementation that points to the project's build directory.
* This ensures all test artifacts are stored within the project structure.
*/
class TemplatePaths : GlobalPaths(Git.getRepoRoot().resolve("build"))
/**
* Setup class for configuring IntelliJ IDE UI tests using the IntelliJ IDE Starter framework.
*
* This class provides the necessary configuration to:
* - Initialize the test environment with proper paths and dependencies
* - Install the plugin under test into the IDE instance
* - Configure VM options for optimal test execution
* - Apply OS-specific settings for compatibility
*
* @see [IntelliJ IDE Starter Documentation](https://github.com/JetBrains/intellij-ide-starter)
*/
class Setup {
companion object {
init {
// Configure dependency injection to use our custom paths
di = DI.Companion {
extend(di)
bindSingleton<GlobalPaths>(overrides = true) { TemplatePaths() }
}
}
/**
* Sets up the test context for UI testing with IntelliJ IDE Starter.
*
* This method:
* 1. Creates a test case with the specified IDE version
* 2. Configures the test context with the built plugin
* 3. Applies VM options for proper IDE behavior during tests
* 4. Applies OS-specific configurations
*
* @param hyphenateWithClass The name of the test class (used for test identification)
* @return IDETestContext configured for running UI tests
*
* @throws IllegalStateException if required system properties are not set
*/
fun setupTestContext(hyphenateWithClass: String): IDETestContext {
// Create test case with the specified IDE version from gradle.properties
val testCase = TestCase(
IdeProductProvider.IC.copy(
buildNumber = System.getProperty("uiPlatformBuildVersion"),
buildType = BuildType.RELEASE.type
), NoProject
)
return Starter.newContext(testName = hyphenateWithClass, testCase = testCase).apply {
// Install the plugin that was built by the buildPlugin task
val pluginPath = System.getProperty("path.to.build.plugin")
PluginConfigurator(this).installPluginFromPath(Paths.get(pluginPath))
withBuildTool<GradleBuildTool>()
}.applyVMOptionsPatch {
// === Common system properties for all operating systems ===
// Required JVM arguments for module access
addSystemProperty("--add-opens", "java.base/java.lang=ALL-UNNAMED")
addSystemProperty("--add-opens", "java.desktop/javax.swing=ALL-UNNAMED")
// Core IDE configuration
addSystemProperty("idea.trust.all.projects", true) // Trust all projects automatically
addSystemProperty("jb.consents.confirmation.enabled", false) // Disable consent dialogs
addSystemProperty("jb.privacy.policy.text", "<!--999.999-->") // Skip privacy policy
addSystemProperty("ide.show.tips.on.startup.default.value", false) // No tips on startup
// Test framework configuration
addSystemProperty("junit.jupiter.extensions.autodetection.enabled", true)
addSystemProperty("shared.indexes.download.auto.consent", true)
// UI testing specific
addSystemProperty("expose.ui.hierarchy.url", true) // Enable UI hierarchy inspection
addSystemProperty("ide.experimental.ui", true) // Use new UI for testing
// === OS-specific system properties ===
when {
SystemInfo.isMac -> {
// macOS specific settings
addSystemProperty("ide.mac.file.chooser.native", false) // Use Java file chooser
addSystemProperty("ide.mac.message.dialogs.as.sheets", false) // Use regular dialogs
addSystemProperty("jbScreenMenuBar.enabled", false) // Disable native menu bar
addSystemProperty("ide.native.launcher", true) // Use native launcher
}
SystemInfo.isWindows -> {
// Windows specific settings
}
SystemInfo.isLinux -> {
// Linux specific settings
addSystemProperty("ide.browser.jcef.enabled", true)
addSystemProperty("ide.native.launcher", false) // Avoid launcher issues on Linux
// X11/Wayland compatibility
addSystemProperty("sun.java2d.uiScale.enabled", false)
addSystemProperty("sun.java2d.xrender", false)
}
}
}.addProjectToTrustedLocations()
}
}
}

View File

@ -0,0 +1,145 @@
package org.jetbrains.plugins.template.ui.toolwindow
import com.intellij.driver.sdk.ui.Finder
import com.intellij.driver.sdk.ui.components.*
import com.intellij.driver.sdk.ui.components.UiComponent.Companion.waitFound
import com.intellij.driver.sdk.ui.xQuery
import com.intellij.ide.starter.report.AllureHelper.step
import org.intellij.lang.annotations.Language
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
/**
* UI component definitions for testing the MyToolWindow custom tool window.
*
* This file demonstrates how to create custom UI component definitions for
* IntelliJ Platform plugin UI testing using the Driver SDK.
*
* ## Architecture:
* - Extension functions on `Finder` provide DSL-style access to UI components
* - Custom component classes (like `MyToolWindowPanel`) encapsulate complex UI structures
* - Helper functions simplify common UI element queries
*
* ## Key Concepts:
* 1. **Finder**: The main entry point for finding UI components in the IDE
* 2. **XPath Queries**: Used to locate specific UI elements by their properties
* 3. **Component Classes**: Custom classes that represent your plugin's UI components
* 4. **Allure Steps**: Optional test reporting integration for better test visibility
*
* @see [Driver SDK Documentation](https://github.com/JetBrains/intellij-ide-starter)
*/
/**
* Finds a JLabel component using an XPath query.
*
* This helper function show how you can extend the finding components.
* In this example we find a label component in the UI.
* If no XPath is provided, it finds any JLabel in the current context.
*
* ## Usage Examples:
* ```kotlin
* // Find a specific label by text
* jlabel("//div[@visible_text='My Label Text']")
*
* // Find any JLabel in context
* jlabel()
* ```
*
* @param xpath Optional XPath query to locate a specific label.
* The @Language annotation enables IDE support for XPath syntax.
* @return A JLabelUiComponent for further interaction
*/
fun Finder.jlabel(@Language("xpath") xpath: String? = null) =
x(xpath ?: xQuery { byType(javax.swing.JLabel::class.java) }, JLabelUiComponent::class.java)
/**
* Opens the MyToolWindow tool window from the left toolbar.
*
* This function navigates to the tool window stripe button and opens it.
* It's a prerequisite for interacting with the tool window contents.
*
* ## How it works:
* 1. Finds the left toolbar component
* 2. Locates the MyToolWindow stripe button by its accessible name
* 3. Opens the tool window if it's not already visible
*
* ## Customization:
* - Replace "MyToolWindow" with your tool window's ID
* - Adjust the toolbar location if your tool window is on a different side
*/
fun Finder.showMyToolWindow() = with(x(ToolWindowLeftToolbarUi::class.java) { byClass("ToolWindowLeftToolbar") }) {
val myToolWindowButton = x(StripeButtonUi::class.java) { byAccessibleName("MyToolWindow") }
myToolWindowButton.open()
}
/**
* Provides a scoped context for interacting with the MyToolWindow panel.
*
* This is the main entry point for tool window UI testing. It:
* 1. Opens the tool window if needed
* 2. Waits for the panel to be available
* 3. Executes test code within the panel's context
*
* ## Usage in Tests:
* ```kotlin
* ideFrame {
* myToolWindow {
* // Your test interactions here
* button("Click Me").click()
* jlabel("//div[@text='Result']").shouldBe { present() }
* }
* }
* ```
*
* ## Parameters:
* @param timeout Maximum time to wait for the tool window to appear (default: 20 seconds)
* @param block The test code to execute within the tool window context
*
* ## Allure Integration:
* The `step` wrapper creates a named step in Allure test reports,
* making it easier to understand test flow and debug failures.
*/
fun Finder.myToolWindow(timeout: Duration = 20.seconds, block: MyToolWindowPanel.() -> Unit) {
step("My Tool Window Panel") {
showMyToolWindow()
// Wait for the tool window's internal decorator to appear
// InternalDecoratorImpl is the container class for tool window content
x("//div[@class='InternalDecoratorImpl']", MyToolWindowPanel::class.java)
.waitFound(timeout)
.apply(block)
}
}
/**
* Custom UI component class representing the MyToolWindow panel.
*
* This class serves as a container for tool-window-specific UI interactions.
* Extend this class to add methods for interacting with your tool window's components.
*
* ## Adding Custom Methods:
* ```kotlin
* class MyToolWindowPanel(data: ComponentData) : UiComponent(data) {
* // Find a button by its text
* fun button(text: String) = x("//div[@defaultbutton and @text='$text']")
*
* // Find an input field
* fun inputField() = x("//div[@class='JTextField']")
*
* // Custom interaction method
* fun performSearch(query: String) {
* inputField().text = query
* button("Search").click()
* }
* }
* ```
*
* ## Best Practices:
* - Keep methods focused on single UI elements or actions
* - Use descriptive names that match your plugin's terminology
* - Document complex XPath queries or interaction patterns
* - Consider adding validation methods for common assertions
*/
class MyToolWindowPanel(data: ComponentData) : UiComponent(data)