Skip to content

Commit

Permalink
chore: fix ui tests on latest intellij
Browse files Browse the repository at this point in the history
  • Loading branch information
kmruiz committed May 10, 2024
1 parent 6fbb948 commit 9d1f71d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 35 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
# IntelliJ platform dependencies
intellij-min="2023.1.5"
intellij-min="2024.1.1"
intellij-type="IU"
intellij-remoteRobot="0.11.22"
intellij-plugin="1.17.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/jetbrains-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ tasks {
}

patchPluginXml {
sinceBuild.set("231")
sinceBuild.set("241")
untilBuild.set("242.*")
version.set(rootProject.version.toString())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,18 @@ package com.mongodb.jbplugin.fixtures

import com.intellij.remoterobot.RemoteRobot
import com.intellij.remoterobot.fixtures.Fixture
import com.intellij.remoterobot.search.locators.Locator
import com.intellij.remoterobot.utils.waitFor
import java.time.Duration

/**
* Return a fixture at locator.
*
* @param locator
* @param timeout
* @return
*/
inline fun <reified T : Fixture> RemoteRobot.findVisible(locator: Locator, timeout: Duration = Duration.ofSeconds(15)) =
run {
waitFor(timeout, Duration.ofMillis(250)) {
runCatching {
find(T::class.java, locator, Duration.ofMillis(100)).callJs<Boolean>("true")
}.getOrDefault(false)
}

find(T::class.java, locator)
}

/**
* Returns a fixture by the default xpath of the fixture.
*
* @param timeout
* @return
*/
inline fun <reified T : Fixture> RemoteRobot.findVisible(timeout: Duration = Duration.ofSeconds(15)) = run {
waitFor(timeout, Duration.ofMillis(250)) {
inline fun <reified T : Fixture> RemoteRobot.findVisible(timeout: Duration = Duration.ofSeconds(45)) = run {
waitFor(timeout, Duration.ofMillis(100),
errorMessage = "Could not find component of class ${T::class.java.canonicalName}") {
runCatching {
find(T::class.java, Duration.ofMillis(100)).callJs<Boolean>("true")
}.getOrDefault(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package com.mongodb.jbplugin.fixtures

import com.intellij.remoterobot.RemoteRobot
import com.intellij.remoterobot.fixtures.ComponentFixture
import com.intellij.remoterobot.fixtures.ContainerFixture
import com.intellij.remoterobot.launcher.Ide
import com.intellij.remoterobot.launcher.IdeDownloader
Expand All @@ -15,6 +14,7 @@ import com.intellij.remoterobot.search.locators.byXpath
import com.intellij.remoterobot.steps.CommonSteps
import com.intellij.remoterobot.utils.DefaultHttpClient.client
import com.intellij.remoterobot.utils.waitFor
import com.intellij.util.io.delete
import okhttp3.OkHttpClient
import okhttp3.Request
import org.jsoup.Jsoup
Expand All @@ -25,6 +25,7 @@ import java.awt.image.BufferedImage
import java.io.ByteArrayOutputStream
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
import java.time.Duration
import java.util.concurrent.atomic.AtomicInteger
import javax.imageio.ImageIO
Expand Down Expand Up @@ -70,6 +71,7 @@ class UiTestExtension : BeforeAllCallback,

override fun afterAll(context: ExtensionContext?) {
ideForTest.dispose()
UiTestExtensions.downloadDirectory.delete(recursively = true)
}

override fun beforeTestExecution(context: ExtensionContext?) {
Expand All @@ -85,7 +87,6 @@ class UiTestExtension : BeforeAllCallback,
CommonSteps(ideForTest.remoteRobot).openProject(
Path("src/test/resources/project-fixtures/${requiresProject.value}").toAbsolutePath().toString()
)
ideForTest.remoteRobot.findVisible<ComponentFixture>(byXpath("//div[@class='EditorsSplitters']"))
}
}

Expand Down Expand Up @@ -213,7 +214,7 @@ annotation class RequiresProject(val value: String)

private object UiTestExtensions {
const val INITIAL_PORT: Int = 8_581
val downloadDirectory = Files.createTempDirectory("idea-download")
val downloadDirectory: Path = Files.createTempDirectory("idea-download")
val currentPort = AtomicInteger(INITIAL_PORT)
val developmentMode = System.getenv("DEVELOPMENT_MODE") == "true"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,28 @@ import com.intellij.remoterobot.search.locators.byXpath
import com.mongodb.jbplugin.fixtures.stripHtml

/**
* Represents the interactions with the hello message box.
*
* @param remoteRobot
* @param remoteComponent
*/
@DefaultXpath(by = "Title", xpath = "//div[@class='MyDialog']")
@DefaultXpath(by = "Name", xpath = "//div[@class='MyDialog' and @title='Build Info']")
@FixtureName(name = "Say Hello Message Box")
class SayHelloMessageBoxFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : ContainerFixture(
remoteRobot, remoteComponent
remoteRobot, remoteComponent
) {
val title = find(ComponentFixture::class.java, byXpath("//div[@visible_text='Build Info']")).callJs<String>(
"component.getText();"
).stripHtml()
val body = find(ComponentFixture::class.java, byXpath(
"//div[contains(@classhierarchy, 'javax.swing.JEditorPane')]"
)).callJs<String>("component.getText();").stripHtml()
val title by lazy {
find(ComponentFixture::class.java, byXpath("//div[@visible_text='Build Info']")).callJs<String>(
"component.getText();"
).stripHtml()
}
val body by lazy {
find(
ComponentFixture::class.java, byXpath("//div[@visible_text='4.11.0']")
).callJs<String>("component.getText();").stripHtml()
}

fun ok() {
find(ActionButtonFixture::class.java, byXpath("//div[@class='JButton']")).click()
find(ActionButtonFixture::class.java, byXpath("//div[@visible_text='OK']")).click()
}
}

0 comments on commit 9d1f71d

Please sign in to comment.