From a63f799e720d2f9c0bed31233381f35e44b16cdd Mon Sep 17 00:00:00 2001 From: "Viktoria.Shirunova" Date: Fri, 30 Nov 2018 22:34:34 +0300 Subject: [PATCH] [gui-test] make CreateJdkGuiTest accessible for all editions --- .../KotlinCreateProjectGuiTestSuite.kt | 2 + .../installKotlinPlugin/CreateSdksGuiTest.kt | 28 +---------- .../kotlin/model/KotlinTestProperties.kt | 6 --- .../testGuiFramework/impl/GuiTestCaseExt.kt | 46 ++++++++++++++++++- .../testCases/CreateJdkGuiTest.kt | 43 +++++++++++++++++ 5 files changed, 91 insertions(+), 34 deletions(-) create mode 100644 platform/testGuiFramework/src/com/intellij/testGuiFramework/testCases/CreateJdkGuiTest.kt diff --git a/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/createProject/KotlinCreateProjectGuiTestSuite.kt b/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/createProject/KotlinCreateProjectGuiTestSuite.kt index f592ce34d42e..89d3b8188f48 100644 --- a/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/createProject/KotlinCreateProjectGuiTestSuite.kt +++ b/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/createProject/KotlinCreateProjectGuiTestSuite.kt @@ -9,6 +9,7 @@ import com.intellij.testGuiFramework.framework.GuiTestSuiteRunner import com.intellij.testGuiFramework.framework.RunWithIde import com.intellij.testGuiFramework.launcher.ide.CommunityIde import com.intellij.testGuiFramework.launcher.ide.CommunityIdeFirstStart +import com.intellij.testGuiFramework.testCases.CreateJdkGuiTest import org.junit.runner.RunWith import org.junit.runners.Suite @@ -73,6 +74,7 @@ class ConfigureKotlinReleaseGuiTestSuite : GuiTestSuite() @Suite.SuiteClasses( InstallPluginGuiTest::class , CreateSdksGuiTest::class + , CreateJdkGuiTest::class ) class PreparationSteps diff --git a/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/installKotlinPlugin/CreateSdksGuiTest.kt b/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/installKotlinPlugin/CreateSdksGuiTest.kt index 20ded0f25a14..66dc23b6fa4d 100644 --- a/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/installKotlinPlugin/CreateSdksGuiTest.kt +++ b/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/installKotlinPlugin/CreateSdksGuiTest.kt @@ -13,33 +13,7 @@ import org.junit.Ignore import org.junit.Test class CreateSdksGuiTest : KotlinGuiTestCase() { - val dialogName = "Project Structure for New Projects" - @Test - @Ignore - fun createJdk(){ - logTestStep("Create a JDK on the path `${KotlinTestProperties.jdk_path}`") - welcomeFrame { - actionLink("Configure").click() - // starting from 191 - popupMenu("Structure for New Projects").clickSearchedItem() - logUIStep("Open `$dialogName` dialog") - dialog(dialogName) { - jList("SDKs").clickItem("SDKs") - actionButton("Add New SDK").click() - popupMenu("JDK").clickSearchedItem() - logUIStep("Open `Select Home Directory for JDK` dialog") - dialog("Select Home Directory for JDK") { - actionButton("Refresh").click() - logUIStep("Type the path `${KotlinTestProperties.jdk_path}`") - typeText(KotlinTestProperties.jdk_path) - logUIStep("Close `Select Home Directory for JDK` dialog with OK") - button("OK").click() - } - logUIStep("Close `Default Project Structure` dialog with OK") - button("OK").click() - } - } - } + private val dialogName = "Project Structure for New Projects" @Test fun createKotlinSdk(){ diff --git a/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/model/KotlinTestProperties.kt b/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/model/KotlinTestProperties.kt index 5166a8926f4c..345f032389c1 100644 --- a/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/model/KotlinTestProperties.kt +++ b/community-guitests/testSrc/com/intellij/ide/projectWizard/kotlin/model/KotlinTestProperties.kt @@ -81,10 +81,4 @@ object KotlinTestProperties { val kotlin_plugin_version_full: String get() = "v${getPropertyValue("kotlin.plugin.version.full")}" - /** - * @return path where the Java is installed - */ - val jdk_path: String - get() = getPropertyValue("JAVA_HOME") - } \ No newline at end of file diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCaseExt.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCaseExt.kt index 1bf8edaa6e31..5ec574dc6106 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCaseExt.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCaseExt.kt @@ -19,6 +19,7 @@ import org.hamcrest.Matcher import org.junit.Assert.assertTrue import org.junit.rules.ErrorCollector import java.awt.IllegalComponentStateException +import javax.swing.JTree fun ErrorCollector.checkThat(value: T, matcher: Matcher, reason: () -> String) { checkThat(reason(), value, matcher) @@ -106,7 +107,7 @@ fun GuiTestCase.waitAMoment() { fun GuiTestCase.testTreeItemExist(name: String, vararg expectedItem: String, predicate: FinderPredicate = Predicate.equality) { ideFrame { logInfo("Check that $name -> ${expectedItem.joinToString(" -> ")} exists in a tree element") - kotlin.assert(exists { jTree(*expectedItem, predicate = predicate, timeout = Timeouts.seconds03) }) { "$name '${expectedItem.joinToString(", ")}' not found" } + kotlin.assert(exists { jTree(*expectedItem, predicate = predicate) }) { "$name '${expectedItem.joinToString(", ")}' not found" } } } @@ -325,3 +326,46 @@ fun GuiTestCase.checkGutterIcons(gutterIcon: GutterFixture.GutterIcon, } } } + +fun GuiTestCase.createJdk(jdkPath: String, jdkName: String = ""): String{ + val dialogName = "Project Structure for New Projects" + logTestStep("Create a JDK on the path `$jdkPath`") + lateinit var installedJdkName: String + welcomeFrame { + actionLink("Configure").click() + popupMenu("Project Defaults").clickSearchedItem() + popupMenu("Project Structure").clickSearchedItem() + logUIStep("Open `$dialogName` dialog") + dialog(dialogName) { + jList("SDKs").clickItem("SDKs") + val sdkTree: ExtendedJTreePathFixture = jTree() + + fun JTree.getListOfInstalledSdks(): List { + val root = model.root + return (0 until model.getChildCount(root)) + .map { model.getChild(root, it).toString() }.toList() + } + + val preInstalledSdks = sdkTree.tree.getListOfInstalledSdks() + installedJdkName = if(jdkName.isEmpty() || preInstalledSdks.contains(jdkName).not()){ + actionButton("Add New SDK").click() + popupMenu("JDK").clickSearchedItem() + logUIStep("Open `Select Home Directory for JDK` dialog") + dialog("Select Home Directory for JDK") { + actionButton("Refresh").click() + logUIStep("Type the path `$jdkPath`") + typeText(jdkPath) + logUIStep("Close `Select Home Directory for JDK` dialog with OK") + button("OK").click() + } + + val postInstalledSdks = sdkTree.tree.getListOfInstalledSdks() + postInstalledSdks.first { preInstalledSdks.contains(it).not() } + } + else jdkName + logUIStep("Close `Default Project Structure` dialog with OK") + button("OK").click() + } // dialog Project Structure + } // ideFrame + return installedJdkName +} diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/testCases/CreateJdkGuiTest.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/testCases/CreateJdkGuiTest.kt new file mode 100644 index 000000000000..582ca29f9ee2 --- /dev/null +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/testCases/CreateJdkGuiTest.kt @@ -0,0 +1,43 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.testGuiFramework.testCases + +import com.intellij.testGuiFramework.impl.GuiTestCase +import com.intellij.testGuiFramework.impl.createJdk +import org.junit.Ignore +import org.junit.Test + +class CreateJdkGuiTest : GuiTestCase() { + + private val javaHome = "JAVA_HOME" + private val java18Home = "JAVA18_HOME" + private val java11Home = "JAVA11_HOME" + + private fun getProperty(name: String) = System.getenv(name) ?: throw IllegalStateException("Property `$name` not set in Environment!") + + @Test + fun createJdk18() { + val expectedJdk = "1.8" + val installedJdk = createJdk(getProperty(java18Home), expectedJdk) + assert(expectedJdk == installedJdk) { + "Expected JDK 1.8 to be installed, but $installedJdk discovered" + } + } + + @Test + @Ignore + fun createJdk11() { + val expectedJdk = "11" + val installedJdk = createJdk(getProperty(java11Home), expectedJdk) + assert(expectedJdk == installedJdk) { + "Expected JDK 11 to be installed, but $installedJdk discovered" + } + } + + @Test + @Ignore + fun createJdkFromHome() { + createJdk(getProperty(javaHome)) + } + + override fun isIdeFrameRun() = false +} \ No newline at end of file