gui-tests-framework: added fast AdvancedRobot; DialogFixture and other UI providers become safer

This commit is contained in:
Sergey Karashevich
2016-10-09 17:59:25 +03:00
parent d35d8d1ec9
commit 8df6b9fae0
7 changed files with 119 additions and 12 deletions
@@ -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<JDialog> {
@NotNull
public static DialogFixture find(@NotNull Robot robot, String title) {
JDialog dialog = robot.finder().find(new GenericTypeMatcher<JDialog>(JDialog.class) {
GenericTypeMatcher<JDialog> matcher = new GenericTypeMatcher<JDialog>(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<JDialog> dialogs = robot.finder().findAll(matcher);
return !dialogs.isEmpty();
}
}, GuiTests.SHORT_TIMEOUT);
JDialog dialog = robot.finder().find(matcher);
return new DialogFixture(robot, dialog);
}
@@ -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);
@@ -682,7 +682,7 @@ public final class GuiTests {
@NotNull
public static JButton findButton(@NotNull ContainerFixture<? extends Container> container, @NotNull final String text, Robot robot) {
return robot.finder().find(container.target(), new GenericTypeMatcher<JButton>(JButton.class) {
GenericTypeMatcher<JButton> matcher = new GenericTypeMatcher<JButton>(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<JButton> 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 */
@@ -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()
@@ -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();
@@ -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";
@@ -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));
}
}
}