Search in sources :

Example 6 with GenericTypeMatcher

use of org.fest.swing.core.GenericTypeMatcher in project ats-framework by Axway.

the class SwingElementLocator method getWindowFixture.

/**
     * Change window by specified name.
     * For internal use
     * @param driver Swing driver
     * @param windowTitle if null look for any visible window
     * @param isDialog
     * @return the {@link ContainerFinxture}
     */
public static WindowFixture<?> getWindowFixture(SwingDriverInternal driver, final String windowTitle, boolean isDialog) throws ElementNotFoundException {
    WindowFixture<?> windowFixture = driver.getWindowFixture();
    Robot robot = null;
    if (windowFixture != null) {
        // use the current robot instance
        robot = windowFixture.robot;
    } else {
        robot = BasicRobot.robotWithCurrentAwtHierarchy();
    }
    try {
        if (windowTitle != null) {
            if (isDialog) {
                windowFixture = WindowFinder.findDialog(new GenericTypeMatcher<Dialog>(Dialog.class) {

                    protected boolean isMatching(Dialog dialog) {
                        return windowTitle.equals(dialog.getTitle()) && dialog.isShowing();
                    }
                }).withTimeout(UiEngineConfigurator.getInstance().getElementStateChangeDelay()).using(robot);
            } else {
                windowFixture = WindowFinder.findFrame(new GenericTypeMatcher<Frame>(Frame.class) {

                    protected boolean isMatching(Frame frame) {
                        return windowTitle.equals(frame.getTitle()) && frame.isShowing();
                    }
                }).withTimeout(UiEngineConfigurator.getInstance().getElementStateChangeDelay()).using(robot);
            }
        } else {
            if (isDialog) {
                windowFixture = WindowFinder.findDialog(new GenericTypeMatcher<Dialog>(Dialog.class) {

                    protected boolean isMatching(Dialog dialog) {
                        return dialog.isShowing();
                    }
                }).withTimeout(UiEngineConfigurator.getInstance().getElementStateChangeDelay()).using(robot);
            } else {
                windowFixture = WindowFinder.findFrame(new GenericTypeMatcher<Frame>(Frame.class) {

                    protected boolean isMatching(Frame frame) {
                        if (log.isTraceEnabled()) {
                            log.trace("WindowFinder isMatching(): Title: " + frame.getTitle() + ", Frame + " + frame + ", Owner: " + frame.getOwner());
                        }
                        // owner == null - top frame. Two independent frames are both considered a top ones
                        return frame.isShowing() && frame.getOwner() == null;
                    }
                }).withTimeout(UiEngineConfigurator.getInstance().getElementStateChangeDelay()).using(robot);
            }
        }
        return windowFixture;
    } catch (WaitTimedOutError wtoe) {
        throw new ElementNotFoundException("Unable to find " + (isDialog ? "dialog" : "frame") + (windowTitle != null ? " with title '" + windowTitle + "'" : " without title specified (null passed)"), wtoe);
    }
}
Also used : Frame(java.awt.Frame) JInternalFrame(javax.swing.JInternalFrame) Dialog(java.awt.Dialog) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) WaitTimedOutError(org.fest.swing.exception.WaitTimedOutError) Robot(org.fest.swing.core.Robot) BasicRobot(org.fest.swing.core.BasicRobot) GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher)

Example 7 with GenericTypeMatcher

use of org.fest.swing.core.GenericTypeMatcher in project intellij-community by JetBrains.

the class JDialogFixture method find.

@NotNull
public static JDialogFixture find(@NotNull Robot robot, String title, Timeout timeout) {
    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 JDialogFixture with title \"" + title + "\"") {

        @Override
        public boolean test() {
            Collection<JDialog> dialogs = robot.finder().findAll(matcher);
            return !dialogs.isEmpty();
        }
    }, timeout);
    JDialog dialog = robot.finder().find(matcher);
    return new JDialogFixture(robot, dialog);
}
Also used : Condition(org.fest.swing.timing.Condition) Collection(java.util.Collection) GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with GenericTypeMatcher

