mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[gui-test] support linkLabels, move all java dependent part from main fixtures
This commit is contained in:
+13
-16
@@ -16,8 +16,6 @@
|
||||
package com.intellij.testGuiFramework.fixtures.newProjectWizard;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.ui.configuration.JdkComboBox;
|
||||
import com.intellij.testGuiFramework.fixtures.FrameworksTreeFixture;
|
||||
import com.intellij.testGuiFramework.fixtures.SelectSdkDialogFixture;
|
||||
@@ -38,7 +36,6 @@ import java.awt.*;
|
||||
import java.io.File;
|
||||
|
||||
import static com.intellij.testGuiFramework.framework.GuiTestUtil.LONG_TIMEOUT;
|
||||
import static com.intellij.testGuiFramework.framework.GuiTestUtil.getSystemJdk;
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.fest.swing.edt.GuiActionRunner.execute;
|
||||
import static org.fest.swing.finder.WindowFinder.findDialog;
|
||||
@@ -135,19 +132,19 @@ public class NewProjectWizardFixture extends AbstractWizardFixture<NewProjectWiz
|
||||
});
|
||||
}
|
||||
|
||||
public NewProjectWizardFixture setupJdk() {
|
||||
if (this.isJdkEmpty()) {
|
||||
JButton newButton = GuiTestUtil.findButton(this,
|
||||
GuiTestUtil.adduction(ApplicationBundle.message("button.new")),
|
||||
robot());
|
||||
robot().click(newButton);
|
||||
File javaSdkPath = new File(getSystemJdk());
|
||||
String sdkType = GuiTestUtil.adduction(ProjectBundle.message("sdk.java.name"));
|
||||
GuiTestUtil.clickPopupMenuItem(sdkType, newButton, robot());
|
||||
this.selectSdkPath(javaSdkPath, sdkType);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
//public NewProjectWizardFixture setupJdk() {
|
||||
// if (this.isJdkEmpty()) {
|
||||
// JButton newButton = GuiTestUtil.findButton(this,
|
||||
// GuiTestUtil.adduction(ApplicationBundle.message("button.new")),
|
||||
// robot());
|
||||
// robot().click(newButton);
|
||||
// File javaSdkPath = new File(getSystemJdk());
|
||||
// String sdkType = GuiTestUtil.adduction(ProjectBundle.message("sdk.java.name"));
|
||||
// GuiTestUtil.clickPopupMenuItem(sdkType, newButton, robot());
|
||||
// this.selectSdkPath(javaSdkPath, sdkType);
|
||||
// }
|
||||
// return this;
|
||||
//}
|
||||
|
||||
|
||||
@NotNull
|
||||
|
||||
+21
-95
@@ -31,11 +31,7 @@ import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.ProjectManagerAdapter;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.SdkModificator;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.SwitchBootJdkAction;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
@@ -83,8 +79,6 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static com.intellij.openapi.projectRoots.JdkUtil.checkForJdk;
|
||||
import static com.intellij.openapi.util.io.FileUtil.pathsEqual;
|
||||
import static com.intellij.openapi.util.io.FileUtil.toCanonicalPath;
|
||||
import static com.intellij.openapi.util.io.FileUtilRt.toSystemDependentName;
|
||||
import static com.intellij.openapi.util.text.StringUtil.isNotEmpty;
|
||||
@@ -163,84 +157,6 @@ GuiTestUtil {
|
||||
@SuppressWarnings("unused")
|
||||
public static void setUpDefaultGeneralSettings() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static String getSystemJdk() {
|
||||
String jdkHome = getSystemPropertyOrEnvironmentVariable(JDK_HOME_FOR_TESTS);
|
||||
if (isNullOrEmpty(jdkHome) || !checkForJdk(jdkHome)) {
|
||||
//than use bundled JDK
|
||||
jdkHome = getBundledJdLocation();
|
||||
}
|
||||
if (isNullOrEmpty(jdkHome) || !checkForJdk(jdkHome)) {
|
||||
fail("Please specify the path to a valid JDK using system property " + JDK_HOME_FOR_TESTS);
|
||||
}
|
||||
return jdkHome;
|
||||
}
|
||||
|
||||
public static void setUpSdks() {
|
||||
|
||||
String jdkHome = getSystemPropertyOrEnvironmentVariable(JDK_HOME_FOR_TESTS);
|
||||
if (isNullOrEmpty(jdkHome) || !checkForJdk(jdkHome)) {
|
||||
//than use bundled JDK
|
||||
jdkHome = getBundledJdLocation();
|
||||
}
|
||||
final File jdkPath = new File(jdkHome);
|
||||
|
||||
execute(new GuiTask() {
|
||||
@Override
|
||||
protected void executeInEDT() throws Throwable {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LOG.info(String.format("Setting JDK: '%1$s'", jdkPath.getPath()));
|
||||
setJdkPath(jdkPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setJdkPath(@NotNull File path) {
|
||||
if (JavaSdk.checkForJdk(path)) {
|
||||
ApplicationManager.getApplication().assertWriteAccessAllowed();
|
||||
Sdk chosenJdk = null;
|
||||
|
||||
for (Sdk jdk : ProjectJdkTable.getInstance().getSdksOfType(JavaSdk.getInstance())) {
|
||||
if (pathsEqual(jdk.getHomePath(), path.getPath())) {
|
||||
chosenJdk = jdk;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (chosenJdk == null) {
|
||||
if (path.isDirectory()) {
|
||||
|
||||
JavaSdk javaSdk = JavaSdk.getInstance();
|
||||
|
||||
//in case of running different from IntelliJ or Android Studio IDE (PyCharm for example)
|
||||
if (javaSdk == null) return;
|
||||
|
||||
String jdk_name = "JDK";
|
||||
final Sdk newJdk = javaSdk.createJdk(jdk_name, path.toString(), false);
|
||||
final Sdk foundJdk = ProjectJdkTable.getInstance().findJdk(newJdk.getName(), newJdk.getSdkType().getName());
|
||||
if (foundJdk == null) {
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
ProjectJdkTable.getInstance().addJdk(newJdk);
|
||||
});
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
SdkModificator modificator = newJdk.getSdkModificator();
|
||||
JavaSdkImpl.attachJdkAnnotations(modificator);
|
||||
modificator.commitChanges();
|
||||
});
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("The resolved path '" + path.getPath() + "' was not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -665,17 +581,27 @@ GuiTestUtil {
|
||||
|
||||
@Nullable
|
||||
public static JLabel findBoundedLabel(@NotNull Container container, @NotNull JTextField textField, @NotNull Robot robot) {
|
||||
Collection<JLabel> labels = robot.finder().findAll(container, new GenericTypeMatcher<JLabel>(JLabel.class) {
|
||||
@Override
|
||||
protected boolean isMatching(@NotNull JLabel label) {
|
||||
return (label.getLabelFor() != null && label.getLabelFor().equals(textField));
|
||||
//in Case of parent component is TextFieldWithBrowseButton
|
||||
if(textField.getParent() instanceof TextFieldWithBrowseButton) {
|
||||
return robot.finder().find(container, new GenericTypeMatcher<JLabel>(JLabel.class) {
|
||||
@Override
|
||||
protected boolean isMatching(@NotNull JLabel label) {
|
||||
return (label.getLabelFor() != null && label.getLabelFor().equals(textField.getParent()));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Collection<JLabel> labels = robot.finder().findAll(container, new GenericTypeMatcher<JLabel>(JLabel.class) {
|
||||
@Override
|
||||
protected boolean isMatching(@NotNull JLabel label) {
|
||||
return (label.getLabelFor() != null && label.getLabelFor().equals(textField));
|
||||
}
|
||||
});
|
||||
if (labels != null && !labels.isEmpty()) {
|
||||
return labels.iterator().next();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
if (labels != null && !labels.isEmpty()) {
|
||||
return labels.iterator().next();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.testGuiFramework.idea
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.projectRoots.JavaSdk
|
||||
import com.intellij.openapi.projectRoots.JdkUtil
|
||||
import com.intellij.openapi.projectRoots.JdkUtil.checkForJdk
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl
|
||||
import com.intellij.openapi.util.io.FileUtil.pathsEqual
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.testGuiFramework.framework.GuiTestUtil.*
|
||||
import junit.framework.Assert.fail
|
||||
import org.fest.swing.edt.GuiActionRunner.execute
|
||||
import org.fest.swing.edt.GuiTask
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* @author Sergey Karashevich
|
||||
*/
|
||||
object IdeaGuiTestUtil{
|
||||
|
||||
val LOG = Logger.getInstance("#com.intellij.testGuiFramework.idea.IdeaGuiTestUtil")
|
||||
|
||||
fun setUpSdks() {
|
||||
|
||||
var jdkHome: String? = getSystemPropertyOrEnvironmentVariable(JDK_HOME_FOR_TESTS)
|
||||
if (StringUtil.isEmpty(jdkHome) || !JdkUtil.checkForJdk(jdkHome!!)) {
|
||||
//than use bundled JDK
|
||||
jdkHome = getBundledJdLocation()
|
||||
}
|
||||
val jdkPath = File(jdkHome)
|
||||
|
||||
execute(object : GuiTask() {
|
||||
@Throws(Throwable::class)
|
||||
override fun executeInEDT() {
|
||||
ApplicationManager.getApplication().runWriteAction {
|
||||
LOG.info(String.format("Setting JDK: '%1\$s'", jdkPath.path))
|
||||
setJdkPath(jdkPath)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun setJdkPath(path: File) {
|
||||
if (JavaSdk.checkForJdk(path)) {
|
||||
ApplicationManager.getApplication().assertWriteAccessAllowed()
|
||||
var chosenJdk: Sdk? = null
|
||||
|
||||
for (jdk in ProjectJdkTable.getInstance().getSdksOfType(JavaSdk.getInstance())) {
|
||||
if (pathsEqual(jdk.homePath, path.path)) {
|
||||
chosenJdk = jdk
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (chosenJdk == null) {
|
||||
if (path.isDirectory) {
|
||||
|
||||
val javaSdk = JavaSdk.getInstance() ?: return
|
||||
|
||||
//in case of running different from IntelliJ or Android Studio IDE (PyCharm for example)
|
||||
|
||||
val jdk_name = "JDK"
|
||||
val newJdk = javaSdk.createJdk(jdk_name, path.toString(), false)
|
||||
val foundJdk = ProjectJdkTable.getInstance().findJdk(newJdk.name, newJdk.sdkType.name)
|
||||
if (foundJdk == null) {
|
||||
ApplicationManager.getApplication().runWriteAction { ProjectJdkTable.getInstance().addJdk(newJdk) }
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction {
|
||||
val modificator = newJdk.sdkModificator
|
||||
JavaSdkImpl.attachJdkAnnotations(modificator)
|
||||
modificator.commitChanges()
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw IllegalStateException("The resolved path '" + path.path + "' was not found")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getSystemJdk(): String {
|
||||
var jdkHome: String? = getSystemPropertyOrEnvironmentVariable(JDK_HOME_FOR_TESTS)
|
||||
if (StringUtil.isEmpty(jdkHome) || !checkForJdk(jdkHome!!)) {
|
||||
//than use bundled JDK
|
||||
jdkHome = getBundledJdLocation()
|
||||
}
|
||||
if (StringUtil.isEmpty(jdkHome) || !checkForJdk(jdkHome!!)) {
|
||||
fail("Please specify the path to a valid JDK using system property " + JDK_HOME_FOR_TESTS)
|
||||
}
|
||||
return jdkHome!!
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.testGuiFramework.impl
|
||||
|
||||
import com.intellij.ide.GeneralSettings
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton
|
||||
import com.intellij.testGuiFramework.cellReader.ExtendedJListCellReader
|
||||
import com.intellij.testGuiFramework.cellReader.SettingsTreeCellReader
|
||||
import com.intellij.testGuiFramework.fixtures.*
|
||||
@@ -23,7 +24,9 @@ import com.intellij.testGuiFramework.fixtures.newProjectWizard.NewProjectWizardF
|
||||
import com.intellij.testGuiFramework.framework.GuiTestBase
|
||||
import com.intellij.testGuiFramework.framework.GuiTestUtil
|
||||
import com.intellij.testGuiFramework.framework.GuiTestUtil.waitUntilFound
|
||||
import com.intellij.ui.components.labels.LinkLabel
|
||||
import com.intellij.util.net.HttpConfigurable
|
||||
import org.fest.swing.core.ComponentMatcher
|
||||
import org.fest.swing.core.GenericTypeMatcher
|
||||
import org.fest.swing.core.SmartWaitRobot
|
||||
import org.fest.swing.exception.LocationUnavailableException
|
||||
@@ -46,7 +49,6 @@ open class GuiTestCase : GuiTestBase() {
|
||||
init {
|
||||
GeneralSettings.getInstance().isShowTipsOnStartup = false
|
||||
GuiTestUtil.setUpDefaultProjectCreationLocationPath()
|
||||
GuiTestUtil.setUpSdks()
|
||||
val ideSettings = HttpConfigurable.getInstance()
|
||||
ideSettings.USE_HTTP_PROXY = false
|
||||
ideSettings.PROXY_HOST = ""
|
||||
@@ -131,7 +133,7 @@ open class GuiTestCase : GuiTestBase() {
|
||||
else throw UnsupportedOperationException(
|
||||
"Sorry, unable to find RadioButton component by label \"${textLabel}\" with ${target().toString()} as a Container")
|
||||
|
||||
fun <S, C : Component> ComponentFixture<S, C>.textfield(textLabel: String): JTextComponentFixture = if (target() is Container) textfield(
|
||||
fun <S, C : Component> ComponentFixture<S, C>.textfield(textLabel: String?): JTextComponentFixture = if (target() is Container) textfield(
|
||||
target() as Container, textLabel)
|
||||
else throw UnsupportedOperationException(
|
||||
"Sorry, unable to find JTextComponent (JTextField) component by label \"${textLabel}\" with ${target().toString()} as a Container")
|
||||
@@ -146,12 +148,16 @@ open class GuiTestCase : GuiTestBase() {
|
||||
else throw UnsupportedOperationException(
|
||||
"Sorry, unable to find Popup component with ${target().toString()} as a Container")
|
||||
|
||||
fun <S, C : Component> ComponentFixture<S, C>.linkLabel(itemName: String) = if (target() is Container) linkLabel(
|
||||
target() as Container, itemName)
|
||||
else throw UnsupportedOperationException(
|
||||
"Sorry, unable to find LinkLabel component with ${target().toString()} as a Container")
|
||||
|
||||
|
||||
//*********COMMON FUNCTIONS WITHOUT CONTEXT
|
||||
fun typeText(text: String) = GuiTestUtil.typeText(text, myRobot, 10)
|
||||
fun shortcut(keyStroke: String) = GuiTestUtil.invokeActionViaShortcut(myRobot, keyStroke)
|
||||
|
||||
|
||||
fun ideFrame() = findIdeFrame()!!
|
||||
fun welcomeFrame() = findWelcomeFrame()
|
||||
fun dialog(title: String? = null): JDialogFixture {
|
||||
@@ -185,7 +191,7 @@ open class GuiTestCase : GuiTestBase() {
|
||||
|
||||
private fun button(container: Container, name: String): JButtonFixture {
|
||||
val jButton = GuiTestUtil.waitUntilFound(myRobot, container, object : GenericTypeMatcher<JButton>(JButton::class.java) {
|
||||
override fun isMatching(jButton: JButton): Boolean = (jButton.text == name)
|
||||
override fun isMatching(jButton: JButton): Boolean = (jButton.isShowing && jButton.text == name)
|
||||
})
|
||||
|
||||
return JButtonFixture(myRobot, jButton)
|
||||
@@ -194,7 +200,7 @@ open class GuiTestCase : GuiTestBase() {
|
||||
private fun combobox(container: Container, labelText: String): JComboBoxFixture {
|
||||
//wait until label has appeared
|
||||
GuiTestUtil.waitUntilFound(myRobot, container, object : GenericTypeMatcher<JLabel>(JLabel::class.java) {
|
||||
override fun isMatching(jLabel: JLabel): Boolean = (jLabel.text == labelText)
|
||||
override fun isMatching(jLabel: JLabel): Boolean = (jLabel.isShowing && jLabel.text == labelText)
|
||||
})
|
||||
|
||||
return GuiTestUtil.findComboBox(myRobot, container, labelText)
|
||||
@@ -203,7 +209,7 @@ open class GuiTestCase : GuiTestBase() {
|
||||
private fun checkbox(container: Container, labelText: String): CheckBoxFixture {
|
||||
//wait until label has appeared
|
||||
GuiTestUtil.waitUntilFound(myRobot, container, object : GenericTypeMatcher<JCheckBox>(JCheckBox::class.java) {
|
||||
override fun isMatching(checkBox: JCheckBox): Boolean = (checkBox.text == labelText)
|
||||
override fun isMatching(checkBox: JCheckBox): Boolean = (checkBox.isShowing && checkBox.text == labelText)
|
||||
})
|
||||
|
||||
return CheckBoxFixture.findByText(labelText, container, myRobot, false)
|
||||
@@ -215,11 +221,27 @@ open class GuiTestCase : GuiTestBase() {
|
||||
|
||||
private fun radioButton(container: Container, labelText: String) = GuiTestUtil.findRadioButton(myRobot, container, labelText)
|
||||
|
||||
private fun textfield(container: Container, labelText: String): JTextComponentFixture {
|
||||
GuiTestUtil.waitUntilFound(myRobot, container, object : GenericTypeMatcher<JLabel>(JLabel::class.java) {
|
||||
override fun isMatching(jLabel: JLabel): Boolean = (jLabel.text == labelText)
|
||||
private fun textfield(container: Container, labelText: String?): JTextComponentFixture {
|
||||
//if 'textfield()' goes without label
|
||||
if (labelText == null) {
|
||||
val jTextField = myRobot.finder().find(ComponentMatcher { component -> component!!.isShowing && component is JTextField }) as JTextField
|
||||
return JTextComponentFixture(myRobot, jTextField)
|
||||
}
|
||||
|
||||
val jLabel = GuiTestUtil.waitUntilFound(myRobot, container, object : GenericTypeMatcher<JLabel>(JLabel::class.java) {
|
||||
override fun isMatching(jLabel: JLabel): Boolean = (jLabel.isShowing && jLabel.text == labelText)
|
||||
})
|
||||
return JTextComponentFixture(myRobot, myRobot.finder().findByLabel(labelText, JTextComponent::class.java))
|
||||
if (jLabel.labelFor != null && jLabel.labelFor is TextFieldWithBrowseButton)
|
||||
return JTextComponentFixture(myRobot, (jLabel.labelFor as TextFieldWithBrowseButton).textField)
|
||||
else
|
||||
return JTextComponentFixture(myRobot, myRobot.finder().findByLabel(labelText, JTextComponent::class.java))
|
||||
}
|
||||
|
||||
private fun linkLabel(container: Container, labelText: String): ComponentFixture<ComponentFixture<*, *>, LinkLabel<*>> {
|
||||
val myLinkLabel = waitUntilFound(myRobot, container, object: GenericTypeMatcher<LinkLabel<*>>(LinkLabel::class.java) {
|
||||
override fun isMatching(someLinkLabel: LinkLabel<*>) = (someLinkLabel.isShowing && (someLinkLabel.text == labelText))
|
||||
})
|
||||
return ComponentFixture<ComponentFixture<*, *>, LinkLabel<*>>(ComponentFixture::class.java, myRobot, myLinkLabel)
|
||||
}
|
||||
|
||||
private fun popupClick(container: Container, itemName: String) {
|
||||
@@ -252,4 +274,6 @@ open class GuiTestCase : GuiTestBase() {
|
||||
return JTreeFixture(myRobot, myTree)
|
||||
}
|
||||
|
||||
//*********SOME EXTENSION FUNCTIONS FOR FIXTURES
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user