### Simplest IDE Test Setup with @BeforeEach (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md Illustrates the simplest way to set up an IDE test using JUnit's `@BeforeEach` annotation. It initializes `IDETestContext` with a remote project and starts the IDE using `runIdeWithDriver()`. The test method then uses `bgRun.useDriverAndCloseIde` to execute test logic with the driver and ensure the IDE is closed afterwards. ```kotlin class OpenGradleJavaFileTest { private lateinit var bgRun: BackgroundRun @BeforeEach fun startIde() { bgRun = Starter.newContext(ideInfo = IdeProductProvider.IU) { project = RemoteArchiveProjectInfo(projectURL = "https://repo.labs.intellij.net/artifactory/idea-test-data/lwjgl3-maven-gradle_2.zip") }.runIdeWithDriver() } @Test fun import() { bgRun.useDriverAndCloseIde { // your test using a driver } } } ``` -------------------------------- ### Applying JUnit5 Extensions for Starter Configuration (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter/README.md This Kotlin code demonstrates how to apply JUnit5 extensions to a test class using the `@ExtendWith` annotation. `EnableClassFileVerification` and `UseLatestDownloadedIdeBuild` are examples of extensions that modify the `intellij-ide-starter`'s behavior, providing a convenient way to set configuration variables for tests. ```Kotlin @ExtendWith(EnableClassFileVerification::class) @ExtendWith(UseLatestDownloadedIdeBuild::class) class ClassWithTest { ... } ``` -------------------------------- ### Using IDE State Waiting Helpers (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md Provides examples of helper functions for waiting on common IDE states during tests. `waitForProjectOpen` ensures a project is open and all background processes are complete. `waitForIndicators` waits for all progress indicators to disappear from the status bar. `waitForCodeAnalysis` waits for the daemon to finish code analysis in a specified file. ```kotlin // 1. there must be an opened project and all progresses finished waitForProjectOpen(timeout) // 2. all progresses must disappear from status bar waitForIndicators(project, timeout) // 3. daemon must finish analysis in a file waitForCodeAnalysis(file) ``` -------------------------------- ### Invoking Custom Command in Performance Test (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter/documentation/createCustomPerformanceCommand.md This Kotlin snippet demonstrates how to integrate and invoke the custom command within an IntelliJ performance test using the `Starter` framework. It defines an extension function `runMyCommand` to add the custom command to a `CommandChain` and shows an example test class `ExampleOfMyCommandTest` that sets up a test context and runs the IDE with the custom command followed by `exitApp`. ```Kotlin fun T.runMyCommand(): T { addCommand(CMD_PREFIX + "myCommandName") return this } class ExampleOfMyCommandTest { @Test fun invokeMyCommand() { val context = Starter.newContext(testName = CurrentTestMethod.hyphenateWithClass(), testCase = TestCases.IU.JitPackAndroidExample) .skipIndicesInitialization() // skip indicies if indexing isn't necessary for test context.runIDE( commands = CommandChain() .runMyCommand() .exitApp() ) } } ``` -------------------------------- ### Reusing IDE Instance Across Tests with @BeforeAll/@AfterAll (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md Demonstrates how to reuse a single IDE instance across multiple tests within a class using JUnit's `@BeforeAll` and `@AfterAll` annotations. The IDE is started once before all tests and closed once after all tests, improving test performance. Test logic then accesses the shared driver instance via `run.driver.withContext`. ```kotlin class OpenGradleJavaFileTest { companion object { private lateinit var run: BackgroundRun @BeforeAll @JvmStatic fun startIde() { run = Starter.newContext(ideInfo = IdeProductProvider.IU) { project = RemoteArchiveProjectInfo(projectURL = "https://repo.labs.intellij.net/artifactory/idea-test-data/lwjgl3-maven-gradle_2.zip") }.runIdeWithDriver() } @AfterAll @JvmStatic fun closeIde() { run.closeIdeAndWait() } } @Test fun import() { run.driver.withContext { //your test goes here } } } ``` -------------------------------- ### Demonstrating Remote Reference Expiration (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md This Kotlin example illustrates a common issue with remote references where a `WeakReference` to an object might expire between calls. Accessing `roots[0]` in a subsequent line after `getContentRoots()` could lead to an error if the reference is no longer valid, highlighting the need for context management. ```kotlin val roots = driver.service().getContentRoots() val name = roots[0].getName() // may throw an error ``` -------------------------------- ### Specifying Custom IDE Download URL with Starter Context (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter/README.md This Kotlin code demonstrates how to create a new `Starter` context with a custom `IdeInfo` that includes a specific download URI. By using `IdeProductProvider.IU.copy(downloadURI = URI("www.example.com"))`, it allows the `intellij-ide-starter` to download the IntelliJ Ultimate IDE from a user-defined URL instead of the default source. ```Kotlin Starter.newContext( CurrentTestMethod.hyphenateWithClass(), TestCase( IdeProductProvider.IU.copy(downloadURI = URI("www.example.com")), GitHubProject.fromGithub( branchName = "master", repoRelativeUrl = "jitpack/gradle-simple.git" ) ) ) ``` -------------------------------- ### Establishing Driver Connection to IDE (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md This Kotlin snippet demonstrates how to create a `Driver` instance and connect to a running IDE via JMX. It initializes the driver with the specified JMX host and port, asserts the connection status, prints the IDE product version, and then gracefully exits the application. ```kotlin val driver = Driver.create(JmxHost(null, null, "localhost:7777")) assertTrue(driver.isConnected) println(driver.getProductVersion()) driver.exitApplication() ``` -------------------------------- ### Clicking UI Component on Welcome Screen (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md Demonstrates how to use `UiRobot` to interact with UI components. It obtains a `UiRobot` instance via `driver.ui`, then uses an XPath selector to find and click a 'New Project' button on the welcome screen. The `x` method defers the actual search until an action like `click` is performed. ```kotlin driver.ui.welcomeScreen { val createNewProjectButton = x("//div[(@accessiblename='New Project' and @class='JButton')") createNewProjectButton.click() } ``` -------------------------------- ### Using Page Object for UI Interaction (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md Demonstrates the simplified usage of the Page Object pattern defined previously. After setting up the `welcomeScreen` extension function and `WelcomeScreenUI` class, this snippet shows how to concisely interact with the welcome screen by calling `clickProjects()` directly within the `welcomeScreen` block. ```kotlin driver.ui.welcomeScreen { clickProjects() } ``` -------------------------------- ### Implementing Page Object Pattern for UI (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md Shows how to implement the Page Object pattern to encapsulate UI interactions. It defines an extension function `welcomeScreen` on `Finder` to locate the welcome frame and map it to `WelcomeScreenUI`. The `WelcomeScreenUI` class then provides methods like `clickProjects` to interact with specific elements within that screen, promoting reusability and maintainability. ```kotlin fun Finder.welcomeScreen(action: WelcomeScreenUI.() -> Unit) { x("//div[@class='FlatWelcomeFrame']", WelcomeScreenUI::class.java).action() } class WelcomeScreenUI(data: ComponentData) : UiComponent(data) { private val leftItems = tree("//div[@class='Tree']") fun clickProjects() = leftItems.clickPath("Projects") } ``` -------------------------------- ### Overriding CIServer Implementation with Kodein DI in Kotlin Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter/README.md This snippet demonstrates how to override the default `CIServer` implementation within the IntelliJ IDE Starter's Kodein dependency injection container. It extends the existing DI configuration and binds a custom `YourImplementationOfCI` as a singleton, allowing for tailored CI integration and reporting. Ensure the same Kodein version as the starter project's `build.gradle` is used. ```Kotlin di = DI { extend(di) bindSingleton(overrides = true) { YourImplementationOfCI() } } ``` -------------------------------- ### Configuring Plugin Dependencies and Extensions (XML) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter/documentation/createCustomPerformanceCommand.md This XML snippet defines the `plugin.xml` file for an IntelliJ plugin. It specifies the plugin's name, ID, description, and declares dependencies on `com.jetbrains.performancePlugin` and `com.intellij.modules.lang`. Crucially, it registers a `performancePlugin.commandProvider` extension, linking to the custom command provider implementation. ```XML Your plugin name com.intellij.performancePlugin.myPlugin My integration tests com.jetbrains.performancePlugin com.intellij.modules.lang ``` -------------------------------- ### Accessing Remote IDE Service with Driver (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md This Kotlin code demonstrates how to access a remote IDE service, `PsiManager`, within a read action using the `Driver`. It retrieves a `PsiFile` by calling the `findFile` method on the remote `PsiManager` instance, passing a `VirtualFile` and the current project context. ```kotlin driver.withReadAction { // here we access Project-level service val psiFile = service(project).findFile(file) } ``` -------------------------------- ### Implementing a Custom Command Provider (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter/documentation/createCustomPerformanceCommand.md This Kotlin snippet shows the implementation of `MyPluginCommandProvider`, which extends `CommandProvider`. Its `getCommands` method returns a map associating a command prefix (`MyCommand.PREFIX`) with a `CreateCommand` instance for `MyCommand`. This provider registers the custom command with the performance testing framework. ```Kotlin package com.intellij.myPlugin.performanceTesting class MyPluginCommandProvider : CommandProvider { override fun getCommands() = mapOf( Pair(MyCommand.PREFIX, CreateCommand(::MyCommand)), ) } ``` -------------------------------- ### Adding Dependencies for OpenTelemetry Metrics Collection (Gradle) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.metrics.collector.starter/README.md This snippet demonstrates how to configure your build.gradle or build.gradle.kts file to include the necessary dependencies for collecting OpenTelemetry metrics with IntelliJ IDE Starter. It specifies the required Maven repositories and testImplementation dependencies for the metrics collector, AP validation, and model. ```Gradle repositories { maven { url = "https://cache-redirector.jetbrains.com/maven-central" } maven { url = "https://cache-redirector.jetbrains.com/intellij-dependencies" } maven { url = "https://www.jetbrains.com/intellij-repository/releases" } maven { url = "https://www.jetbrains.com/intellij-repository/snapshots" } maven { url = "https://www.jetbrains.com/intellij-repository/nightly" } } testImplementation("com.jetbrains.intellij.tools:ide-metrics-collector-starter:LATEST-EAP-SNAPSHOT") testImplementation("com.jetbrains.fus.reporting:ap-validation:76") testImplementation("com.jetbrains.fus.reporting:model:76") ``` -------------------------------- ### Configuring Remote JVM Debugging Arguments Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter/README.md This command-line argument configures the Java Debug Wire Protocol (JDWP) agent for remote debugging. It sets up a socket transport, makes the JVM act as a server, does not suspend the JVM on startup, and listens on all available network interfaces on port 5005. This is used to allow an external debugger to connect to the running IDE instance. ```JVM Command Line -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 ``` -------------------------------- ### Configuring JMX for Driver Connection (Shell) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md These shell VM options are required to enable JMX for a running IntelliJ IDE instance, allowing the `Driver` API to connect and interact with it. They specify enabling JMX, setting the port to 7777, disabling authentication and SSL for simplicity in testing, and configuring the RMI server hostname to localhost. ```shell -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=7777 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost ``` -------------------------------- ### Defining Remote Interfaces with @Remote (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md These Kotlin interfaces, annotated with `@Remote`, define the contract for calling methods on remote IDE classes. They map to `com.intellij.psi.PsiManager`, `com.intellij.openapi.vfs.VirtualFile`, and `com.intellij.psi.PsiFile` respectively, allowing the `Driver` to invoke their methods across JVM processes. ```kotlin @Remote("com.intellij.psi.PsiManager") interface PsiManager { fun findFile(file: VirtualFile): PsiFile? } @Remote("com.intellij.openapi.vfs.VirtualFile") interface VirtualFile { fun getName(): String } @Remote("com.intellij.psi.PsiFile") interface PsiFile ``` -------------------------------- ### Overriding Default IDE Downloader in Kotlin DI Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter/README.md This Kotlin code snippet shows how to override the default `IdeDownloader` implementation within a dependency injection (DI) container. By binding `IdeByLinkDownloader` as a singleton with `overrides = true`, it ensures that custom IDE download URLs can be used instead of the default JetBrains public hosting. ```Kotlin init { di = DI { extend(di) bindSingleton(overrides = true) { IdeByLinkDownloader } } } ``` -------------------------------- ### Invoking UI Action with Driver (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md This Kotlin snippet shows a shorthand method for triggering a UI action within the IDE using the `Driver`. It directly invokes the action identified by its string ID, such as "SearchEverywhere", simulating user interaction for testing purposes. ```kotlin driver.invokeAction("SearchEverywhere") ``` -------------------------------- ### Utilizing Nested Context Boundaries in Driver (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md This Kotlin extension function `importGradleProject` showcases how to use nested context boundaries within helper methods. It ensures that remote references, such as `forProject` and the `ImportGradleProjectUtil` utility, remain valid throughout the project import operation, demonstrating robust reference management. ```kotlin fun Driver.importGradleProject(project: Project? = null) { withContext { val forProject = project ?: singleProject() this.utility(ImportGradleProjectUtil::class).importProject(forProject) } } ``` -------------------------------- ### Defining a Custom Performance Command (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter/documentation/createCustomPerformanceCommand.md This Kotlin snippet defines `MyCommand`, a custom performance testing command that extends `PlaybackCommandCoroutineAdapter`. It includes a `PREFIX` constant for the command name and overrides `doExecute` where the actual custom logic for the command should be implemented. This command will wait for its `doExecute` method to complete before finishing. ```Kotlin package com.intellij.myPlugin.performanceTesting.command import com.intellij.openapi.ui.playback.PlaybackContext import com.intellij.openapi.ui.playback.commands.PlaybackCommandCoroutineAdapter internal class MyCommand(text: String, line: Int) : PlaybackCommandCoroutineAdapter(text, line) { companion object { const val PREFIX = CMD_PREFIX + "myCommandName" } override suspend fun doExecute(context: PlaybackContext) { TODO("YOUR CODE HERE") } } ``` -------------------------------- ### Asserting UI Component Visibility (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md Illustrates how to assert the visibility of a UI component using the `shouldBe` method. An XPath selector is used to locate a header element, and then `shouldBe` is called to verify its visibility, providing a custom error message if the assertion fails. The component search is performed during the assertion. ```kotlin val header = x("//div[@text='AI Assistant']") header.shouldBe("AI assistant header not present", visible) ``` -------------------------------- ### Defining Remote Interface for Plugin Service (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md This Kotlin `@Remote` interface specifies a remote utility class from a specific plugin. The `plugin` attribute is crucial for identifying services or utilities declared within a plugin rather than the core platform, ensuring the `Driver` correctly locates and invokes the `importProject` method. ```kotlin @Remote("org.jetbrains.plugins.gradle.performanceTesting.ImportGradleProjectUtil", plugin = "org.jetbrains.plugins.gradle") interface ImportGradleProjectUtil { fun importProject(project: Project) } ``` -------------------------------- ### Managing Remote References with Driver.withContext (Kotlin) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.ide.starter.driver/README.md This Kotlin snippet demonstrates the use of `driver.withContext { }` to manage remote object references and prevent their expiration. Objects obtained within this block are guaranteed to remain alive until the context boundary is exited, ensuring subsequent operations on those references are successful. ```kotlin driver.withContext { val roots = service.getContentRoots() val name = roots[0].getName() // always OK! // results computed inside guaranteed to be alive till the end of the block } ``` -------------------------------- ### Configuring TeamCity Authentication for Local Debugging (Java) Source: https://github.com/jetbrains/intellij-ide-starter/blob/master/intellij.tools.plugin.checker.tests/README.md This snippet illustrates the TeamCity authentication properties necessary for local debugging of plugin validation tests. These properties enable a local test run to authenticate with the TeamCity server, allowing it to use build trigger information as input data, thereby replicating the TeamCity environment. ```Java Pair("teamcity.build.id", "BUILD_ID"), Pair("teamcity.auth.userId", "YOUR_USER_ID"), Pair("teamcity.auth.password", "YOUR_SECRET" ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.