|
| 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 | +} |
0 commit comments