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

[WIP] SamTemplateProjectWizard UI test migrate to intellij-ide-starter framework #5348

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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,98 @@
// Copyright 2021 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.ui.components.textField
import com.intellij.driver.sdk.ui.ui
import com.intellij.driver.sdk.waitForProjectOpen
import com.intellij.ide.starter.driver.engine.runIdeWithDriver
import com.intellij.ide.starter.ide.IdeProductProvider
import com.intellij.ide.starter.models.TestCase
import com.intellij.ide.starter.project.LocalProjectInfo
import com.intellij.ide.starter.runner.Starter
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.io.TempDir
import org.slf4j.LoggerFactory
import software.aws.toolkits.jetbrains.uitests.utils.IdeStarterTestUtils
import software.aws.toolkits.jetbrains.uitests.utils.IdeStarterTestUtils.findAndClick
import java.io.File
import java.nio.file.Path
import java.util.Locale

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class SamTemplateProjectWizardTest {
private val logger = LoggerFactory.getLogger(javaClass)

@TempDir
lateinit var tempDir: Path

private var samCliConfigured = false

@BeforeAll
fun setup() {
val samPath = System.getenv("SAM_CLI_EXEC")
if (samPath.isNullOrEmpty()) {
logger.warn("No custom SAM set, skipping setup")
return
}
}

@Test
fun createSamApp() {
if (!samCliConfigured) {
IdeStarterTestUtils.setupSamCliWithStarter(tempDir)
samCliConfigured = true
}

val testCase = TestCase(
IdeProductProvider.IC,
LocalProjectInfo(tempDir)
)

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

updateGeneralSettings()
}.runIdeWithDriver()
.useDriverAndCloseIde {
ui.findAndClick("//div[contains(@accessiblename, 'New Project')]")

ui.findAndClick("//div[text='AWS']")

ui.findAndClick("//div[text='AWS Serverless Application']")

ui.findAndClick("//button[text='Next']")

ui.textField("//div[@class='TextFieldWithBrowseButton']").text = tempDir.toAbsolutePath().toString()

ui.findAndClick("//button[text='Create']")

waitForProjectOpen()

ui.textField("//div[@class='EditorTab' and contains(@text, 'README.md')]")?.let { editor ->
assertThat(editor).isNotNull()
}

ui.keyboard {
if (System.getProperty("os.name").lowercase(Locale.getDefault()).contains("mac")) {
hotKey(157, 59) // Cmd + ; for Mac
} else {
hotKey(17, 18, 16, 83) // Ctrl + Alt + Shift + S for Windows/Linux
}
}

ui.textField("//div[@class='JdkComboBox']")?.let { jdkCombo ->
assertThat(jdkCombo.text).startsWith("2")
}

ui.findAndClick("//button[text='OK']")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.jetbrains.uitests.utils

import com.intellij.driver.sdk.ui.UiRobot
import com.intellij.driver.sdk.ui.components.textField
import com.intellij.driver.sdk.ui.ui
import com.intellij.ide.starter.driver.engine.runIdeWithDriver
import com.intellij.ide.starter.ide.IdeProductProvider
import com.intellij.ide.starter.models.TestCase
import com.intellij.ide.starter.project.LocalProjectInfo
import com.intellij.ide.starter.runner.Starter
import org.slf4j.LoggerFactory
import java.awt.Point
import java.nio.file.Path
import java.util.Locale

object IdeStarterTestUtils {
private val LOG = LoggerFactory.getLogger(IdeStarterTestUtils::class.java)
fun UiRobot.findAndClick(xpath: String) {
searchService.findAll(xpath).firstOrNull()?.let { component ->
val point = Point(component.x + component.width / 2, component.y + component.height / 2)
clickMouse(point)
}
}
fun setupSamCliWithStarter(tempDir: Path) {
val samPath = System.getenv("SAM_CLI_EXEC")
if (samPath.isNullOrEmpty()) {
LOG.warn("No custom SAM set, skipping setup")
return
}

val testCase = TestCase(
IdeProductProvider.IC,
LocalProjectInfo(tempDir)
)

Starter.newContext("setupSamCli", testCase).apply {
updateGeneralSettings()
}.runIdeWithDriver()
.useDriverAndCloseIde {
// Open Preferences/Settings
ui.keyboard {
if (System.getProperty("os.name").lowercase(Locale.getDefault()).contains("mac")) {
hotKey(157, 44) // Cmd + , for Mac
} else {
hotKey(17, 18, 83) // Ctrl + Alt + S for Windows/Linux
}
}

ui.textField("//div[@class='SearchField']").text = "AWS"

ui.findAndClick("//div[text='Tools']")
ui.findAndClick("//div[text='AWS']")

ui.textField("//div[@text='SAM CLI executable:']").text = samPath

ui.findAndClick("//button[text='OK']")

ui.findAndClick("//div[text='Projects']")
}
}
}
Loading