Search in sources :

Example 6 with ComponentLookupException

use of org.fest.swing.exception.ComponentLookupException in project ats-framework by Axway.

the class SwingElementLocator method findFixture.

public static ComponentFixture<? extends Component> findFixture(UiElement uiElement) {
    SwingDriverInternal driver = (SwingDriverInternal) uiElement.getUiDriver();
    ContainerFixture<?> containerFixture = (ContainerFixture<?>) driver.getActiveContainerFixture();
    Class<? extends Component> componentClass = componentsMap.get(uiElement.getClass());
    try {
        if (componentClass.equals(JButton.class)) {
            return (ComponentFixture<? extends Component>) new JButtonFixture(containerFixture.robot, (JButton) findElement(uiElement));
        } else if (componentClass.equals(JTextComponent.class)) {
            return (ComponentFixture<? extends Component>) new JTextComponentFixture(containerFixture.robot, (JTextComponent) findElement(uiElement));
        } else if (componentClass.equals(JMenuItem.class)) {
            if (uiElement.getElementProperty("path") != null) {
                return containerFixture.menuItemWithPath(uiElement.getElementProperty("path").split("[\\,\\/]+"));
            } else {
                return (ComponentFixture<? extends Component>) new JMenuItemFixture(containerFixture.robot, (JMenuItem) findElement(uiElement));
            }
        } else if (componentClass.equals(JPopupMenu.class)) {
            return (ComponentFixture<? extends Component>) new JPopupMenuFixture(containerFixture.robot, (JPopupMenu) findElement(uiElement));
        } else if (componentClass.equals(JTree.class)) {
            return (ComponentFixture<? extends Component>) new JTreeFixture(containerFixture.robot, (JTree) findElement(uiElement));
        } else if (componentClass.equals(JList.class)) {
            return (ComponentFixture<? extends Component>) new JListFixture(containerFixture.robot, (JList) findElement(uiElement));
        } else if (componentClass.equals(JCheckBox.class)) {
            return (ComponentFixture<? extends Component>) new JCheckBoxFixture(containerFixture.robot, (JCheckBox) findElement(uiElement));
        } else if (componentClass.equals(JToggleButton.class)) {
            return (ComponentFixture<? extends Component>) new JToggleButtonFixture(containerFixture.robot, (JToggleButton) findElement(uiElement));
        } else if (componentClass.equals(JComboBox.class)) {
            return (ComponentFixture<? extends Component>) new JComboBoxFixture(containerFixture.robot, (JComboBox) findElement(uiElement));
        } else if (componentClass.equals(JRadioButton.class)) {
            return (ComponentFixture<? extends Component>) new JRadioButtonFixture(containerFixture.robot, (JRadioButton) findElement(uiElement));
        } else if (componentClass.equals(JTable.class)) {
            return (ComponentFixture<? extends Component>) new JTableFixture(containerFixture.robot, (JTable) findElement(uiElement));
        } else if (componentClass.equals(JSpinner.class)) {
            return (ComponentFixture<? extends Component>) new JSpinnerFixture(containerFixture.robot, (JSpinner) findElement(uiElement));
        } else if (componentClass.equals(JTabbedPane.class)) {
            return (ComponentFixture<? extends Component>) new JTabbedPaneFixture(containerFixture.robot, (JTabbedPane) findElement(uiElement));
        } else if (componentClass.equals(JOptionPane.class)) {
            return (ComponentFixture<? extends Component>) containerFixture.optionPane();
        } else if (componentClass.equals(JLabel.class)) {
            return (ComponentFixture<? extends Component>) new JLabelFixture(containerFixture.robot, (JLabel) findElement(uiElement));
        } else if (componentClass.equals(Component.class)) {
            return new ComponentFixture<Component>(containerFixture.robot, findElement(uiElement)) {
            };
        } else if (componentClass.equals(JFileChooser.class)) {
            // TODO - might be searched by name too
            return containerFixture.fileChooser(Timeout.timeout(UiEngineConfigurator.getInstance().getElementStateChangeDelay()));
        } else {
            throw new ElementNotFoundException(uiElement.toString() + " not found. No such Fixture");
        }
    } catch (ComponentLookupException cle) {
        throw new ElementNotFoundException(uiElement.toString() + " not found.", cle);
    } catch (WaitTimedOutError exc) {
        // thrown for OptionPane search, wait for Window (BasicRobot.waitForWindow), AbstractJTableCellWriter, JTreeDriver.waitForChildrenToShowUp, each Pause wait
        throw new ElementNotFoundException(uiElement.toString() + " not found.", exc);
    }
}
Also used : JTreeFixture(org.fest.swing.fixture.JTreeFixture) JRadioButton(javax.swing.JRadioButton) SwingDriverInternal(com.axway.ats.uiengine.internal.driver.SwingDriverInternal) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) JTextComponent(javax.swing.text.JTextComponent) JSpinnerFixture(org.fest.swing.fixture.JSpinnerFixture) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) ComponentLookupException(org.fest.swing.exception.ComponentLookupException) WaitTimedOutError(org.fest.swing.exception.WaitTimedOutError) JLabelFixture(org.fest.swing.fixture.JLabelFixture) JTabbedPaneFixture(org.fest.swing.fixture.JTabbedPaneFixture) JButtonFixture(org.fest.swing.fixture.JButtonFixture) JToggleButtonFixture(org.fest.swing.fixture.JToggleButtonFixture) JComboBoxFixture(org.fest.swing.fixture.JComboBoxFixture) JTableFixture(org.fest.swing.fixture.JTableFixture) JToggleButton(javax.swing.JToggleButton) JTextComponentFixture(org.fest.swing.fixture.JTextComponentFixture) ComponentFixture(org.fest.swing.fixture.ComponentFixture) JMenuItemFixture(org.fest.swing.fixture.JMenuItemFixture) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent) JMenuItem(javax.swing.JMenuItem) JTextComponentFixture(org.fest.swing.fixture.JTextComponentFixture) JRadioButtonFixture(org.fest.swing.fixture.JRadioButtonFixture) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) JOptionPane(javax.swing.JOptionPane) JPopupMenu(javax.swing.JPopupMenu) JCheckBox(javax.swing.JCheckBox) JTree(javax.swing.JTree) JPopupMenuFixture(org.fest.swing.fixture.JPopupMenuFixture) JListFixture(org.fest.swing.fixture.JListFixture) ContainerFixture(org.fest.swing.fixture.ContainerFixture) JTable(javax.swing.JTable) JSpinner(javax.swing.JSpinner) JCheckBoxFixture(org.fest.swing.fixture.JCheckBoxFixture) JList(javax.swing.JList)

