[gui-test] add expand() method to ComboBoxFixture

This commit is contained in:
Sergey Karashevich
2017-08-10 14:18:19 +03:00
parent d5744660a1
commit e96a2b5ae5
2 changed files with 36 additions and 5 deletions
@@ -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
}
}
@@ -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 <S, C : Component> ComponentFixture<S, C>.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
}