Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add template for local UI testing #5407

Open
wants to merge 2 commits into
base: manodnyb/tryPuppeteerWithAuth
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.jetbrains.uitests

import com.intellij.driver.sdk.waitForProjectOpen
import com.intellij.ide.starter.ci.CIServer
import com.intellij.ide.starter.config.ConfigurationStorage
import com.intellij.ide.starter.di.di
import com.intellij.ide.starter.driver.engine.runIdeWithDriver
import com.intellij.ide.starter.ide.IdeProductProvider
import com.intellij.ide.starter.junit5.hyphenateWithClass
import com.intellij.ide.starter.models.TestCase
import com.intellij.ide.starter.project.LocalProjectInfo
import com.intellij.ide.starter.runner.CurrentTestMethod
import com.intellij.ide.starter.runner.Starter
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable
import org.kodein.di.DI
import org.kodein.di.bindSingleton
import software.aws.toolkits.jetbrains.uitests.chatTests.dummyScript
import java.io.File
import java.nio.file.Path
import java.nio.file.Paths

@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
class LocalUiTestRunTemplate {
init {
di = DI {
extend(di)
bindSingleton<CIServer>(overrides = true) { TestCIServer }
val defaults = ConfigurationStorage.instance().defaults.toMutableMap().apply {
put("LOG_ENVIRONMENT_VARIABLES", (!System.getenv("CI").toBoolean()).toString())
}

bindSingleton<ConfigurationStorage>(overrides = true) {
ConfigurationStorage(this, defaults)
}
}
}

@BeforeEach
fun setUp() {
// Setup test environment
setupTestEnvironment()
}

@Test
fun `Local testing example`() {
val testCase = TestCase(
IdeProductProvider.IC,
LocalProjectInfo(
Paths.get("tstData", "Hello")
)
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))

useExistingConnectionForTest()

Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
pluginConfigurator.installPluginFromPath(
Path.of(path)
)
}

copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
updateGeneralSettings()
}.runIdeWithDriver()
.useDriverAndCloseIde {
waitForProjectOpen()
// required wait time for the system to be fully ready
Thread.sleep(30000)

val result = executePuppeteerScript(dummyScript)
// only for detekt
result

// write your assertions here

Thread.sleep(20000)
}
}

companion object {
@JvmStatic
@AfterAll
fun clearAwsXml() {
clearAwsXmlFile()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,28 @@ async function testNavigation() {
testNavigation().catch(console.error);

""".trimIndent()

// language=JS
val dummyScript = """
import puppeteer from "puppeteer";

async function testNavigation() {
const browser = await puppeteer.connect({
browserURL: "http://localhost:9222"
})
try {
const pages = await browser.pages()
for(const page of pages) {
const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root'));
const element = await page.$('.mynah-chat-prompt-input')
if(element) {

}
}
} finally {
await browser.close();
}
}
testNavigation().catch(console.error);

""".trimIndent()
2 changes: 2 additions & 0 deletions ui-tests-starter/tst-prep/PreAmazonQUiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.intellij.testFramework.junit5.TestDisposable
import org.junit.Rule
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable
import org.junit.jupiter.api.extension.ExtendWith
import software.aws.toolkits.core.rules.SystemPropertyHelper
import software.aws.toolkits.jetbrains.core.credentials.LegacyManagedBearerSsoConnection
Expand All @@ -18,6 +19,7 @@ import software.aws.toolkits.jetbrains.core.credentials.sso.bearer.BearerTokenPr
import software.aws.toolkits.jetbrains.utils.extensions.SsoLogin
import software.aws.toolkits.jetbrains.utils.extensions.SsoLoginExtension

@DisabledIfEnvironmentVariable(named = "CI", matches = "false")
@ExtendWith(ApplicationExtension::class, SsoLoginExtension::class)
@SsoLogin("amazonq-test-account")
class PreAmazonQUiTest {
Expand Down
Loading