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