[gui-test] fix GUI tests for focus issues

Fix finding search window with SearchEverywhereUI panel
This commit is contained in:
Sergey Karashevich
2018-06-08 16:22:20 +03:00
parent d3b626b4d9
commit 2eb2ed7b3b
4 changed files with 39 additions and 100 deletions
@@ -0,0 +1,28 @@
// 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.tests.community.focus
import com.intellij.ide.actions.searcheverywhere.SearchEverywhereUI
import com.intellij.testGuiFramework.impl.GuiRobotHolder
import com.intellij.ui.components.fields.ExtendableTextField
import org.fest.swing.exception.ComponentLookupException
import org.junit.Assert
import java.awt.Container
object FocusIssuesUtil {
fun checkSearchEverywhereUI(expectedString: String) {
val searchEverywhereUI = try {
findSearchEverywhereUI()
}
catch (cle: ComponentLookupException) {
GuiRobotHolder.robot.waitForIdle()
findSearchEverywhereUI()
}
val extendableTextField: ExtendableTextField = GuiRobotHolder.robot.finder().find(searchEverywhereUI) { it is ExtendableTextField } as ExtendableTextField
Assert.assertEquals(expectedString, extendableTextField.text)
}
private fun findSearchEverywhereUI(): Container {
return GuiRobotHolder.robot.finder().find { it is SearchEverywhereUI } as SearchEverywhereUI
}
}
@@ -4,22 +4,16 @@ package com.intellij.testGuiFramework.tests.community.focus
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.application.ApplicationManager
import com.intellij.testGuiFramework.fixtures.IdeFrameFixture
import com.intellij.testGuiFramework.framework.GuiTestUtil.defaultTimeout
import com.intellij.testGuiFramework.framework.GuiTestUtil.textfield
import com.intellij.testGuiFramework.impl.GuiRobotHolder
import com.intellij.testGuiFramework.impl.GuiTestCase
import com.intellij.testGuiFramework.impl.GuiTestUtilKt
import com.intellij.testGuiFramework.tests.community.CommunityProjectCreator
import com.intellij.testGuiFramework.tests.community.focus.FocusIssuesUtil.checkSearchEverywhereUI
import com.intellij.testGuiFramework.util.Key.ESCAPE
import org.fest.swing.core.SmartWaitRobot
import org.fest.swing.exception.ComponentLookupException
import org.fest.swing.timing.Pause
import org.junit.Assert
import org.junit.Test
import java.awt.Container
import java.awt.Window
import java.lang.Math.tan
import java.util.*
import javax.swing.JLabel
class GoToClassFocusTest : GuiTestCase() {
@@ -33,7 +27,7 @@ class GoToClassFocusTest : GuiTestCase() {
ideFrame {
focusOnEditor()
for (i in 0..10) {
openGoToClassSearchAndType(this@GoToClassFocusTest)
openGoToClassSearchAndType()
focusOnEditor()
}
}
@@ -69,36 +63,15 @@ class GoToClassFocusTest : GuiTestCase() {
}
}
private fun openGoToClassSearchAndType(guiTestCase: GuiTestCase) {
private fun openGoToClassSearchAndType() {
val smartRobot = guiTestCase.robot() as SmartWaitRobot
val smartRobot = GuiRobotHolder.robot as SmartWaitRobot
smartRobot.shortcutAndTypeString(actionKeyStroke, typedString, 100)
Pause.pause(500)
checkSearchWindow(guiTestCase)
checkSearchEverywhereUI(typedString)
shortcut(ESCAPE)
}
private fun checkSearchWindow(guiTestCase: GuiTestCase) {
val searchWindow = try {
findSearchWindow()
}
catch (cle: ComponentLookupException) {
guiTestCase.robot().waitForIdle()
findSearchWindow()
}
with(guiTestCase) {
val textfield = textfield("", searchWindow, defaultTimeout)
Assert.assertEquals(typedString, textfield.target().text)
}
}
private fun findSearchWindow(): Container {
fun checkWindowContainsEnterClassName(it: Window) = GuiTestUtilKt.findAllWithBFS(it,
JLabel::class.java).firstOrNull { it.text == "Enter class name:" } != null
return Window.getWindows()
.filterNotNull()
.firstOrNull { checkWindowContainsEnterClassName(it) } ?: throw ComponentLookupException(
"Unable to find GoToClass search window")
}
}
@@ -5,22 +5,17 @@ import com.intellij.openapi.actionSystem.ShortcutSet
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.keymap.KeymapUtil
import com.intellij.testGuiFramework.fixtures.IdeFrameFixture
import com.intellij.testGuiFramework.framework.GuiTestUtil.textfield
import com.intellij.testGuiFramework.framework.GuiTestUtil.defaultTimeout
import com.intellij.testGuiFramework.impl.*
import com.intellij.testGuiFramework.impl.GuiTestCase
import com.intellij.testGuiFramework.impl.LogActionsDuringTest
import com.intellij.testGuiFramework.impl.ScreenshotsDuringTest
import com.intellij.testGuiFramework.tests.community.CommunityProjectCreator
import com.intellij.testGuiFramework.util.Key.ESCAPE
import org.fest.swing.core.SmartWaitRobot
import org.fest.swing.exception.ComponentLookupException
import org.fest.swing.timing.Pause
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import java.awt.Container
import java.awt.Window
import java.lang.Math.tan
import java.util.*
import javax.swing.JLabel
import javax.swing.KeyStroke
class GoToClassTwiceFocusTest : GuiTestCase() {
@@ -87,31 +82,8 @@ class GoToClassTwiceFocusTest : GuiTestCase() {
smartRobot.shortcut(actionKeyStroke)
smartRobot.shortcutAndTypeString(actionKeyStroke, typedString, 100)
Pause.pause(500)
checkSearchWindow(guiTestCase)
FocusIssuesUtil.checkSearchEverywhereUI(typedString)
shortcut(ESCAPE)
}
private fun checkSearchWindow(guiTestCase: GuiTestCase) {
val searchWindow = try {
findSearchWindow()
}
catch (cle: ComponentLookupException) {
guiTestCase.robot().waitForIdle()
findSearchWindow()
}
with(guiTestCase) {
val textfield = textfield("", searchWindow, defaultTimeout)
Assert.assertEquals(typedString, textfield.target().text)
}
}
private fun findSearchWindow(): Container {
fun checkWindowContainsEnterClassName(it: Window) = GuiTestUtilKt.findAllWithBFS(it,
JLabel::class.java).firstOrNull { it.text == "Enter class name:" } != null
return Window.getWindows()
.filterNotNull()
.firstOrNull { checkWindowContainsEnterClassName(it) } ?: throw ComponentLookupException(
"Unable to find GoToClass search window")
}
}
@@ -2,27 +2,17 @@
package com.intellij.testGuiFramework.tests.community.focus
import com.intellij.testGuiFramework.fixtures.IdeFrameFixture
import com.intellij.testGuiFramework.framework.GuiTestUtil.textfield
import com.intellij.testGuiFramework.impl.GuiTestCase
import com.intellij.testGuiFramework.impl.GuiTestUtilKt
import com.intellij.testGuiFramework.framework.GuiTestUtil.defaultTimeout
import com.intellij.testGuiFramework.tests.community.CommunityProjectCreator
import com.intellij.testGuiFramework.util.Key.ESCAPE
import org.fest.swing.core.SmartWaitRobot
import org.fest.swing.exception.ComponentLookupException
import org.fest.swing.timing.Pause
import org.junit.Assert
import org.junit.Test
import java.awt.Container
import java.awt.Window
import java.awt.event.InputEvent
import javax.swing.JLabel
class SearchEverywhereFocusTest : GuiTestCase() {
private val typedString = "here is a demo text"
private val expectedText = typedString
private val searchWindowLabelText = "Search Everywhere:"
@Test
fun testSearchEverywhereFocus() {
@@ -33,7 +23,7 @@ class SearchEverywhereFocusTest : GuiTestCase() {
doubleShift(50)
fastType(typedString)
Pause.pause(500)
checkTextInSearchWindow(findSearchWindowTwice(), expectedText)
FocusIssuesUtil.checkSearchEverywhereUI(typedString)
shortcut(ESCAPE)
focusOnEditor()
}
@@ -54,30 +44,6 @@ class SearchEverywhereFocusTest : GuiTestCase() {
smartRobot.fastTyping(stringToType)
}
private fun GuiTestCase.checkTextInSearchWindow(searchWindow: Container, expectedText: String) {
with(this) {
val textfield = textfield("", searchWindow, defaultTimeout)
Assert.assertEquals(expectedText, textfield.target().text)
}
}
private fun findSearchWindowTwice() : Container {
return try {
findSearchWindow(searchWindowLabelText)
}
catch (cle: ComponentLookupException) {
this.robot().waitForIdle()
findSearchWindow(searchWindowLabelText)
}
}
private fun findSearchWindow(labelText: String): Container {
fun checkWindowContainsEnterClassName(it: Window) = GuiTestUtilKt.findAllWithBFS(it,
JLabel::class.java).firstOrNull { it.text?.contains(labelText) == true } != null
return Window.getWindows()
.filterNotNull()
.firstOrNull { checkWindowContainsEnterClassName(it) } ?: throw ComponentLookupException(
"Unable to find search window")
}
}