use of org.fest.swing.core.GenericTypeMatcher in project intellij-community by JetBrains.

the class ActionButtonFixture method findByActionId.

@NotNull
public static ActionButtonFixture findByActionId(@NotNull final String actionId, @NotNull final Robot robot, @NotNull final Container container, Timeout timeout) {
    final Ref<ActionButton> actionButtonRef = new Ref<ActionButton>();
    Pause.pause(new Condition("Find ActionButton with ID '" + actionId + "'") {

        @Override
        public boolean test() {
            Collection<ActionButton> found = robot.finder().findAll(container, new GenericTypeMatcher<ActionButton>(ActionButton.class) {

                @Override
                protected boolean isMatching(@NotNull ActionButton button) {
                    if (button.isVisible()) {
                        AnAction action = button.getAction();
                        if (action != null) {
                            String id = ActionManager.getInstance().getId(action);
                            return actionId.equals(id);
                        }
                    }
                    return false;
                }
            });
            if (found.size() == 1) {
                actionButtonRef.set(getFirstItem(found));
                return true;
            }
            return false;
        }
    }, timeout);
    ActionButton button = actionButtonRef.get();
    if (button == null) {
        throw new ComponentLookupException("Failed to find ActionButton with ID '" + actionId + "'");
    }
    return new ActionButtonFixture(robot, button);
}
Also used : Condition(org.fest.swing.timing.Condition) Ref(com.intellij.openapi.util.Ref) ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton) Collection(java.util.Collection) ComponentLookupException(org.fest.swing.exception.ComponentLookupException) GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher) NotNull(org.jetbrains.annotations.NotNull) AnAction(com.intellij.openapi.actionSystem.AnAction) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with GenericTypeMatcher

use of org.fest.swing.core.GenericTypeMatcher in project android by JetBrains.

the class ThemeEditorTableTest method testStateListPicker.

/**
   * Test creating a new state list and setting it as a style attribute value with the state list picker.
   */
