From 507cdfc61a1c76c714b7ddd33017008dd42cb4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20B=C5=82ach?= Date: Fri, 19 Sep 2025 21:54:25 +0200 Subject: [PATCH] test: use intellij-ide-starter for e2e tests (#7690) * test: use intellij-ide-starter for e2e tests Solves CON-3723 Extra / details: * Update the CI and docs accordingly * Remove robot dependencies and remove the custom runIdeForUiTests task. The IDE startup is now automatic/per test (+ instance can be reused if we want). * A new DSL for E2E tests means we no longer need to add "wait" everywhere, because each closure opening ensures that the window is ready to use. As a result, the tests are slightly faster. The only exception is waiting for inline completion. * The testing task now depends on prepareSandbox, because an E2E test requires specifying where the plugin can be copied from (hence this dependency, since we need to make sure these files exist, see: CONTINUE_PLUGIN_DIR). * The test framework is specified in a different version than the platform version, because older versions don't have the required drivers (241 vs 243). * fix: add testIntegration * fix: fix warning in build script * fix: remove invalid run config --- .../actions/run-jetbrains-tests/action.yml | 18 +-- extensions/intellij/.gitignore | 4 +- extensions/intellij/.run/Run Test IDE.run.xml | 26 ---- .../intellij/.run/Run e2e tests.run.xml | 7 - extensions/intellij/CONTRIBUTING.md | 58 ++------ extensions/intellij/build.gradle.kts | 70 ++++----- .../e2e/Autocomplete.kt | 75 ---------- .../continueintellijextension/e2e/GUI.kt | 96 ------------ .../e2e/InlineEdit.kt | 96 ------------ .../e2e/Onboarding.kt | 85 ----------- .../fixtures/DialogFixture.kt | 36 ----- .../fixtures/IdeaFrame.kt | 92 ------------ .../fixtures/WelcomeFrame.kt | 27 ---- .../utils/BrowserUtils.kt | 76 ---------- .../utils/RemoteRobotExtension.kt | 138 ------------------ .../utils/StepsLogger.kt | 19 --- .../continueintellijextension/Autocomplete.kt | 48 ++++++ .../test-continue/config.json | 0 18 files changed, 99 insertions(+), 872 deletions(-) delete mode 100644 extensions/intellij/.run/Run Test IDE.run.xml delete mode 100644 extensions/intellij/.run/Run e2e tests.run.xml delete mode 100644 extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/Autocomplete.kt delete mode 100644 extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/GUI.kt delete mode 100644 extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/InlineEdit.kt delete mode 100644 extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/Onboarding.kt delete mode 100644 extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/fixtures/DialogFixture.kt delete mode 100644 extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/fixtures/IdeaFrame.kt delete mode 100644 extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/fixtures/WelcomeFrame.kt delete mode 100644 extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/utils/BrowserUtils.kt delete mode 100644 extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/utils/RemoteRobotExtension.kt delete mode 100644 extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/utils/StepsLogger.kt create mode 100644 extensions/intellij/src/testIntegration/kotlin/com/github/continuedev/continueintellijextension/Autocomplete.kt rename extensions/intellij/src/{test/kotlin/com/github/continuedev/continueintellijextension/e2e => testIntegration/kotlin/com/github/continuedev/continueintellijextension}/test-continue/config.json (100%) diff --git a/.github/actions/run-jetbrains-tests/action.yml b/.github/actions/run-jetbrains-tests/action.yml index 77f6ceff3..03a9c7855 100644 --- a/.github/actions/run-jetbrains-tests/action.yml +++ b/.github/actions/run-jetbrains-tests/action.yml @@ -107,7 +107,7 @@ runs: cd binary npm run build - - name: Start test IDE + - name: Run tests shell: bash run: | cd extensions/intellij @@ -115,21 +115,7 @@ runs: Xvfb -ac :99 -screen 0 1920x1080x24 & sleep 10 mkdir -p build/reports - ./gradlew runIdeForUiTests & - - - name: Wait for JB connection - uses: jtalk/url-health-check-action@v3 - with: - url: http://127.0.0.1:8082 - max-attempts: 15 - retry-delay: 30s - - - name: Run tests - shell: bash - run: | - cd extensions/intellij - export DISPLAY=:99.0 - ./gradlew test + ./gradlew test testIntegration - name: Move video if: ${{ failure() }} diff --git a/extensions/intellij/.gitignore b/extensions/intellij/.gitignore index 147aaa022..9619f5d1f 100644 --- a/extensions/intellij/.gitignore +++ b/extensions/intellij/.gitignore @@ -5,5 +5,5 @@ src/main/resources/config_schema.json src/main/resources/continue_rc_schema.json video .intellijPlatform -src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/test-continue/* -!src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/test-continue/config.json \ No newline at end of file +src/testIntegration/kotlin/com/github/continuedev/continueintellijextension/test-continue/* +!src/testIntegration/kotlin/com/github/continuedev/continueintellijextension/test-continue/config.json \ No newline at end of file diff --git a/extensions/intellij/.run/Run Test IDE.run.xml b/extensions/intellij/.run/Run Test IDE.run.xml deleted file mode 100644 index 94ab5809f..000000000 --- a/extensions/intellij/.run/Run Test IDE.run.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - true - true - false - false - - - - \ No newline at end of file diff --git a/extensions/intellij/.run/Run e2e tests.run.xml b/extensions/intellij/.run/Run e2e tests.run.xml deleted file mode 100644 index 2280aece0..000000000 --- a/extensions/intellij/.run/Run e2e tests.run.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/extensions/intellij/CONTRIBUTING.md b/extensions/intellij/CONTRIBUTING.md index fc1fdaa24..c9d05b502 100644 --- a/extensions/intellij/CONTRIBUTING.md +++ b/extensions/intellij/CONTRIBUTING.md @@ -179,55 +179,29 @@ This will generate a .zip file in `./build/distributions` with the version defin ## Testing -### e2e testing +Test commands: -#### Overview +- `./gradlew test` - to run **unit tests** +- `./gradlew testIntegration` - to run **e2e tests** -The e2e tests are written using [intellij-ui-test-robot](`https://github.com/JetBrains/intellij-ui-test-robot`). The -README for this project has a lot of helpful info on how to use the library. +### About e2e tests -Note that these tests fully take control of your mouse while executing. +The e2e tests are written using [intellij-ide-starter](https://github.com/JetBrains/intellij-ide-starter). +The first run of the e2e tests may take a while because the required IDE needs +to be downloaded. Note that these tests +fully take control of your mouse while executing. #### Setup If you are on macOS, you'll need to give IntelliJ permission to control your computer in order to run the e2e tests. -Open _System Settings_ and select `Privacy & Security` -> `Accessibility` and toggle the switch for IntelliJ. +Open `System Settings > Privacy & Security > Accessibility` and toggle the switch for IntelliJ. -#### Running the tests +#### Working with Intellij IDE Starter -Instantiate the test IDE as a background task: +The testing platform provides a rich DSL for most UI components in IntelliJ. However, if you want to interact with a +custom element, you can define your own XPath selector. -```sh -./gradlew clean runIdeForUiTests & -``` - -Once the IDE has loaded, you can run the tests. Note that you need to have the test IDE focused in order for the tests -to run. - -```sh -./gradlew test -``` - -Run a single test - -```sh -./gradlew test --tests "com.github.continuedev.continueintellijextension.e2e.TESTNAME" -``` - -#### Identifying selectors - -While the `runIdeForUiTests` task is running, you can visit the following URL -to view the UI hierarchy of the running IDE: - - - -#### Rebuilding the extension - -To rebuild the extension with the latest source code, run the following: - -```sh -./gradlew buildPlugin -``` - -This will update the contents of the extension that is loaded into the test IDE from -`build/idea-sandbox/plugins-uiTest/continue-intellij-extension` +To do this, run an e2e test and visit [localhost:63343/api/remote-driver/](http://localhost:63343/api/remote-driver/) to +view an HTML representation of the IDE's Swing component tree. +See [Integration Tests](https://plugins.jetbrains.com/docs/intellij/integration-tests-ui.html#searching-components) for +more details about this workflow. diff --git a/extensions/intellij/build.gradle.kts b/extensions/intellij/build.gradle.kts index 7b7ed7c29..86231350f 100644 --- a/extensions/intellij/build.gradle.kts +++ b/extensions/intellij/build.gradle.kts @@ -1,17 +1,17 @@ import org.jetbrains.changelog.markdownToHTML import org.jetbrains.intellij.platform.gradle.TestFrameworkType import org.jetbrains.intellij.platform.gradle.tasks.PrepareSandboxTask +import org.gradle.kotlin.dsl.intellijPlatform fun environment(key: String) = providers.environmentVariable(key) -val remoteRobotVersion = "0.11.23" val platformVersion: String by project val pluginGroup: String by project val pluginVersion: String by project val isEap get() = environment("RELEASE_CHANNEL").orNull == "eap" plugins { - kotlin("jvm") version "1.9.22" + kotlin("jvm") version "2.1.0" id("org.jetbrains.intellij.platform") version "2.7.2" id("org.jetbrains.changelog") version "2.1.2" id("org.jetbrains.qodana") version "0.1.13" @@ -28,17 +28,28 @@ repositories { } } +sourceSets { + val testIntegration = create("testIntegration") + testIntegration.apply { + compileClasspath += sourceSets.main.get().output + runtimeClasspath += sourceSets.main.get().output + } +} + +val testIntegrationImplementation: Configuration by configurations.getting { + extendsFrom(configurations.testImplementation.get()) +} + dependencies { intellijPlatform { - create("IC", platformVersion) + intellijIdeaCommunity(platformVersion) plugins(listOf("org.jetbrains.plugins.terminal:241.14494.150")) testFramework(TestFrameworkType.Platform) + testFramework(TestFrameworkType.Starter, "243.21565.193", configurationName = "testIntegrationImplementation") } implementation("com.posthog.java:posthog:1.2.0") testImplementation("junit:junit:4.13.2") - testImplementation("com.intellij.remoterobot:remote-robot:$remoteRobotVersion") - testImplementation("com.intellij.remoterobot:remote-fixtures:$remoteRobotVersion") testImplementation("io.mockk:mockk:1.14.2") { // this transitive dependency (1.6.4) conflicts with built-in version (1.7.3) // otherwise e2e tests (runIdeForUiTests) will have linkage errors @@ -47,6 +58,10 @@ dependencies { testImplementation("com.squareup.okhttp3:logging-interceptor:4.12.0") testImplementation("com.automation-remarks:video-recorder-junit5:2.0") testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.10.0") // required to run both JUnit 5 and JUnit 3 + + testIntegrationImplementation("org.junit.jupiter:junit-jupiter:5.7.1") + testIntegrationImplementation("org.kodein.di:kodein-di-jvm:7.20.2") + testIntegrationImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.10.1") } kotlin { @@ -88,40 +103,6 @@ qodana { showReport = environment("QODANA_SHOW_REPORT").map { it.toBoolean() }.getOrElse(false) } -intellijPlatformTesting { - runIde { - // This task might not work locally because the binary tends to ignore CONTINUE_GLOBAL_DIR when a - // local Continue config is present. If you want to run the e2e tests locally, the most effective - // way is to temporarily disconnect from the network and run the tests again. - // todo: fix it properly - register("runIdeForUiTests") { - task { - environment( - "CONTINUE_GLOBAL_DIR", - "${rootProject.projectDir}/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/test-continue" - ) - jvmArgumentProviders += CommandLineArgumentProvider { - listOf( - "-Drobot-server.port=8082", - "-Dide.mac.message.dialogs.as.sheets=false", - "-Djb.privacy.policy.text=", - "-Djb.consents.confirmation.enabled=false", - "-Dide.mac.file.chooser.native=false", - "-DjbScreenMenuBar.enabled=false", - "-Dapple.laf.useScreenMenuBar=false", - "-Didea.trust.all.projects=true", - "-Dide.show.tips.on.startup.default.value=false", - "-Dide.browser.jcef.sandbox.enable=false" - ) - } - } - plugins { - robotServerPlugin() - } - } - } -} - tasks { withType { from("../../binary/bin") { @@ -146,6 +127,17 @@ tasks { test { useJUnitPlatform() + environment("CONTINUE_GLOBAL_DIR", "${rootProject.projectDir}/src/test/kotlin/com/github/continuedev/continueintellijextension/test-continue") jvmArgumentProviders += CommandLineArgumentProvider { listOf("-Dide.browser.jcef.sandbox.enable=false") } } } + +val testIntegration = task("testIntegration") { + val integrationTestSourceSet = sourceSets.getByName("testIntegration") + testClassesDirs = integrationTestSourceSet.output.classesDirs + classpath = integrationTestSourceSet.runtimeClasspath + systemProperty("CONTINUE_PLUGIN_DIR", tasks.prepareSandbox.get().pluginDirectory.get().asFile) + environment("CONTINUE_GLOBAL_DIR", "${rootProject.projectDir}/src/testIntegration/kotlin/com/github/continuedev/continueintellijextension/test-continue") + useJUnitPlatform() + dependsOn(tasks.prepareSandbox) +} diff --git a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/Autocomplete.kt b/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/Autocomplete.kt deleted file mode 100644 index 44171e581..000000000 --- a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/Autocomplete.kt +++ /dev/null @@ -1,75 +0,0 @@ -package com.github.continuedev.continueintellijextension.e2e - -import com.automation.remarks.junit5.Video -import com.github.continuedev.continueintellijextension.fixtures.dialog -import com.github.continuedev.continueintellijextension.fixtures.idea -import com.github.continuedev.continueintellijextension.fixtures.welcomeFrame -import com.github.continuedev.continueintellijextension.utils.RemoteRobotExtension -import com.github.continuedev.continueintellijextension.utils.StepsLogger -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.fixtures.ComponentFixture -import com.intellij.remoterobot.search.locators.byXpath -import com.intellij.remoterobot.steps.CommonSteps -import com.intellij.remoterobot.utils.keyboard -import com.intellij.remoterobot.utils.waitFor -import com.intellij.remoterobot.utils.waitForIgnoringError -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import java.time.Duration.ofMinutes -import java.time.Duration.ofSeconds - -@ExtendWith(RemoteRobotExtension::class) -class Autocomplete { - init { - StepsLogger.init() - } - - @BeforeEach - fun waitForIde(remoteRobot: RemoteRobot) { - waitForIgnoringError(ofMinutes(3)) { remoteRobot.callJs("true") } - } - - @AfterEach - fun closeProject(remoteRobot: RemoteRobot) { - CommonSteps(remoteRobot).closeProject() - } - - @Test - @Video - fun displayCompletion(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { - welcomeFrame { - createNewProjectLink.click() - dialog("New Project") { - findText("Java").click() - checkBox("Add sample code").select() - button("Create").click() - } - } - - // Wait for the default "Main.java" tab to load - // Our "continue_tutorial.java.ft" tab loads first, but then "Main.java" takes focus. - waitFor(ofSeconds(20)) { - findAll( - byXpath("//div[@visible_text='Main.java']") - ).isNotEmpty() - } - - idea { - with(textEditor()) { - val userMsg = "TEST_USER_MESSAGE_0" - editor.insertTextAtLine(0, 0, userMsg) - editor.clickOnOffset(userMsg.length) - - keyboard { - enterText(" ") - } - - waitFor(ofSeconds(20)) { - editor.hasText("TEST_LLM_RESPONSE_0") - } - } - } - } -} \ No newline at end of file diff --git a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/GUI.kt b/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/GUI.kt deleted file mode 100644 index 44b205134..000000000 --- a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/GUI.kt +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Currently we can't test any actions in the GUI that involve clicks. - * See this open issue for details: https://github.com/JetBrains/intellij-ui-test-robot/issues/491 - */ -package com.github.continuedev.continueintellijextension.e2e - -import com.automation.remarks.junit5.Video -import com.github.continuedev.continueintellijextension.fixtures.* -import com.github.continuedev.continueintellijextension.utils.RemoteRobotExtension -import com.github.continuedev.continueintellijextension.utils.StepsLogger -import com.github.continuedev.continueintellijextension.utils.getMetaKey -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.fixtures.ComponentFixture -import com.intellij.remoterobot.search.locators.byXpath -import com.intellij.remoterobot.steps.CommonSteps -import com.intellij.remoterobot.stepsProcessing.step -import com.intellij.remoterobot.utils.keyboard -import com.intellij.remoterobot.utils.waitFor -import com.intellij.remoterobot.utils.waitForIgnoringError -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import java.awt.event.KeyEvent.* -import java.time.Duration.ofMinutes -import java.time.Duration.ofSeconds - -@ExtendWith(RemoteRobotExtension::class) -class GUI { - init { - StepsLogger.init() - } - - @BeforeEach - fun waitForIde(remoteRobot: RemoteRobot) { - waitForIgnoringError(ofMinutes(3)) { remoteRobot.callJs("true") } - } - - @AfterEach - fun closeProject(remoteRobot: RemoteRobot) = CommonSteps(remoteRobot).closeProject() - - // @Test - @Video - fun highlightCode(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { - welcomeFrame { - createNewProjectLink.click() - dialog("New Project") { - findText("Java").click() - checkBox("Add sample code").select() - button("Create").click() - } - } - - // Wait for the default "Main.java" tab to load - // Our "continue_tutorial.java.ft" tab loads first, but then "Main.java" takes focus. - // If we don't wait for this, clicking on the GUI may fail because a popup displays - // while the `continue_tutorial.java` is loading. - waitFor(ofSeconds(20)) { - findAll( - byXpath("//div[@accessiblename='Main.java' and @class='SingleHeightLabel']") - ).isNotEmpty() - } - - idea { - step("Manually open the webview") { - // Manually open the webview - find(byXpath("//div[@text='Continue']"), ofSeconds((10))).click() - - waitFor(ofSeconds(10)) { - browser().isShowing - } - - // Arbitrary timeout due to a bug where the webview will refresh - // and clear the editor state on first load - Thread.sleep(5000) - } - - step("Verify we can highlight code and add to webview") { - val textToInsert = "Hello world!" - - with(textEditor()) { - editor.insertTextAtLine(0, 0, textToInsert) - editor.selectText(textToInsert) - - keyboard { - hotKey(getMetaKey(), VK_J) - } - } - - waitFor(ofSeconds(10)) { - browser().findElementByContainsText(textToInsert).html.isNotEmpty() - } - } - } - } -} diff --git a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/InlineEdit.kt b/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/InlineEdit.kt deleted file mode 100644 index e668bd4b1..000000000 --- a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/InlineEdit.kt +++ /dev/null @@ -1,96 +0,0 @@ -package com.github.continuedev.continueintellijextension.e2e - -import com.automation.remarks.junit5.Video -import com.github.continuedev.continueintellijextension.fixtures.dialog -import com.github.continuedev.continueintellijextension.fixtures.idea -import com.github.continuedev.continueintellijextension.fixtures.welcomeFrame -import com.github.continuedev.continueintellijextension.utils.RemoteRobotExtension -import com.github.continuedev.continueintellijextension.utils.StepsLogger -import com.github.continuedev.continueintellijextension.utils.* -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.fixtures.ComponentFixture -import com.intellij.remoterobot.search.locators.byXpath -import com.intellij.remoterobot.steps.CommonSteps -import com.intellij.remoterobot.utils.keyboard -import com.intellij.remoterobot.utils.waitFor -import com.intellij.remoterobot.utils.waitForIgnoringError -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import java.awt.event.KeyEvent.VK_I -import java.time.Duration.ofMinutes -import java.time.Duration.ofSeconds - -@ExtendWith(RemoteRobotExtension::class) -class InlineEdit { - init { - StepsLogger.init() - } - - @BeforeEach - fun waitForIde(remoteRobot: RemoteRobot) { - waitForIgnoringError(ofMinutes(3)) { remoteRobot.callJs("true") } - } - - @AfterEach - fun closeProject(remoteRobot: RemoteRobot) = CommonSteps(remoteRobot).closeProject() - - @Test - @Disabled("Failing in CI, seems like the timeout just needs to be increased") - @Video - fun submitInlineEdit(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { - welcomeFrame { - createNewProjectLink.click() - dialog("New Project") { - findText("Java").click() - checkBox("Add sample code").select() - button("Create").click() - } - } - - // Wait for the default "Main.java" tab to load - // Our "continue_tutorial.java.ft" tab loads first, but then "Main.java" takes focus. - waitFor(ofSeconds(20)) { - findAll( - byXpath("//div[@accessiblename='Main.java' and @class='SingleHeightLabel']") - ).isNotEmpty() - } - - idea { - with(textEditor()) { - val userMsg = "TEST_USER_MESSAGE_0" - editor.insertTextAtLine(0, 0, userMsg) - editor.selectText(userMsg) - - keyboard { - hotKey(getMetaKey(), VK_I) - } - - val textArea = find(byXpath("//div[@class='CustomTextArea']")) - textArea.hasText("Enter instructions...") - - val modelSelect = find(byXpath("//div[@class='JComboBox']")) - modelSelect.hasText("TEST LLM") - - keyboard { - enterText("Hello world!") - } - - val enterBtn = find(byXpath("//div[@class='CustomButton']")) - enterBtn.click() - - val rejectText = "${getAltKeyLabel()}${getShiftKeyLabel()}N" - val acceptText = "${getAltKeyLabel()}${getShiftKeyLabel()}Y" - val acceptAllText = "Accept All (${getMetaKeyLabel()}${getShiftKeyLabel()}⏎)" - val rejectAllText = "Reject All (${getMetaKeyLabel()}${getShiftKeyLabel()}⌫)" - - find(byXpath("//div[@text='$rejectText']")).isShowing - find(byXpath("//div[@text='$acceptText']")).isShowing - find(byXpath("//div[@text='$acceptAllText']")).isShowing - find(byXpath("//div[@text='$rejectAllText']")).isShowing - } - } - } -} \ No newline at end of file diff --git a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/Onboarding.kt b/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/Onboarding.kt deleted file mode 100644 index 30306b7ba..000000000 --- a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/Onboarding.kt +++ /dev/null @@ -1,85 +0,0 @@ -package com.github.continuedev.continueintellijextension.e2e - -import com.automation.remarks.junit5.Video -import com.github.continuedev.continueintellijextension.fixtures.dialog -import com.github.continuedev.continueintellijextension.fixtures.idea -import com.github.continuedev.continueintellijextension.fixtures.welcomeFrame -import com.github.continuedev.continueintellijextension.utils.RemoteRobotExtension -import com.github.continuedev.continueintellijextension.utils.StepsLogger -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.fixtures.ComponentFixture -import com.intellij.remoterobot.search.locators.byXpath -import com.intellij.remoterobot.steps.CommonSteps -import com.intellij.remoterobot.stepsProcessing.step -import com.intellij.remoterobot.utils.waitFor -import com.intellij.remoterobot.utils.waitForIgnoringError -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import java.time.Duration.ofMinutes -import java.time.Duration.ofSeconds - -@ExtendWith(RemoteRobotExtension::class) -class Onboarding { - init { - StepsLogger.init() - } - - @BeforeEach - fun waitForIde(remoteRobot: RemoteRobot) { - waitForIgnoringError(ofMinutes(3)) { remoteRobot.callJs("true") } - } - - @AfterEach - fun closeProject(remoteRobot: RemoteRobot) = CommonSteps(remoteRobot).closeProject() - - - // @Test - @Video - fun onboarding(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { - welcomeFrame { - createNewProjectLink.click() - dialog("New Project") { - findText("Java").click() - checkBox("Add sample code").select() - button("Create").click() - } - } - - idea { - // Wait for the default "Main.java" tab to load - // Our "continue_tutorial.java.ft" tab loads first, but then "Main.java" takes focus. - // So we need to wait for that to occur, and then focus on "continue_tutorial.java.ft" - waitFor(ofSeconds(20)) { - findAll( - byXpath("//div[@accessiblename='Main.java' and @class='SingleHeightLabel']") - ).isNotEmpty() - } - - // TODO: Need a good way to ensure this is the first test ran in the entire suite -// step("Verify Continue tutorial file is loaded") { -// find(byXpath("//div[@visible_text='continue_tutorial.java']")) -// } - - step("Manually open the webview") { - // Manually open the webview - find(byXpath("//div[@text='Continue']"), ofSeconds((10))).click() - - waitFor(ofSeconds(10)) { - browser().isShowing - } - } - - step("Verify the onboarding card is present") { - waitFor(ofSeconds(30)) { - try { - browser().findElement("//*[@data-testid='onboarding-card']").html.isNotEmpty() - } catch (e: Exception) { - false - } - } - } - } - } -} diff --git a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/fixtures/DialogFixture.kt b/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/fixtures/DialogFixture.kt deleted file mode 100644 index d9643a96b..000000000 --- a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/fixtures/DialogFixture.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.continuedev.continueintellijextension.fixtures - -/* - * Source: https://github.com/JetBrains/intellij-ui-test-robot/blob/139a05eb99e9a49f13605626b81ad9864be23c96/ui-test-example/src/test/kotlin/org/intellij/examples/simple/plugin/pages/DialogFixture.kt - */ -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.data.RemoteComponent -import com.intellij.remoterobot.fixtures.CommonContainerFixture -import com.intellij.remoterobot.fixtures.ContainerFixture -import com.intellij.remoterobot.fixtures.FixtureName -import com.intellij.remoterobot.search.locators.byXpath -import com.intellij.remoterobot.stepsProcessing.step -import java.time.Duration - -fun ContainerFixture.dialog( - title: String, - timeout: Duration = Duration.ofSeconds(30), - function: DialogFixture.() -> Unit = {} -): DialogFixture = step("Search for dialog with title $title") { - find(DialogFixture.byTitle(title), timeout).apply(function) -} - -@FixtureName("Dialog") -class DialogFixture( - remoteRobot: RemoteRobot, - remoteComponent: RemoteComponent -) : CommonContainerFixture(remoteRobot, remoteComponent) { - - companion object { - @JvmStatic - fun byTitle(title: String) = byXpath("title $title", "//div[@title='$title' and @class='MyDialog']") - } - - val title: String - get() = callJs("component.getTitle();") -} \ No newline at end of file diff --git a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/fixtures/IdeaFrame.kt b/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/fixtures/IdeaFrame.kt deleted file mode 100644 index 141677c15..000000000 --- a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/fixtures/IdeaFrame.kt +++ /dev/null @@ -1,92 +0,0 @@ -package com.github.continuedev.continueintellijextension.fixtures - -/* - * Source: https://github.com/JetBrains/intellij-ui-test-robot/blob/139a05eb99e9a49f13605626b81ad9864be23c96/ui-test-example/src/test/kotlin/org/intellij/examples/simple/plugin/pages/IdeaFrame.kt - */ -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.data.RemoteComponent -import com.intellij.remoterobot.fixtures.* -import com.intellij.remoterobot.search.locators.byXpath -import com.intellij.remoterobot.stepsProcessing.step -import com.intellij.remoterobot.utils.waitFor -import java.time.Duration - -fun RemoteRobot.idea(function: IdeaFrame.() -> Unit) { - find(timeout = Duration.ofSeconds(10)).apply(function) -} - -@FixtureName("Idea frame") -@DefaultXpath("IdeFrameImpl type", "//div[@class='IdeFrameImpl']") -class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : - CommonContainerFixture(remoteRobot, remoteComponent) { - - val projectViewTree - get() = find(byXpath("ProjectViewTree", "//div[@class='ProjectViewTree']")) - - val projectName - get() = step("Get project name") { return@step callJs("component.getProject().getName()") } - - val menuBar: JMenuBarFixture - get() = step("Menu...") { - return@step remoteRobot.find(JMenuBarFixture::class.java, JMenuBarFixture.byType()) - } - - @JvmOverloads - fun dumbAware(timeout: Duration = Duration.ofMinutes(5), function: () -> Unit) { - step("Wait for smart mode") { - waitFor(duration = timeout, interval = Duration.ofSeconds(5)) { - runCatching { isDumbMode().not() }.getOrDefault(false) - } - function() - step("..wait for smart mode again") { - waitFor(duration = timeout, interval = Duration.ofSeconds(5)) { - isDumbMode().not() - } - } - } - } - - fun isDumbMode(): Boolean { - return callJs( - """ - const frameHelper = com.intellij.openapi.wm.impl.ProjectFrameHelper.getFrameHelper(component) - if (frameHelper) { - const project = frameHelper.getProject() - project ? com.intellij.openapi.project.DumbService.isDumb(project) : true - } else { - true - } - """, true - ) - } - - fun openFile(path: String) { - runJs( - """ - importPackage(com.intellij.openapi.fileEditor) - importPackage(com.intellij.openapi.vfs) - importPackage(com.intellij.openapi.wm.impl) - importClass(com.intellij.openapi.application.ApplicationManager) - - const path = '$path' - const frameHelper = ProjectFrameHelper.getFrameHelper(component) - if (frameHelper) { - const project = frameHelper.getProject() - const projectPath = project.getBasePath() - const file = LocalFileSystem.getInstance().findFileByPath(projectPath + '/' + path) - const openFileFunction = new Runnable({ - run: function() { - FileEditorManager.getInstance(project).openTextEditor( - new OpenFileDescriptor( - project, - file - ), true - ) - } - }) - ApplicationManager.getApplication().invokeLater(openFileFunction) - } - """, true - ) - } -} \ No newline at end of file diff --git a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/fixtures/WelcomeFrame.kt b/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/fixtures/WelcomeFrame.kt deleted file mode 100644 index 70029fdaf..000000000 --- a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/fixtures/WelcomeFrame.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.github.continuedev.continueintellijextension.fixtures - -/* - * Source: https://github.com/JetBrains/intellij-ui-test-robot/blob/139a05eb99e9a49f13605626b81ad9864be23c96/ui-test-example/src/test/kotlin/org/intellij/examples/simple/plugin/pages/WelcomeFrame.kt - */ -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.data.RemoteComponent -import com.intellij.remoterobot.fixtures.* -import com.intellij.remoterobot.search.locators.byXpath -import java.time.Duration - -fun RemoteRobot.welcomeFrame(function: WelcomeFrame.() -> Unit) { - find(WelcomeFrame::class.java, Duration.ofSeconds(20)).apply(function) -} - -@FixtureName("Welcome Frame") -@DefaultXpath("type", "//div[@class='FlatWelcomeFrame']") -class WelcomeFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : - CommonContainerFixture(remoteRobot, remoteComponent) { - val createNewProjectLink - get() = actionLink( - byXpath( - "New Project", - "//div[(@class='MainButton' and @text='New Project') or (@accessiblename='New Project' and @class='JButton')]" - ) - ) -} \ No newline at end of file diff --git a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/utils/BrowserUtils.kt b/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/utils/BrowserUtils.kt deleted file mode 100644 index 51868f031..000000000 --- a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/utils/BrowserUtils.kt +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Notes: - * - `sendIntellijMessage` isn't working, but keeping this around as an example of how we might be able to implement - * - Below is an AI generated summary of what the problem might be based on troubleshooting attempts - * - For details, see https://intellij-support.jetbrains.com/hc/en-us/community/posts/26714246086162--intellij-ui-test-robot-Error-when-attempting-to-click-on-DomElement-491 - * - * - * The issue is with how the JCefBrowserFixture.executeJsInBrowser method handles JavaScript code execution. - * When trying to call window.postIntellijMessage, we're encountering these challenges: - * - * 1. **Double Injection Problem**: The postIntellijMessage function already uses JBCefJSQuery.inject internally. - * When we try to call it through executeJsInBrowser, we're essentially trying to pass it through another injection - * mechanism, creating nested injections that break. - * - * 2. **String Escaping Issues**: The way quotes are being escaped between the layers of execution is causing syntax - * errors in the final JavaScript that gets executed. - * - * 3. **Context Isolation**: The executeJsInBrowser method likely runs in a different execution context than where the - * function was defined, causing scope/reference issues. - * - * The key insight is that we cannot directly call a function that itself uses the JBCefJSQuery bridge through the test - * framework's executeJsInBrowser method. These bridge functions are designed to be called directly in the browser - * context, not through another layer of script injection. - */ -package com.github.continuedev.continueintellijextension.utils - -import com.intellij.remoterobot.fixtures.JCefBrowserFixture - -/** - * Utility functions for interacting with browser components in tests - */ -object BrowserUtils { - - /** - * Sends a message to the webview using JCefBrowserFixture's executeJsInBrowser - * - * @param browser The JCefBrowserFixture to execute JavaScript in - * @param messageType The type of message to send - * @param messageData The data object to send as message payload - * @param messageId A unique ID for the message - */ - fun sendIntellijMessage( - browser: JCefBrowserFixture, - messageType: String, - messageData: Any, - messageId: String = "test-message-id" - ) { - // Convert the messageData to a JSON string - val dataJson = when (messageData) { - is String -> "\"$messageData\"" - else -> messageData.toString() - } - - val jsCode = """ - (function() { - window.postIntellijMessage( - "$messageType", - $dataJson, - "$messageId" - ); - return true; - })(); - """.trimIndent() - - browser.executeJsInBrowser(jsCode) - } -} - -// Extension function for JCefBrowserFixture for easier usage -fun JCefBrowserFixture.sendIntellijMessage( - messageType: String, - messageData: Any, - messageId: String = "test-message-id" -) { - BrowserUtils.sendIntellijMessage(this, messageType, messageData, messageId) -} \ No newline at end of file diff --git a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/utils/RemoteRobotExtension.kt b/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/utils/RemoteRobotExtension.kt deleted file mode 100644 index 0ae25a389..000000000 --- a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/utils/RemoteRobotExtension.kt +++ /dev/null @@ -1,138 +0,0 @@ -package com.github.continuedev.continueintellijextension.utils - -/** - * Source: https://github.com/JetBrains/intellij-ui-test-robot/blob/139a05eb99e9a49f13605626b81ad9864be23c96/ui-test-example/src/test/kotlin/org/intellij/examples/simple/plugin/utils/RemoteRobotExtension.kt - */ -import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.fixtures.ContainerFixture -import com.intellij.remoterobot.search.locators.byXpath -import okhttp3.OkHttpClient -import okhttp3.Request -import okhttp3.logging.HttpLoggingInterceptor -import org.junit.jupiter.api.extension.AfterTestExecutionCallback -import org.junit.jupiter.api.extension.ExtensionContext -import org.junit.jupiter.api.extension.ParameterContext -import org.junit.jupiter.api.extension.ParameterResolver -import java.awt.image.BufferedImage -import java.io.ByteArrayOutputStream -import java.io.File -import java.lang.IllegalStateException -import java.lang.reflect.Method -import javax.imageio.ImageIO - -class RemoteRobotExtension : AfterTestExecutionCallback, ParameterResolver { - private val url: String = System.getProperty("remote-robot-url") ?: "http://127.0.0.1:8082" - private val remoteRobot: RemoteRobot = if (System.getProperty("debug-retrofit")?.equals("enable") == true) { - val interceptor: HttpLoggingInterceptor = HttpLoggingInterceptor().apply { - this.level = HttpLoggingInterceptor.Level.BODY - } - val client = OkHttpClient.Builder().apply { - this.addInterceptor(interceptor) - }.build() - RemoteRobot(url, client) - } else { - RemoteRobot(url) - } - private val client = OkHttpClient() - - override fun supportsParameter(parameterContext: ParameterContext?, extensionContext: ExtensionContext?): Boolean { - return parameterContext?.parameter?.type?.equals(RemoteRobot::class.java) ?: false - } - - override fun resolveParameter(parameterContext: ParameterContext?, extensionContext: ExtensionContext?): Any { - return remoteRobot - } - - override fun afterTestExecution(context: ExtensionContext?) { - val testMethod: Method = context?.requiredTestMethod ?: throw IllegalStateException("test method is null") - val testMethodName = testMethod.name - val testFailed: Boolean = context.executionException?.isPresent ?: false - if (testFailed) { -// saveScreenshot(testMethodName) - saveIdeaFrames(testMethodName) - saveHierarchy(testMethodName) - } - } - - private fun saveScreenshot(testName: String) { - fetchScreenShot().save(testName) - } - - private fun saveHierarchy(testName: String) { - val hierarchySnapshot = - saveFile(url, "build/reports", "hierarchy-$testName.html") - if (File("build/reports/styles.css").exists().not()) { - saveFile("$url/styles.css", "build/reports", "styles.css") - } - println("Hierarchy snapshot: ${hierarchySnapshot.absolutePath}") - } - - private fun saveFile(url: String, folder: String, name: String): File { - val response = client.newCall(Request.Builder().url(url).build()).execute() - return File(folder).apply { - mkdirs() - }.resolve(name).apply { - writeText(response.body?.string() ?: "") - } - } - - private fun BufferedImage.save(name: String) { - val bytes = ByteArrayOutputStream().use { b -> - ImageIO.write(this, "png", b) - b.toByteArray() - } - File("build/reports").apply { mkdirs() }.resolve("$name.png").writeBytes(bytes) - } - - private fun saveIdeaFrames(testName: String) { - remoteRobot.findAll(byXpath("//div[@class='IdeFrameImpl']")).forEachIndexed { n, frame -> - val pic = try { - frame.callJs( - """ - importPackage(java.io) - importPackage(javax.imageio) - importPackage(java.awt.image) - const screenShot = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB); - component.paint(screenShot.getGraphics()) - let pictureBytes; - const baos = new ByteArrayOutputStream(); - try { - ImageIO.write(screenShot, "png", baos); - pictureBytes = baos.toByteArray(); - } finally { - baos.close(); - } - pictureBytes; - """, true - ) - } catch (e: Throwable) { - e.printStackTrace() - throw e - } - pic.inputStream().use { - ImageIO.read(it) - }.save(testName + "_" + n) - } - } - - private fun fetchScreenShot(): BufferedImage { - return remoteRobot.callJs( - """ - importPackage(java.io) - importPackage(javax.imageio) - const screenShot = new java.awt.Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); - let pictureBytes; - const baos = new ByteArrayOutputStream(); - try { - ImageIO.write(screenShot, "png", baos); - pictureBytes = baos.toByteArray(); - } finally { - baos.close(); - } - pictureBytes; - """ - ).inputStream().use { - ImageIO.read(it) - } - } -} diff --git a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/utils/StepsLogger.kt b/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/utils/StepsLogger.kt deleted file mode 100644 index bf4c86214..000000000 --- a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/utils/StepsLogger.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.continuedev.continueintellijextension.utils - -/** - * Source: https://github.com/JetBrains/intellij-ui-test-robot/blob/139a05eb99e9a49f13605626b81ad9864be23c96/ui-test-example/src/test/kotlin/org/intellij/examples/simple/plugin/utils/StepsLogger.kt - */ -import com.intellij.remoterobot.stepsProcessing.StepLogger -import com.intellij.remoterobot.stepsProcessing.StepWorker - -object StepsLogger { - private var initialized = false - - @JvmStatic - fun init() { - if (initialized.not()) { - StepWorker.registerProcessor(StepLogger()) - initialized = true - } - } -} \ No newline at end of file diff --git a/extensions/intellij/src/testIntegration/kotlin/com/github/continuedev/continueintellijextension/Autocomplete.kt b/extensions/intellij/src/testIntegration/kotlin/com/github/continuedev/continueintellijextension/Autocomplete.kt new file mode 100644 index 000000000..beca66839 --- /dev/null +++ b/extensions/intellij/src/testIntegration/kotlin/com/github/continuedev/continueintellijextension/Autocomplete.kt @@ -0,0 +1,48 @@ +package com.github.continuedev.continueintellijextension + +import com.automation.remarks.junit5.Video +import com.intellij.driver.sdk.ui.components.* +import com.intellij.driver.sdk.wait +import com.intellij.ide.starter.driver.engine.runIdeWithDriver +import com.intellij.ide.starter.ide.IdeProductProvider +import com.intellij.ide.starter.models.TestCase +import com.intellij.ide.starter.plugins.PluginConfigurator +import com.intellij.ide.starter.project.NoProject +import com.intellij.ide.starter.runner.Starter +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.Assertions.assertTrue +import java.io.File +import kotlin.time.Duration.Companion.seconds + +class Autocomplete { + + @Video + @Test + fun testAutocomplete() { + val starter = Starter.newContext("testExample", TestCase(IdeProductProvider.IC, NoProject).withVersion("2024.3")) + PluginConfigurator(starter).installPluginFromFolder(File(System.getProperty("CONTINUE_PLUGIN_DIR"))) + starter.runIdeWithDriver().useDriverAndCloseIde { + welcomeScreen { + createNewProjectButton.click() + button("Create").click() + } + ideFrame { + editorTabs { + clickTab("Main.java") + } + codeEditor { + keyboard { + enterText("TEST_USER_MESSAGE_0") + space() + } + wait(2.seconds) + keyboard { + tab() + } + assertTrue(text.contains("TEST_LLM_RESPONSE_0")) + } + } + } + } + +} \ No newline at end of file diff --git a/extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/test-continue/config.json b/extensions/intellij/src/testIntegration/kotlin/com/github/continuedev/continueintellijextension/test-continue/config.json similarity index 100% rename from extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/e2e/test-continue/config.json rename to extensions/intellij/src/testIntegration/kotlin/com/github/continuedev/continueintellijextension/test-continue/config.json