Skip to content

Commit 65e6888

Browse files
committed
sam ui test migrate to starter
1 parent 5416099 commit 65e6888

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright 2021 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.ui.components.textField
7+
import com.intellij.driver.sdk.ui.ui
8+
import com.intellij.driver.sdk.waitForProjectOpen
9+
import com.intellij.ide.starter.driver.engine.runIdeWithDriver
10+
import com.intellij.ide.starter.ide.IdeProductProvider
11+
import com.intellij.ide.starter.models.TestCase
12+
import com.intellij.ide.starter.project.LocalProjectInfo
13+
import com.intellij.ide.starter.runner.Starter
14+
import org.assertj.core.api.Assertions.assertThat
15+
import org.junit.jupiter.api.BeforeAll
16+
import org.junit.jupiter.api.Test
17+
import org.junit.jupiter.api.TestInstance
18+
import org.junit.jupiter.api.io.TempDir
19+
import org.slf4j.LoggerFactory
20+
import software.aws.toolkits.jetbrains.uitests.utils.IdeStarterTestUtils
21+
import software.aws.toolkits.jetbrains.uitests.utils.IdeStarterTestUtils.findAndClick
22+
import java.io.File
23+
import java.nio.file.Path
24+
import java.util.Locale
25+
26+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
27+
class SamTemplateProjectWizardTest {
28+
private val logger = LoggerFactory.getLogger(javaClass)
29+
30+
@TempDir
31+
lateinit var tempDir: Path
32+
33+
private var samCliConfigured = false
34+
35+
@BeforeAll
36+
fun setup() {
37+
val samPath = System.getenv("SAM_CLI_EXEC")
38+
if (samPath.isNullOrEmpty()) {
39+
logger.warn("No custom SAM set, skipping setup")
40+
return
41+
}
42+
}
43+
44+
@Test
45+
fun createSamApp() {
46+
if (!samCliConfigured) {
47+
IdeStarterTestUtils.setupSamCliWithStarter(tempDir)
48+
samCliConfigured = true
49+
}
50+
51+
val testCase = TestCase(
52+
IdeProductProvider.IC,
53+
LocalProjectInfo(tempDir)
54+
)
55+
56+
Starter.newContext("createSamApp", testCase).apply {
57+
// Install required plugins
58+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
59+
pluginConfigurator.installPluginFromPath(Path.of(path))
60+
}
61+
62+
updateGeneralSettings()
63+
}.runIdeWithDriver()
64+
.useDriverAndCloseIde {
65+
ui.findAndClick("//div[contains(@accessiblename, 'New Project')]")
66+
67+
ui.findAndClick("//div[text='AWS']")
68+
69+
ui.findAndClick("//div[text='AWS Serverless Application']")
70+
71+
ui.findAndClick("//button[text='Next']")
72+
73+
ui.textField("//div[@class='TextFieldWithBrowseButton']").text = tempDir.toAbsolutePath().toString()
74+
75+
ui.findAndClick("//button[text='Create']")
76+
77+
waitForProjectOpen()
78+
79+
ui.textField("//div[@class='EditorTab' and contains(@text, 'README.md')]")?.let { editor ->
80+
assertThat(editor).isNotNull()
81+
}
82+
83+
ui.keyboard {
84+
if (System.getProperty("os.name").lowercase(Locale.getDefault()).contains("mac")) {
85+
hotKey(157, 59) // Cmd + ; for Mac
86+
} else {
87+
hotKey(17, 18, 16, 83) // Ctrl + Alt + Shift + S for Windows/Linux
88+
}
89+
}
90+
91+
ui.textField("//div[@class='JdkComboBox']")?.let { jdkCombo ->
92+
assertThat(jdkCombo.text).startsWith("2")
93+
}
94+
95+
ui.findAndClick("//button[text='OK']")
96+
}
97+
}
98+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.utils
5+
6+
import com.intellij.driver.sdk.ui.UiRobot
7+
import com.intellij.driver.sdk.ui.components.textField
8+
import com.intellij.driver.sdk.ui.ui
9+
import com.intellij.ide.starter.driver.engine.runIdeWithDriver
10+
import com.intellij.ide.starter.ide.IdeProductProvider
11+
import com.intellij.ide.starter.models.TestCase
12+
import com.intellij.ide.starter.project.LocalProjectInfo
13+
import com.intellij.ide.starter.runner.Starter
14+
import org.slf4j.LoggerFactory
15+
import java.awt.Point
16+
import java.nio.file.Path
17+
import java.util.Locale
18+
19+
object IdeStarterTestUtils {
20+
private val LOG = LoggerFactory.getLogger(IdeStarterTestUtils::class.java)
21+
fun UiRobot.findAndClick(xpath: String) {
22+
searchService.findAll(xpath).firstOrNull()?.let { component ->
23+
val point = Point(component.x + component.width / 2, component.y + component.height / 2)
24+
clickMouse(point)
25+
}
26+
}
27+
fun setupSamCliWithStarter(tempDir: Path) {
28+
val samPath = System.getenv("SAM_CLI_EXEC")
29+
if (samPath.isNullOrEmpty()) {
30+
LOG.warn("No custom SAM set, skipping setup")
31+
return
32+
}
33+
34+
val testCase = TestCase(
35+
IdeProductProvider.IC,
36+
LocalProjectInfo(tempDir)
37+
)
38+
39+
Starter.newContext("setupSamCli", testCase).apply {
40+
updateGeneralSettings()
41+
}.runIdeWithDriver()
42+
.useDriverAndCloseIde {
43+
// Open Preferences/Settings
44+
ui.keyboard {
45+
if (System.getProperty("os.name").lowercase(Locale.getDefault()).contains("mac")) {
46+
hotKey(157, 44) // Cmd + , for Mac
47+
} else {
48+
hotKey(17, 18, 83) // Ctrl + Alt + S for Windows/Linux
49+
}
50+
}
51+
52+
ui.textField("//div[@class='SearchField']").text = "AWS"
53+
54+
ui.findAndClick("//div[text='Tools']")
55+
ui.findAndClick("//div[text='AWS']")
56+
57+
ui.textField("//div[@text='SAM CLI executable:']").text = samPath
58+
59+
ui.findAndClick("//button[text='OK']")
60+
61+
ui.findAndClick("//div[text='Projects']")
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)