Example 7 with ComponentLookupException

use of org.fest.swing.exception.ComponentLookupException in project intellij-community by JetBrains.

the class NewProjectWizardFixture method setProjectName.

@NotNull
public NewProjectWizardFixture setProjectName(@NotNull String projectName) {
    String labelText = GuiTestUtil.adduction(IdeBundle.message("label.project.name"));
    pause(new Condition("Waiting for the sliding to project name settings") {

        @Override
        public boolean test() {
            final Component label;
            try {
                label = robot().finder().findByLabel(labelText);
            } catch (ComponentLookupException componentLookupException) {
                return false;
            }
            return true;
        }
    }, GuiTestUtil.SHORT_TIMEOUT);
    final JTextComponentFixture textField = findTextField(labelText);
    robot().click(textField.target());
    textField.setText(projectName);
    return this;
}
Also used : Condition(org.fest.swing.timing.Condition) ComponentLookupException(org.fest.swing.exception.ComponentLookupException) JTextComponentFixture(org.fest.swing.fixture.JTextComponentFixture) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ComponentLookupException

use of org.fest.swing.exception.ComponentLookupException 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 ComponentLookupException

use of org.fest.swing.exception.ComponentLookupException in project android by JetBrains.

the class HprofEditorFixture method findByFileName.

