[gui-tests] Use labelFor for componentWithBrowseButton lookup

This commit is contained in:
Maxim.Kolmakov
2017-10-06 14:21:09 +02:00
parent 9128e51a86
commit 5cade9c1f2
2 changed files with 11 additions and 14 deletions
@@ -115,9 +115,9 @@ class ComponentWithBrowseButtonGenerator : ComponentCodeGenerator<FixedSizeButto
}
override fun generate(cmp: FixedSizeButton, me: MouseEvent, cp: Point): String {
var className = cmp.parent.parent.javaClass.simpleName
if (className.isEmpty()) className = cmp.parent.parent.javaClass.genericSuperclass.typeName
return "componentWithBrowseButton($className::class.java).clickButton()"
val componentWithBrowseButton= cmp.parent.parent
val labelText = Utils.getBoundedLabel(componentWithBrowseButton).text
return """componentWithBrowseButton("$labelText").clickButton()"""
}
}
@@ -244,21 +244,18 @@ open class GuiTestCase {
}
else throw UnableToFindComponent("""JButton named by $name""")
/**
* Finds a ComponentWithBrowseButton component in hierarchy of context component with a name and returns ComponentWithBrowseButtonFixture.
*
* @timeout in seconds to find ComponentWithBrowseButton component
* @throws ComponentLookupException if component has not been found or timeout exceeded
*/
fun <S, C : Component> ComponentFixture<S, C>.componentWithBrowseButton(comboboxClass: Class<out ComponentWithBrowseButton<out JComponent>>,
fun <S, C : Component> ComponentFixture<S, C>.componentWithBrowseButton(boundedLabelText: String,
timeout: Long = defaultTimeout): ComponentWithBrowseButtonFixture {
if (target() is Container) {
val component = waitUntilFound(target() as Container, ComponentWithBrowseButton::class.java, timeout) {
it.isShowing && comboboxClass.isInstance(it)
val boundedLabel = waitUntilFound(target() as Container, JLabel::class.java, timeout) {
it.text == boundedLabelText
}
val component = boundedLabel.labelFor
if (component is ComponentWithBrowseButton<*>) {
return ComponentWithBrowseButtonFixture(component, guiTestRule.robot())
}
return ComponentWithBrowseButtonFixture(component, guiTestRule.robot())
}
else throw UnableToFindComponent("ComponentWithBrowseButton")
throw UnableToFindComponent("ComponentWithBrowseButton with labelFor=$boundedLabelText")
}
fun <S, C : Component> ComponentFixture<S, C>.spinner(boundedLabelText: String, timeout: Long = defaultTimeout): JSpinnerFixture {