Skip to content

Commit 4c09587

Browse files
committed
Using puppeteer for basic tests
1 parent a545699 commit 4c09587

File tree

4 files changed

+190
-2
lines changed

4 files changed

+190
-2
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ toolkitVersion=3.52-SNAPSHOT
88
publishToken=
99
publishChannel=
1010

11-
ideProfileName=2024.2
11+
ideProfileName=2024.3
1212

1313
remoteRobotPort=8080
1414

ui-tests-starter/build.gradle.kts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,27 @@ intellijPlatform {
3030
val testPlugins by configurations.registering
3131

3232
dependencies {
33-
testImplementation(platform("com.jetbrains.intellij.tools:ide-starter-squashed"))
33+
//testImplementation(platform("com.jetbrains.intellij.tools:ide-starter"))
3434
// should really be set by the BOM, but too much work to figure out right now
3535
testImplementation("org.kodein.di:kodein-di-jvm:7.20.2")
36+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
37+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0")
38+
39+
testImplementation(project(":plugin-core:jetbrains-community"))
40+
testImplementation(project(":plugin-core:core"))
41+
testImplementation(testFixtures(project(":plugin-core:jetbrains-community")))
42+
43+
44+
45+
46+
3647
intellijPlatform {
3748
intellijIdeaCommunity(IdeVersions.ideProfile(providers).map { it.name })
49+
intellijIdeaCommunity(ideProfile.community.sdkVersion)
3850

51+
testFramework(TestFrameworkType.JUnit5)
3952
testFramework(TestFrameworkType.Starter)
53+
testFramework(TestFrameworkType.Bundled)
4054
}
4155

4256
testPlugins(project(":plugin-amazonq", "pluginZip"))
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.uitests
5+
6+
import com.intellij.driver.sdk.waitForProjectOpen
7+
import com.intellij.ide.starter.ci.CIServer
8+
import com.intellij.ide.starter.di.di
9+
import com.intellij.ide.starter.driver.engine.runIdeWithDriver
10+
import com.intellij.ide.starter.ide.IdeProductProvider
11+
import com.intellij.ide.starter.junit5.hyphenateWithClass
12+
import com.intellij.ide.starter.models.TestCase
13+
import com.intellij.ide.starter.project.LocalProjectInfo
14+
import com.intellij.ide.starter.runner.CurrentTestMethod
15+
import com.intellij.ide.starter.runner.Starter
16+
import org.junit.jupiter.api.Assertions.assertEquals
17+
import org.junit.jupiter.api.Assertions.assertTrue
18+
import org.junit.jupiter.api.BeforeEach
19+
import org.junit.jupiter.api.Test
20+
import org.kodein.di.DI
21+
import org.kodein.di.bindSingleton
22+
import java.io.File
23+
import java.nio.file.Path
24+
import java.nio.file.Paths
25+
import kotlin.io.path.createParentDirectories
26+
import kotlin.io.path.writeText
27+
28+
class AmazonQChatTest {
29+
30+
init {
31+
di = DI {
32+
extend(di)
33+
bindSingleton<CIServer>(overrides = true) { TestCIServer }
34+
}
35+
}
36+
37+
private val testResourcesPath = "src/test/tstData"
38+
39+
@BeforeEach
40+
fun setUp() {
41+
// Setup test environment
42+
setupTestEnvironment()
43+
}
44+
private fun setupTestEnvironment() {
45+
// Ensure Puppeteer is installed
46+
val npmInstall = ProcessBuilder()
47+
.command("npm", "install", "puppeteer")
48+
.inheritIO()
49+
.start()
50+
.waitFor()
51+
52+
assertEquals(0, npmInstall, "Failed to install Puppeteer")
53+
54+
}
55+
56+
@Test
57+
fun `can open up IDE`() {
58+
val testCase = TestCase(
59+
IdeProductProvider.IC,
60+
LocalProjectInfo(
61+
Paths.get("tstData", "Hello")
62+
)
63+
).useRelease("2024.3")
64+
65+
66+
67+
Paths.get(System.getProperty("user.home"), ".aws", "sso", "cache", "ee1d2538cb8d358377d7661466c866af747a8a3f.json")
68+
.createParentDirectories()
69+
.writeText(
70+
"""
71+
paste your client reg here
72+
""".trimIndent()
73+
)
74+
75+
Paths.get(System.getProperty("user.home"), ".aws", "sso", "cache", "d3b447f809607422aac1470dd17fbb32e358cdb3.json")
76+
.writeText(
77+
"""
78+
paste your access token here
79+
""".trimIndent()
80+
)
81+
82+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
83+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
84+
pluginConfigurator.installPluginFromPath(
85+
Path.of(path)
86+
)
87+
}
88+
89+
copyExistingConfig(Paths.get("tstData", "config"))
90+
updateGeneralSettings()
91+
}.runIdeWithDriver()
92+
.useDriverAndCloseIde {
93+
waitForProjectOpen()
94+
Thread.sleep(20000)
95+
96+
97+
val result = executeScript(scr)
98+
assertTrue(result.contains("/doc"))
99+
assertTrue(result.contains("/dev"))
100+
assertTrue(result.contains("/transform"))
101+
assertTrue(result.contains("/help"))
102+
assertTrue(result.contains("/clear"))
103+
assertTrue(result.contains("/review"))
104+
assertTrue(result.contains("/test"))
105+
}
106+
}
107+
108+
private fun executeScript(scriptContent: String): String {
109+
val scriptFile = File("$testResourcesPath/temp-script.js")
110+
scriptFile.parentFile.mkdirs()
111+
scriptFile.writeText(scriptContent)
112+
113+
val process = ProcessBuilder()
114+
.command("node", scriptFile.absolutePath)
115+
.redirectErrorStream(true)
116+
.start()
117+
118+
val output = process.inputStream.bufferedReader().use { it.readText() }
119+
val exitCode = process.waitFor()
120+
121+
scriptFile.delete()
122+
123+
assertEquals(0, exitCode, "Script execution failed with output: $output")
124+
return output
125+
}
126+
127+
128+
}
129+
130+
private val scr = """
131+
import puppeteer from "puppeteer";
132+
133+
async function testNavigation() {
134+
const browser = await puppeteer.connect({
135+
browserURL: "http://localhost:9222"
136+
})
137+
138+
try {
139+
140+
const pages = await browser.pages()
141+
//console.log(pages)
142+
for(const page of pages) {
143+
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));
144+
//console.log(contents)
145+
const element = await page.$('.mynah-chat-prompt-input')
146+
if(element) {
147+
console.log("found")
148+
149+
await page.type('.mynah-chat-prompt-input', '/')
150+
const elements = await page.$$(".mynah-chat-command-selector-command");
151+
const attr = await Promise.all(
152+
elements.map(async element => {
153+
return element.evaluate(el => el.getAttribute("command"));
154+
})
155+
);
156+
157+
158+
159+
console.log("found commands")
160+
console.log(JSON.stringify(attr, null, 2))
161+
162+
}
163+
}
164+
165+
166+
} finally {
167+
await browser.close();
168+
}
169+
}
170+
171+
testNavigation().catch(console.error);
172+
173+
""".trimIndent()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<application>
22
<component name="Registry">
33
<entry key="performance.watcher.unresponsive.interval.ms" value="500" />
4+
<entry key="ide.browser.jcef.debug.port" value="9222"/>
45
</component>
56
</application>

0 commit comments

Comments
 (0)