From 2eb2ed7b3b4d0a0d91ec86e9217817165436ceb2 Mon Sep 17 00:00:00 2001 From: Sergey Karashevich Date: Fri, 8 Jun 2018 16:12:29 +0300 Subject: [PATCH] [gui-test] fix GUI tests for focus issues Fix finding search window with SearchEverywhereUI panel --- .../tests/community/focus/FocusIssuesUtil.kt | 28 +++++++++++++ .../community/focus/GoToClassFocusTest.kt | 39 +++---------------- .../focus/GoToClassTwiceFocusTest.kt | 36 ++--------------- .../focus/SearchEverywhereFocusTest.kt | 36 +---------------- 4 files changed, 39 insertions(+), 100 deletions(-) create mode 100644 community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/FocusIssuesUtil.kt diff --git a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/FocusIssuesUtil.kt b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/FocusIssuesUtil.kt new file mode 100644 index 000000000000..4a78f2986657 --- /dev/null +++ b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/FocusIssuesUtil.kt @@ -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 + } +} \ No newline at end of file diff --git a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassFocusTest.kt b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassFocusTest.kt index a878a4d86f36..5ef558b73f18 100644 --- a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassFocusTest.kt +++ b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassFocusTest.kt @@ -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") - } } \ No newline at end of file diff --git a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassTwiceFocusTest.kt b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassTwiceFocusTest.kt index 375c4886c3a2..a729e64a04b0 100644 --- a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassTwiceFocusTest.kt +++ b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassTwiceFocusTest.kt @@ -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") - } - } \ No newline at end of file diff --git a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/SearchEverywhereFocusTest.kt b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/SearchEverywhereFocusTest.kt index 5d10489608e6..39ce8e321146 100644 --- a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/SearchEverywhereFocusTest.kt +++ b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/SearchEverywhereFocusTest.kt @@ -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") - } } \ No newline at end of file