From 8df6b9fae0e6ee66f437f5d254d59d85699cbe4d Mon Sep 17 00:00:00 2001 From: Sergey Karashevich Date: Mon, 12 Sep 2016 12:59:30 +0300 Subject: [PATCH] gui-tests-framework: added fast AdvancedRobot; DialogFixture and other UI providers become safer --- .../tests/gui/fixtures/DialogFixture.java | 19 ++++- .../tests/gui/framework/GuiTestCase.java | 13 ++- .../tests/gui/framework/GuiTests.java | 14 +++- .../com/intellij/tests/gui/test/GitGuiTest.kt | 2 - .../tests/gui/test/JavaEEProjectTest.java | 1 + .../tests/gui/test/JavaGitGuiTest.java | 3 +- .../org/fest/swing/core/AdvancedRobot.java | 79 +++++++++++++++++++ 7 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 community-tests/src/org/fest/swing/core/AdvancedRobot.java diff --git a/community-tests/src/com/intellij/tests/gui/fixtures/DialogFixture.java b/community-tests/src/com/intellij/tests/gui/fixtures/DialogFixture.java index 5579654712e2..8fe51769c4ff 100644 --- a/community-tests/src/com/intellij/tests/gui/fixtures/DialogFixture.java +++ b/community-tests/src/com/intellij/tests/gui/fixtures/DialogFixture.java @@ -15,13 +15,16 @@ */ package com.intellij.tests.gui.fixtures; -import com.intellij.openapi.project.ProjectBundle; +import com.intellij.tests.gui.framework.GuiTests; import org.fest.swing.core.GenericTypeMatcher; import org.fest.swing.core.Robot; import org.fest.swing.fixture.ContainerFixture; +import org.fest.swing.timing.Condition; +import org.fest.swing.timing.Pause; import org.jetbrains.annotations.NotNull; import javax.swing.*; +import java.util.Collection; /** * Created by jetbrains on 22/08/16. @@ -38,12 +41,22 @@ public class DialogFixture implements ContainerFixture { @NotNull public static DialogFixture find(@NotNull Robot robot, String title) { - JDialog dialog = robot.finder().find(new GenericTypeMatcher(JDialog.class) { + GenericTypeMatcher matcher = new GenericTypeMatcher(JDialog.class) { @Override protected boolean isMatching(@NotNull JDialog dialog) { return title.equals(dialog.getTitle()) && dialog.isShowing(); } - }); + }; + + Pause.pause(new Condition("Finding for DialogFixture with title \"" + title + "\"") { + @Override + public boolean test() { + Collection dialogs = robot.finder().findAll(matcher); + return !dialogs.isEmpty(); + } + }, GuiTests.SHORT_TIMEOUT); + + JDialog dialog = robot.finder().find(matcher); return new DialogFixture(robot, dialog); } diff --git a/community-tests/src/com/intellij/tests/gui/framework/GuiTestCase.java b/community-tests/src/com/intellij/tests/gui/framework/GuiTestCase.java index 25f89ff6996e..157b686299f7 100644 --- a/community-tests/src/com/intellij/tests/gui/framework/GuiTestCase.java +++ b/community-tests/src/com/intellij/tests/gui/framework/GuiTestCase.java @@ -37,7 +37,7 @@ import com.intellij.tests.gui.fixtures.IdeFrameFixture; import com.intellij.tests.gui.fixtures.WelcomeFrameFixture; import com.intellij.tests.gui.fixtures.newProjectWizard.NewProjectWizardFixture; import com.intellij.util.net.HttpConfigurable; -import org.fest.swing.core.BasicRobot; +import org.fest.swing.core.AdvancedRobot; import org.fest.swing.core.Robot; import org.fest.swing.edt.GuiQuery; import org.fest.swing.edt.GuiTask; @@ -68,7 +68,6 @@ import static junit.framework.Assert.assertNotNull; import static org.fest.swing.edt.GuiActionRunner.execute; import static org.fest.swing.timing.Pause.pause; import static org.fest.util.Strings.quote; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -99,8 +98,9 @@ public abstract class GuiTestCase { assertNotNull(application); // verify that we are using the IDE's ClassLoader. setUpDefaultProjectCreationLocationPath(); - myRobot = BasicRobot.robotWithCurrentAwtHierarchy(); - myRobot.settings().delayBetweenEvents(30); + //myRobot = BasicRobot.robotWithCurrentAwtHierarchy(); + myRobot = new AdvancedRobot(); + //myRobot.settings().delayBetweenEvents(30); setIdeSettings(); setUpSdks(); @@ -321,6 +321,11 @@ public abstract class GuiTestCase { return projectPath; } + private void updateLocalProperties(File path) { + + + } + @NotNull protected File copyProjectBeforeOpening(@NotNull String projectDirName) throws IOException { File masterProjectPath = getMasterProjectDirPath(projectDirName); diff --git a/community-tests/src/com/intellij/tests/gui/framework/GuiTests.java b/community-tests/src/com/intellij/tests/gui/framework/GuiTests.java index 5acb7063f385..db69c81ee4f6 100644 --- a/community-tests/src/com/intellij/tests/gui/framework/GuiTests.java +++ b/community-tests/src/com/intellij/tests/gui/framework/GuiTests.java @@ -682,7 +682,7 @@ public final class GuiTests { @NotNull public static JButton findButton(@NotNull ContainerFixture container, @NotNull final String text, Robot robot) { - return robot.finder().find(container.target(), new GenericTypeMatcher(JButton.class) { + GenericTypeMatcher matcher = new GenericTypeMatcher(JButton.class) { @Override protected boolean isMatching(@NotNull JButton button) { String buttonText = button.getText(); @@ -691,7 +691,17 @@ public final class GuiTests { } return false; } - }); + }; + + pause(new Condition("Finding for a button with text \"" + text + "\"") { + @Override + public boolean test() { + Collection buttons = robot.finder().findAll(matcher); + return !buttons.isEmpty(); + } + }, SHORT_TIMEOUT); + + return robot.finder().find(container.target(), matcher); } /** Returns a full path to the GUI data directory in the user's AOSP source tree, if known, or null */ diff --git a/community-tests/src/com/intellij/tests/gui/test/GitGuiTest.kt b/community-tests/src/com/intellij/tests/gui/test/GitGuiTest.kt index 71c4208bb215..e448bdec34ae 100644 --- a/community-tests/src/com/intellij/tests/gui/test/GitGuiTest.kt +++ b/community-tests/src/com/intellij/tests/gui/test/GitGuiTest.kt @@ -17,7 +17,6 @@ package com.intellij.tests.gui.test import com.intellij.dvcs.ui.CloneDvcsDialog import com.intellij.dvcs.ui.DvcsBundle -import com.intellij.ide.IdeBundle import com.intellij.openapi.project.DumbService import com.intellij.openapi.vcs.VcsBundle import com.intellij.tests.gui.BelongsToTestGroups @@ -69,7 +68,6 @@ class GitGuiTest : GuiTestCase() { GuiTests.findAndClickButton(this, "Next") //libraries GuiTests.findAndClickButton(this, "Next") //module dependencies GuiTests.findAndClickButton(this, "Next") //select sdk - MessagesFixture.findByTitle(myRobot, this.target(), IdeBundle.message("title.no.jdk.specified")).clickOk() GuiTests.findAndClickButton(this, "Finish") } val ideFrame = findIdeFrame() diff --git a/community-tests/src/com/intellij/tests/gui/test/JavaEEProjectTest.java b/community-tests/src/com/intellij/tests/gui/test/JavaEEProjectTest.java index 1fc7040a3221..7751aa4afe23 100644 --- a/community-tests/src/com/intellij/tests/gui/test/JavaEEProjectTest.java +++ b/community-tests/src/com/intellij/tests/gui/test/JavaEEProjectTest.java @@ -70,6 +70,7 @@ public class JavaEEProjectTest extends GuiTestCase { newProjectWizard.clickFinish(); myProjectFrame = findIdeFrame(projectName, locationInFileSystem); + myProjectFrame.waitForBackgroundTasksToFinish(); final ProjectViewFixture projectView = myProjectFrame.getProjectView(); final ProjectViewFixture.PaneFixture paneFixture = projectView.selectProjectPane(); diff --git a/community-tests/src/com/intellij/tests/gui/test/JavaGitGuiTest.java b/community-tests/src/com/intellij/tests/gui/test/JavaGitGuiTest.java index e5e78e17bc20..71e869d3679d 100644 --- a/community-tests/src/com/intellij/tests/gui/test/JavaGitGuiTest.java +++ b/community-tests/src/com/intellij/tests/gui/test/JavaGitGuiTest.java @@ -21,10 +21,10 @@ import com.intellij.ide.IdeBundle; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.tests.gui.fixtures.*; import com.intellij.tests.gui.framework.GuiTestCase; -import com.intellij.tests.gui.framework.GuiTests; import com.intellij.ui.EditorComboBox; import org.fest.swing.edt.GuiActionRunner; import org.fest.swing.edt.GuiTask; +import org.junit.Ignore; import org.junit.Test; import static com.intellij.tests.gui.framework.GuiTests.findAndClickButton; @@ -34,6 +34,7 @@ import static com.intellij.tests.gui.framework.GuiTests.findAndClickButton; */ public class JavaGitGuiTest extends GuiTestCase { + @Ignore @Test public void testGitImport(){ String gitPath = "https://github.com/karashevich/test.git"; diff --git a/community-tests/src/org/fest/swing/core/AdvancedRobot.java b/community-tests/src/org/fest/swing/core/AdvancedRobot.java new file mode 100644 index 000000000000..512a07b95068 --- /dev/null +++ b/community-tests/src/org/fest/swing/core/AdvancedRobot.java @@ -0,0 +1,79 @@ +/* + * Copyright 2000-2016 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 org.fest.swing.core; + +import org.fest.swing.hierarchy.ComponentHierarchy; +import org.fest.swing.hierarchy.ExistingHierarchy; +import org.fest.swing.timing.Pause; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Created by jetbrains on 09/09/16. + */ +public class AdvancedRobot extends BasicRobot { + + public AdvancedRobot(){ + super((Object)null, new ExistingHierarchy()); + } + + AdvancedRobot(@Nullable Object screenLockOwner, + @Nonnull ComponentHierarchy hierarchy) { + super(screenLockOwner, hierarchy); + } + + volatile boolean isIdle = false; + + @Override + public void waitForIdle() { + //do not wait for idle + + //if (!myKeyboardBusy && myKeyEventDispatcher.isReady()) return; + // + //isIdle = false; + // + //this.waitIfNecessary(); + //IdeEventQueue.getInstance().doWhenReady(new Runnable() { + // @Override + // public void run() { + // isIdle = true; + // } + //}); + // + //assert !EventQueue.isDispatchThread(); + //Pause.pause(new Condition("Waiting for idle...") { + // @Override + // public boolean test() { + // return isIdle; + // } + //}, 120000L); + } + + private void waitIfNecessary() { + + int delayBetweenEvents = settings().delayBetweenEvents(); + int eventPostingDelay = settings().eventPostingDelay(); + if(eventPostingDelay > delayBetweenEvents) { + Pause.pause((long)(eventPostingDelay - delayBetweenEvents)); + } + + } + + + + +}