From e96a2b5ae53edcf0f6ec7d993d3738bbf7ee5af8 Mon Sep 17 00:00:00 2001 From: Sergey Karashevich Date: Thu, 10 Aug 2017 14:11:27 +0300 Subject: [PATCH] [gui-test] add expand() method to ComboBoxFixture --- .../fixtures/ComboBoxFixture.kt | 32 +++++++++++++++++++ .../testGuiFramework/impl/GuiTestCase.kt | 9 +++--- 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/ComboBoxFixture.kt diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/ComboBoxFixture.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/ComboBoxFixture.kt new file mode 100644 index 000000000000..11b51e7e5698 --- /dev/null +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/ComboBoxFixture.kt @@ -0,0 +1,32 @@ +/* + * 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.fixtures + +import org.fest.swing.core.Robot +import org.fest.swing.exception.ComponentLookupException +import org.fest.swing.fixture.JComboBoxFixture +import javax.swing.JButton +import javax.swing.JComboBox + +class ComboBoxFixture(robot: Robot, comboBox: JComboBox<*>) : JComboBoxFixture(robot, comboBox) { + + fun expand(): ComboBoxFixture { + val arrowButton = target().components.filter { it is JButton }.firstOrNull() ?: throw ComponentLookupException("Unable to find bounded arrow button for a combobox") + robot().click(arrowButton) + return this + } + +} \ No newline at end of file diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCase.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCase.kt index 0085f7edac30..f1b74a34011a 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCase.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCase.kt @@ -47,7 +47,6 @@ import org.fest.swing.timing.Condition import org.fest.swing.timing.Pause import org.fest.swing.timing.Timeout import org.fest.swing.timing.Timeout.timeout -import org.junit.After import java.awt.Component import java.awt.Container import java.io.File @@ -244,13 +243,13 @@ open class GuiTestCase : GuiTestBase() { /** - * Finds a JComboBox component in hierarchy of context component by text of label and returns JComboBoxFixture. + * Finds a JComboBox component in hierarchy of context component by text of label and returns ComboBoxFixture. * * @timeout in seconds to find JComboBox component * @throws ComponentLookupException if component has not been found or timeout exceeded */ fun ComponentFixture.combobox(labelText: String, - timeout: Long = defaultTimeout): JComboBoxFixture = if (target() is Container) combobox( + timeout: Long = defaultTimeout): ComboBoxFixture = if (target() is Container) combobox( target() as Container, labelText, timeout) else throw UnsupportedOperationException( "Sorry, unable to find JComboBox component near label by \"${labelText}\" with ${target().toString()} as a Container") @@ -519,7 +518,7 @@ open class GuiTestCase : GuiTestBase() { return ComponentWithBrowseButtonFixture(component, myRobot) } - private fun combobox(container: Container, text: String, timeout: Long): JComboBoxFixture { + private fun combobox(container: Container, text: String, timeout: Long): ComboBoxFixture { //wait until label has appeared waitUntilFound(container, Component::class.java, timeout) { component -> @@ -529,7 +528,7 @@ open class GuiTestCase : GuiTestBase() { && component.getComponentText() == text } val comboBox = findBoundedComponentByText(myRobot, container, text, JComboBox::class.java) - val comboboxFixture = JComboBoxFixture(myRobot, comboBox) + val comboboxFixture = ComboBoxFixture(myRobot, comboBox) comboboxFixture.replaceCellReader(ExtendedJComboboxCellReader()) return comboboxFixture }