@NotNull
public static HprofEditorFixture findByFileName(@NotNull Robot robot, @NotNull final IdeFrameFixture frame, @NotNull final String hprofFileName) {
    HprofEditor hprofEditor = GuiQuery.getNonNull(() -> {
        FileEditor[] openEditors = null;
        FileEditorManagerImpl fileEditorManager = (FileEditorManagerImpl) FileEditorManager.getInstance(frame.getProject());
        for (EditorsSplitters splitters : fileEditorManager.getAllSplitters()) {
            for (EditorWindow window : splitters.getWindows()) {
                for (EditorWithProviderComposite editorWithProviderComposite : window.getEditors()) {
                    if (editorWithProviderComposite.getFile().getName().endsWith(hprofFileName)) {
                        if (openEditors != null) {
                            throw new ComponentLookupException(String.format("More than one Hprof editor for file '%s' found", hprofFileName));
                        }
                        openEditors = editorWithProviderComposite.getEditors();
                    }
                }
            }
        }
        if (openEditors == null) {
            throw new ComponentLookupException(String.format("Cannot find any open Hprof editors for file '%s'", hprofFileName));
        }
        HprofEditor targetEditor = null;
        for (FileEditor editor : openEditors) {
            if (editor instanceof HprofEditor) {
                if (targetEditor != null) {
                    throw new ComponentLookupException(String.format("More than one Hprof editor pane for file '%s' found", hprofFileName));
                } else {
                    targetEditor = (HprofEditor) editor;
                }
            }
        }
        return targetEditor;
    });
    return new HprofEditorFixture(robot, frame, hprofEditor);
}
Also used : EditorWithProviderComposite(com.intellij.openapi.fileEditor.impl.EditorWithProviderComposite) HprofEditor(com.android.tools.idea.editors.hprof.HprofEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) EditorsSplitters(com.intellij.openapi.fileEditor.impl.EditorsSplitters) FileEditorManagerImpl(com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl) ComponentLookupException(org.fest.swing.exception.ComponentLookupException) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with ComponentLookupException

use of org.fest.swing.exception.ComponentLookupException in project android by JetBrains.

the class ActionLinkFixture method findByActionId.

@NotNull
public static ActionLinkFixture findByActionId(@NotNull final String actionId, @NotNull final Robot robot, @NotNull final Container container) {
    final Ref<ActionLink> actionLinkRef = new Ref<>();
    Wait.seconds(1).expecting("ActionLink with ID '" + actionId + "' to be visible").until(() -> {
        Collection<ActionLink> found = robot.finder().findAll(container, new GenericTypeMatcher<ActionLink>(ActionLink.class) {

            @Override
            protected boolean isMatching(@NotNull ActionLink actionLink) {
                if (actionLink.isVisible()) {
                    AnAction action = actionLink.getAction();
                    String id = ActionManager.getInstance().getId(action);
                    return actionId.equals(id);
                }
                return false;
            }
        });
        if (found.size() == 1) {
            actionLinkRef.set(getFirstItem(found));
            return true;
        }
        return false;
    });
    ActionLink actionLink = actionLinkRef.get();
    if (actionLink == null) {
        throw new ComponentLookupException("Failed to find ActionLink with ID '" + actionId + "'");
    }
    return new ActionLinkFixture(robot, actionLink);
}
Also used : Ref(com.intellij.openapi.util.Ref) ComponentLookupException(org.fest.swing.exception.ComponentLookupException) AnAction(com.intellij.openapi.actionSystem.AnAction) ActionLink(com.intellij.ui.components.labels.ActionLink) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ComponentLookupException (org.fest.swing.exception.ComponentLookupException)10 NotNull (org.jetbrains.annotations.NotNull)7 Ref (com.intellij.openapi.util.Ref)5 AnAction (com.intellij.openapi.actionSystem.AnAction)4 Condition (org.fest.swing.timing.Condition)4 ActionLink (com.intellij.ui.components.labels.ActionLink)3 Collection (java.util.Collection)3 GenericTypeMatcher (org.fest.swing.core.GenericTypeMatcher)3 ElementNotFoundException (com.axway.ats.uiengine.exceptions.ElementNotFoundException)2 SwingDriverInternal (com.axway.ats.uiengine.internal.driver.SwingDriverInternal)2 ActionButton (com.intellij.openapi.actionSystem.impl.ActionButton)2 JTextComponent (javax.swing.text.JTextComponent)2 JTextComponentFixture (org.fest.swing.fixture.JTextComponentFixture)2 HprofEditor (com.android.tools.idea.editors.hprof.HprofEditor)1 MoreThanOneSuchElementException (com.axway.ats.uiengine.exceptions.MoreThanOneSuchElementException)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 EditorWindow (com.intellij.openapi.fileEditor.impl.EditorWindow)1 EditorWithProviderComposite (com.intellij.openapi.fileEditor.impl.EditorWithProviderComposite)1 EditorsSplitters (com.intellij.openapi.fileEditor.impl.EditorsSplitters)1 FileEditorManagerImpl (com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl)1