@Test
public void testStateListPicker() throws IOException {
    guiTest.importSimpleApplication();
    ThemeEditorFixture themeEditor = ThemeEditorGuiTestUtils.openThemeEditor(guiTest.ideFrame());
    ThemeEditorTableFixture themeEditorTable = themeEditor.getPropertiesTable();
    TableCell parentCell = row(0).column(0);
    JTableCellFixture parentCellFixture = themeEditorTable.cell(parentCell);
    // Selects AppCompat as parent
    Component parentEditor = parentCellFixture.editor();
    parentCellFixture.startEditing();
    JComboBoxFixture parentComboBox = new JComboBoxFixture(guiTest.robot(), guiTest.robot().finder().findByType((JComponent) parentEditor, JComboBox.class));
    parentComboBox.selectItem("Theme.AppCompat.NoActionBar");
    parentCellFixture.stopEditing();
    TableCell cell = row(8).column(0);
    FontFixture cellFont = themeEditorTable.fontAt(cell);
    cellFont.requireNotBold();
    assertEquals("android:textColorPrimary", themeEditorTable.attributeNameAt(cell));
    assertEquals("@android:color/primary_text_material_dark", themeEditorTable.valueAt(cell));
    JTableCellFixture stateListCell = themeEditorTable.cell(cell);
    ResourceComponentFixture resourceComponent = new ResourceComponentFixture(guiTest.robot(), (ResourceComponent) stateListCell.editor());
    stateListCell.startEditing();
    resourceComponent.getSwatchButton().click();
    final ChooseResourceDialogFixture dialog = ChooseResourceDialogFixture.find(guiTest.robot());
    StateListPickerFixture stateListPicker = dialog.getStateListPicker();
    List<StateListComponentFixture> states = stateListPicker.getStateComponents();
    assertThat(states).hasSize(2);
    final StateListComponentFixture state0 = states.get(0);
    assertEquals("Not enabled", state0.getStateName());
    assertEquals("@android:color/primary_text_default_material_dark", state0.getValue());
    assertTrue(state0.isAlphaVisible());
    assertEquals("@android:dimen/disabled_alpha_material_dark", state0.getAlphaValue());
    final StateListComponentFixture state1 = states.get(1);
    assertEquals("Default", state1.getStateName());
    assertEquals("@android:color/primary_text_default_material_dark", state1.getValue());
    assertFalse(state1.isAlphaVisible());
    state0.getValueComponent().getSwatchButton().click();
    ChooseResourceDialogFixture secondDialog = ChooseResourceDialogFixture.find(guiTest.robot(), new GenericTypeMatcher<JDialog>(JDialog.class) {

        @Override
        protected boolean isMatching(@NotNull JDialog component) {
            return !component.equals(dialog.target());
        }
    });
    secondDialog.getColorPicker().setColorWithIntegers(new Color(200, 0, 0, 200));
    secondDialog.clickOK();
    Wait.seconds(1).expecting("component update").until(() -> "@color/primary_text_default_material_dark".equals(state0.getValue()));
    state0.getAlphaComponent().getSwatchButton().click();
    secondDialog = ChooseResourceDialogFixture.find(guiTest.robot(), new GenericTypeMatcher<JDialog>(JDialog.class) {

        @Override
        protected boolean isMatching(@NotNull JDialog component) {
            return !component.equals(dialog.target());
        }
    });
    secondDialog.getResourceNameTable().cell("android:disabledAlpha").click();
    secondDialog.clickOK();
    Wait.seconds(1).expecting("component update").until(() -> "?android:attr/disabledAlpha".equals(state0.getAlphaValue()));
    state1.getValueComponent().getSwatchButton().click();
    secondDialog = ChooseResourceDialogFixture.find(guiTest.robot(), new GenericTypeMatcher<JDialog>(JDialog.class) {

        @Override
        protected boolean isMatching(@NotNull JDialog component) {
            return !component.equals(dialog.target());
        }
    });
    secondDialog.getColorPicker().setColorWithIntegers(new Color(0, 200, 0, 255));
    secondDialog.clickOK();
    Wait.seconds(1).expecting("component update").until(() -> "@color/primary_text_default_material_dark".equals(state1.getValue()));
    dialog.requireNoError();
    dialog.clickOK();
    stateListCell.stopEditing();
    cellFont = themeEditorTable.fontAt(cell);
    cellFont.requireBold();
    assertEquals("android:textColorPrimary", themeEditorTable.attributeNameAt(cell));
    assertEquals("@color/primary_text_material_dark", themeEditorTable.valueAt(cell));
}
Also used : GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher) NotNull(org.jetbrains.annotations.NotNull) TableCell(org.fest.swing.data.TableCell) ResourceComponent(com.android.tools.idea.editors.theme.ui.ResourceComponent) Test(org.junit.Test)

Aggregations

GenericTypeMatcher (org.fest.swing.core.GenericTypeMatcher)9 NotNull (org.jetbrains.annotations.NotNull)6 Condition (org.fest.swing.timing.Condition)5 Collection (java.util.Collection)4 Ref (com.intellij.openapi.util.Ref)3 ComponentLookupException (org.fest.swing.exception.ComponentLookupException)3 AnAction (com.intellij.openapi.actionSystem.AnAction)2 ActionLink (com.intellij.ui.components.labels.ActionLink)2 Component (java.awt.Component)2 JButton (javax.swing.JButton)2 JTextComponent (javax.swing.text.JTextComponent)2 BasicRobot (org.fest.swing.core.BasicRobot)2 Robot (org.fest.swing.core.Robot)2 ResourceComponent (com.android.tools.idea.editors.theme.ui.ResourceComponent)1 ElementNotFoundException (com.axway.ats.uiengine.exceptions.ElementNotFoundException)1 ActionButton (com.intellij.openapi.actionSystem.impl.ActionButton)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)1 AWTEvent (java.awt.AWTEvent)1