Skip to content

Commit 36be991

Browse files
committed
Add template for local UI testing
1 parent f3fbd5f commit 36be991

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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.config.ConfigurationStorage
9+
import com.intellij.ide.starter.di.di
10+
import com.intellij.ide.starter.driver.engine.runIdeWithDriver
11+
import com.intellij.ide.starter.ide.IdeProductProvider
12+
import com.intellij.ide.starter.junit5.hyphenateWithClass
13+
import com.intellij.ide.starter.models.TestCase
14+
import com.intellij.ide.starter.project.LocalProjectInfo
15+
import com.intellij.ide.starter.runner.CurrentTestMethod
16+
import com.intellij.ide.starter.runner.Starter
17+
import org.junit.jupiter.api.AfterAll
18+
import org.junit.jupiter.api.BeforeEach
19+
import org.junit.jupiter.api.Test
20+
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable
21+
import org.kodein.di.DI
22+
import org.kodein.di.bindSingleton
23+
import software.aws.toolkits.jetbrains.uitests.chatTests.dummyScript
24+
import java.io.File
25+
import java.nio.file.Path
26+
import java.nio.file.Paths
27+
28+
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
29+
class LocalUiTestRunTemplate {
30+
init {
31+
di = DI {
32+
extend(di)
33+
bindSingleton<CIServer>(overrides = true) { TestCIServer }
34+
val defaults = ConfigurationStorage.instance().defaults.toMutableMap().apply {
35+
put("LOG_ENVIRONMENT_VARIABLES", (!System.getenv("CI").toBoolean()).toString())
36+
}
37+
38+
bindSingleton<ConfigurationStorage>(overrides = true) {
39+
ConfigurationStorage(this, defaults)
40+
}
41+
}
42+
}
43+
44+
@BeforeEach
45+
fun setUp() {
46+
// Setup test environment
47+
setupTestEnvironment()
48+
}
49+
50+
@Test
51+
fun `Local testing example`() {
52+
val testCase = TestCase(
53+
IdeProductProvider.IC,
54+
LocalProjectInfo(
55+
Paths.get("tstData", "Hello")
56+
)
57+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
58+
59+
useExistingConnectionForTest()
60+
61+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
62+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
63+
pluginConfigurator.installPluginFromPath(
64+
Path.of(path)
65+
)
66+
}
67+
68+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
69+
updateGeneralSettings()
70+
}.runIdeWithDriver()
71+
.useDriverAndCloseIde {
72+
waitForProjectOpen()
73+
// required wait time for the system to be fully ready
74+
Thread.sleep(30000)
75+
76+
val result = executePuppeteerScript(dummyScript)
77+
// only for detekt
78+
result
79+
80+
// write your assertions here
81+
82+
Thread.sleep(20000)
83+
}
84+
}
85+
86+
companion object {
87+
@JvmStatic
88+
@AfterAll
89+
fun clearAwsXml() {
90+
clearAwsXmlFile()
91+
}
92+
}
93+
}

ui-tests-starter/tst-243+/software/aws/toolkits/jetbrains/uitests/chatTests/TestCaseScripts.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,28 @@ async function testNavigation() {
3434
testNavigation().catch(console.error);
3535
3636
""".trimIndent()
37+
38+
// language=JS
39+
val dummyScript = """
40+
import puppeteer from "puppeteer";
41+
42+
async function testNavigation() {
43+
const browser = await puppeteer.connect({
44+
browserURL: "http://localhost:9222"
45+
})
46+
try {
47+
const pages = await browser.pages()
48+
for(const page of pages) {
49+
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));
50+
const element = await page.$('.mynah-chat-prompt-input')
51+
if(element) {
52+
53+
}
54+
}
55+
} finally {
56+
await browser.close();
57+
}
58+
}
59+
testNavigation().catch(console.error);
60+
61+
""".trimIndent()

ui-tests-starter/tst-prep/PreAmazonQUiTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.intellij.testFramework.junit5.TestDisposable
77
import org.junit.Rule
88
import org.junit.jupiter.api.BeforeEach
99
import org.junit.jupiter.api.Test
10+
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable
1011
import org.junit.jupiter.api.extension.ExtendWith
1112
import software.aws.toolkits.core.rules.SystemPropertyHelper
1213
import software.aws.toolkits.jetbrains.core.credentials.LegacyManagedBearerSsoConnection
@@ -18,6 +19,7 @@ import software.aws.toolkits.jetbrains.core.credentials.sso.bearer.BearerTokenPr
1819
import software.aws.toolkits.jetbrains.utils.extensions.SsoLogin
1920
import software.aws.toolkits.jetbrains.utils.extensions.SsoLoginExtension
2021

22+
@DisabledIfEnvironmentVariable(named = "CI", matches = "false")
2123
@ExtendWith(ApplicationExtension::class, SsoLoginExtension::class)
2224
@SsoLogin("amazonq-test-account")
2325
class PreAmazonQUiTest {
@@ -33,7 +35,9 @@ class PreAmazonQUiTest {
3335

3436
@BeforeEach
3537
fun setUp() {
38+
System.setProperty("aws.profile", "ghtestlambda")
3639
System.setProperty("aws.dev.useDAG", "true")
40+
System.setProperty("aws.region", "us-west-2")
3741
}
3842

3943
@Test

0 commit comments

Comments
 (0)