Java Code Examples for org.netbeans.jemmy.Waiter#setOutput()

The following examples show how to use org.netbeans.jemmy.Waiter#setOutput() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertySheetOperator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Waits for property sheet anywhere in IDE. First it tries to find TopComponent
 * representing global properties and if not found, it tries to find 
 * property sheet in all dialogs owned by Main Window or other frames.
 * @param sheetName name of property sheet
 * @param index index of property sheet 
 */
private static JComponent waitPropertySheet(final String sheetName, final int index) {
    try {
        Waiter waiter = new Waiter(new Waitable() {
            public Object actionProduced(Object obj) {
                return findPropertySheet(sheetName, index);
            }
            public String getDescription() {
                return("Wait PropertySheet with name="+sheetName+
                       " index="+index+" loaded");
            }
        });
        Timeouts times = JemmyProperties.getCurrentTimeouts().cloneThis();
        times.setTimeout("Waiter.WaitingTime", times.getTimeout("ComponentOperator.WaitComponentTimeout"));
        waiter.setTimeouts(times);
        waiter.setOutput(JemmyProperties.getCurrentOutput());
        return (JComponent)waiter.waitAction(null);
    } catch(InterruptedException e) {
        throw new JemmyException("Interrupted.", e);
    }
}
 
Example 2
Source File: WidgetOperator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Waits for index-th widget specified by WidgetChooser under given parent
 * widget.
 *
 * @param parentWidget parent Widget
 * @param widgetChooser WidgetChooser implementation
 * @param index index to be found
 * @return Widget instance if found or throws JemmyException if not found.
 */
private static Widget waitWidget(final Widget parentWidget, final WidgetChooser widgetChooser, final int index) {
    try {
        Waiter waiter = new Waiter(new Waitable() {

            @Override
            public Object actionProduced(Object obj) {
                return findWidget(parentWidget, widgetChooser, index);
            }

            @Override
            public String getDescription() {
                return (index > 0 ? index + "-th " : "")
                        + (widgetChooser == null ? "Widget " : widgetChooser.getDescription())
                        + " displayed";
            }
        });
        Timeouts timeouts = JemmyProperties.getCurrentTimeouts().cloneThis();
        timeouts.setTimeout("Waiter.WaitingTime", timeouts.getTimeout("WidgetOperator.WaitWidgetTimeout"));
        waiter.setTimeouts(timeouts);
        waiter.setOutput(JemmyProperties.getCurrentOutput());
        return (Widget) waiter.waitAction(null);
    } catch (InterruptedException ex) {
        throw new JemmyException("Interrupted.", ex);
    }
}
 
Example 3
Source File: ComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Waits for this Component has the keyboard focus.
 *
 * @throws TimeoutExpiredException
 */
public void waitHasFocus() {
    Waiter<String, Void> focusWaiter = new Waiter<>(new Waitable<String, Void>() {
        @Override
        public String actionProduced(Void obj) {
            return hasFocus() ? "" : null;
        }

        @Override
        public String getDescription() {
            return "Wait component has focus";
        }

        @Override
        public String toString() {
            return "ComponentOperator.waitHasFocus.Waitable{description = " + getDescription() + '}';
        }
    });
    focusWaiter.setTimeoutsToCloneOf(timeouts, "ComponentOperator.WaitFocusTimeout");
    focusWaiter.setOutput(output.createErrorOutput());
    try {
        focusWaiter.waitAction(null);
    } catch (InterruptedException e) {
        output.printStackTrace(e);
    }
}
 
Example 4
Source File: GeneralNodeJs.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void waitForNavigator() {
    long defaultTimeout = JemmyProperties.getCurrentTimeout("ComponentOperator.WaitComponentEnabledTimeout");

    try {
        JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentEnabledTimeout", 300000);
        NavigatorOperator nav = new NavigatorOperator();
        Waiter waiter = new Waiter(new Waitable() {
            @Override
            public Object actionProduced(Object obj) {
                int rowCount = ((NavigatorOperator) obj).getTree().getRowCount();
                if (rowCount > 1) {
                    return true;
                } else {
                    return (null);
                }
            }

            @Override
            public String getDescription() {
                return "Navigator populated: ";
            }
        });
        waiter.setOutput(nav.getOutput());
        waiter.setTimeoutsToCloneOf(nav.getTimeouts(), "ComponentOperator.WaitComponentEnabledTimeout");
        waiter.waitAction(nav);

        JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentEnabledTimeout", defaultTimeout);
    } catch (InterruptedException ex) {
        JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentEnabledTimeout", defaultTimeout);
        Exceptions.printStackTrace(ex);
    }
}
 
Example 5
Source File: TopComponentOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Waits for index-th TopComponent with given name in IDE registry.
 * It throws JemmyException when TopComponent is not find until timeout
 * expires.
 * @param cont container where to search
 * @param name name of TopComponent
 * @param index index of TopComponent
 * @param subchooser ComponentChooser to determine exact TopComponent
 * @return TopComponent instance or throws JemmyException if not found
 * @see #findTopComponent
 */
protected static JComponent waitTopComponent(final ContainerOperator cont, final String name, final int index, final ComponentChooser subchooser) {
    try {
        Waiter waiter = new Waiter(new Waitable() {

            @Override
            public Object actionProduced(Object obj) {
                return findTopComponent(cont, name, index, subchooser);
            }

            @Override
            public String getDescription() {
                return ("Wait TopComponent with name=" + name
                        + " index=" + String.valueOf(index)
                        + (subchooser == null ? "" : " subchooser=" + subchooser.getDescription())
                        + " loaded");
            }
        });
        Timeouts times = JemmyProperties.getCurrentTimeouts().cloneThis();
        times.setTimeout("Waiter.WaitingTime", times.getTimeout("ComponentOperator.WaitComponentTimeout"));
        waiter.setTimeouts(times);
        waiter.setOutput(JemmyProperties.getCurrentOutput());
        return ((JComponent) waiter.waitAction(null));
    } catch (InterruptedException e) {
        return (null);
    }
}
 
Example 6
Source File: DefaultJMenuDriver.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected JMenuItem waitItem(ComponentOperator oper, MenuElement element, PathChooser chooser, int depth) {
    Waiter<MenuElement, Void> waiter = new Waiter<>(new JMenuItemWaiter(element, chooser, depth));
    waiter.setOutput(oper.getOutput().createErrorOutput());
    waiter.setTimeouts(oper.getTimeouts());
    try {
        return (JMenuItem) waiter.waitAction(null);
    } catch (InterruptedException e) {
        throw (new JemmyException("Waiting has been interrupted", e));
    }
}
 
Example 7
Source File: QueueJMenuDriver.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private JMenuItem runAction(final OneReleaseAction action, ComponentOperator env, long waitingTime, final String description) {
    Waiter<MenuElement, Void> waiter = new Waiter<>(new Waitable<MenuElement, Void>() {
        @Override
        public MenuElement actionProduced(Void param) {
            return queueTool.invokeSmoothly(action);
        }

        @Override
        public String getDescription() {
            return description;
        }

        @Override
        public String toString() {
            return "runAction.Waiter{description = " + getDescription() + '}';
        }
    });
    waiter.setOutput(env.getOutput().createErrorOutput());
    waiter.setTimeouts(env.getTimeouts().cloneThis());
    waiter.getTimeouts().setTimeout("Waiter.WaitingTime",
            waitingTime);
    waiter.getTimeouts().setTimeout("Waiter.TimeDelta", 100);
    //1.5 workaround
    if (System.getProperty("java.specification.version").compareTo("1.4") > 0) {
        queueTool.setOutput(env.getOutput().createErrorOutput());
        queueTool.waitEmpty(10);
        queueTool.waitEmpty(10);
        queueTool.waitEmpty(10);
    }
    //end of 1.5 workaround
    try {
        return (JMenuItem) waiter.waitAction(null);
    } catch (InterruptedException e) {
        action.stop();
        throw (new JemmyException("Waiting has been interrupted", e));
    }
}
 
Example 8
Source File: ComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A method to be used from subclasses. Uses timeouts and output passed as
 * parameters during the waiting.
 *
 * @param cont Container to search component in.
 * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
 * @param index Ordinal component index.
 * @param timeouts timeouts to be used during the waiting.
 * @param output an output to be used during the waiting.
 * @return Component instance or null if component was not found.
 * @throws TimeoutExpiredException
 */
protected static Component waitComponent(final Container cont,
        final ComponentChooser chooser,
        final int index,
        Timeouts timeouts, final TestOut output) {
    try {
        Waiter<Component, Void> waiter = new Waiter<>(new Waitable<Component, Void>() {
            @Override
            public Component actionProduced(Void obj) {
                return findComponent(cont, new VisibleComponentFinder(chooser), index,
                        output.createErrorOutput());
            }

            @Override
            public String getDescription() {
                return "Wait " + chooser.getDescription() + " loaded";
            }

            @Override
            public String toString() {
                return "ComponentOperator.waitComponent.Waitable{description = " + getDescription() + '}';
            }
        });
        waiter.setTimeoutsToCloneOf(timeouts, "ComponentOperator.WaitComponentTimeout");
        waiter.setOutput(output);
        return waiter.waitAction(null);
    } catch (InterruptedException e) {
        return null;
    }
}
 
Example 9
Source File: ComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Waits for the component to be enabled.
 *
 * @throws TimeoutExpiredException
 * @throws InterruptedException
 */
public void waitComponentEnabled() throws InterruptedException {
    Waiter<Component, Component> waiter = new Waiter<>(new Waitable<Component, Component>() {
        @Override
        public Component actionProduced(Component obj) {
            if (obj.isEnabled()) {
                return obj;
            } else {
                return null;
            }
        }

        @Override
        public String getDescription() {
            return ("Component enabled: "
                    + getSource().getClass().toString());
        }

        @Override
        public String toString() {
            return "ComponentOperator.waitComponentEnabled.Waitable{description = " + getDescription() + '}';
        }
    });
    waiter.setOutput(output);
    waiter.setTimeoutsToCloneOf(timeouts, "ComponentOperator.WaitComponentEnabledTimeout");
    waiter.waitAction(getSource());
}
 
Example 10
Source File: JTreeOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the root of the tree.
 *
 * @return tree root.
 * @throws TimeoutExpiredException
 */
public Object getRoot() {
    Waiter<Object, Void> rootWaiter = new Waiter<>(new Waitable<Object, Void>() {
        @Override
        public Object actionProduced(Void obj) {
            Object root = getModel().getRoot();
            if (root == null || root.toString().equals("null")) {
                return null;
            } else {
                return root;
            }
        }

        @Override
        public String getDescription() {
            return "Wait root node";
        }

        @Override
        public String toString() {
            return "JTreeOperator.getRoot.Waitable{description = " + getDescription() + '}';
        }
    });
    rootWaiter.setTimeoutsToCloneOf(timeouts, "JTreeOperator.WaitNodeVisibleTimeout");
    rootWaiter.setOutput(output.createErrorOutput());
    try {
        return rootWaiter.waitAction(null);
    } catch (InterruptedException e) {
        output.printStackTrace(e);
        return null;
    }
}
 
Example 11
Source File: ContainerOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Waits for a subcomponent.
 *
 * @param chooser a chooser specifying searching criteria.
 * @param index Ordinal component index.
 * @return Component instance.
 */
public Component waitSubComponent(final ComponentChooser chooser, final int index) {
    getOutput().printLine("Waiting for \"" + chooser.getDescription()
            + "\" subcomponent");
    final ComponentSearcher searcher = new ComponentSearcher((Container) getSource());
    searcher.setOutput(getOutput().createErrorOutput());
    Waiter<Component, Void> waiter = new Waiter<>(new Waitable<Component, Void>() {
        @Override
        public Component actionProduced(Void obj) {
            return searcher.findComponent(chooser, index);
        }

        @Override
        public String getDescription() {
            return ("Wait for \"" + chooser.getDescription()
                    + "\" subcomponent to be displayed");
        }

        @Override
        public String toString() {
            return "ContainerOperator.waitSubComponent.Waitable{description = " + getDescription() + '}';
        }
    });
    waiter.setTimeoutsToCloneOf(getTimeouts(), "ComponentOperator.WaitComponentTimeout");
    waiter.setOutput(getOutput());
    try {
        return waiter.waitAction(null);
    } catch (InterruptedException e) {
        throw (new JemmyException("Waiting for \"" + chooser.getDescription()
                + "\" component has been interrupted", e));
    }
}
 
Example 12
Source File: JFileChooserOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private int findFileIndex(final String file, final StringComparator comparator) {
    Waiter<Integer, Void> fileWaiter = new Waiter<>(new Waitable<Integer, Void>() {
        @Override
        public Integer actionProduced(Void obj) {
            File[] files = getFiles();
            for (int i = 0; i < files.length; i++) {
                if (comparator.equals(files[i].getName(),
                        file)) {
                    return i;
                }
            }
            return null;
        }

        @Override
        public String getDescription() {
            return "\"" + file + "\" file to be displayed";
        }

        @Override
        public String toString() {
            return "JFileChooserOperator.findFileIndex.Waitable{description = " + getDescription() + '}';
        }
    });
    fileWaiter.setOutput(getOutput().createErrorOutput());
    fileWaiter.setTimeoutsToCloneOf(getTimeouts(), "JFileChooserOperator.WaitListPaintedTimeout");
    try {
        return fileWaiter.waitAction(null);
    } catch (InterruptedException e) {
        throw (new JemmyException("Waiting has been interrupted!"));
    }
}
 
Example 13
Source File: JProgressBarOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Waits for criteria defined by {@code chooser} to be reached.
 *
 * @param chooser an object specifying waiting criteria.
 * @see #waitValue(int)
 * @deprecated Use waitState(ComponentChooser) instead.
 */
@Deprecated
public void waitValue(final ValueChooser chooser) {
    output.printLine("Wait \"" + chooser.getDescription()
            + "\" value in progressbar\n    : "
            + toStringSource());
    output.printGolden("Wait \"" + chooser.getDescription()
            + "\" value in progressbar");
    Waiter<String, Void> wt = new Waiter<>(new Waitable<String, Void>() {
        @Override
        public String actionProduced(Void obj) {
            return (chooser.checkValue(((JProgressBar) getSource()).getValue())
                    ? "" : null);
        }

        @Override
        public String getDescription() {
            return "\"" + chooser.getDescription() + "\" value";
        }

        @Override
        public String toString() {
            return "JProgressBarOperator.waitValue.Waitable{description = " + getDescription() + '}';
        }
    });
    wt.setTimeoutsToCloneOf(timeouts, "JProgressBarOperator.WaitValueTimeout");
    wt.setOutput(output.createErrorOutput());
    try {
        wt.waitAction(null);
    } catch (InterruptedException e) {
        throw (new JemmyException("Exception during progressbar value waiting", e));
    }
}
 
Example 14
Source File: Operator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Waits a state specified by a ComponentChooser instance.
 *
 * @param state a ComponentChooser defining the state criteria.
 * @throws TimeoutExpiredException if the state has not achieved in a value
 * defined by {@code "ComponentOperator.WaitStateTimeout"}
 */
public void waitState(final ComponentChooser state) {
    Waiter<String, Void> stateWaiter = new Waiter<>(new Waitable<String, Void>() {
        @Override
        public String actionProduced(Void obj) {
            return state.checkComponent(getSource()) ? "" : null;
        }

        @Override
        public String getDescription() {
            return "Wait \"" + state.getDescription()
                    + "\" state to be reached";
        }

        @Override
        public String toString() {
            return "Operator.waitState.Waitable{description = " + getDescription() + '}';
        }
    });
    stateWaiter.setTimeoutsToCloneOf(getTimeouts(), "ComponentOperator.WaitStateTimeout");
    stateWaiter.setOutput(getOutput().createErrorOutput());
    try {
        stateWaiter.waitAction(null);
    } catch (InterruptedException e) {
        throw (new JemmyException("Waiting of \"" + state.getDescription()
                + "\" state has been interrupted!"));
    }
}
 
Example 15
Source File: JTreeOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches path in tree.
 *
 * @param chooser TreePathChooser implementation.
 * @return a path fitting the criteria.
 * @see TreePathChooser
 * @see #findPath
 * @throws TimeoutExpiredException
 */
public TreePath findPath(TreePathChooser chooser) {
    output.printLine("Search for a tree path " + chooser.getDescription());
    output.printGolden("Search for a tree path");
    TreePath rootPath = new TreePath(getRoot());
    if (chooser.checkPath(rootPath, 0)) {
        return rootPath;
    }
    Waiter<Object[], Object[]> loadedWaiter = new Waiter<>(new Waitable<Object[], Object[]>() {
        // fields used in getDescription() method
        TreePath currentPath;
        String requestedPath;

        @Override
        public Object[] actionProduced(Object[] obj) {
            TreePathChooser chsr = (TreePathChooser) obj[0];
            requestedPath = chsr.getDescription();
            TreePath path = (TreePath) obj[1];
            currentPath = path;
            Object[] result = new Object[2];
            Object[] children = getChildren(path.getLastPathComponent());
            for (int j = 0; j < children.length; j++) {
                result[0] = path.pathByAddingChild(children[j]);
                if (chsr.checkPath((TreePath) result[0], j)) {
                    result[1] = Boolean.TRUE;
                    return result;
                }
                if (chsr.hasAsParent((TreePath) result[0], j)) {
                    result[1] = Boolean.FALSE;
                    return result;
                }
            }
            return null;
        }

        @Override
        public String getDescription() {
            return "Wait next node loaded under parent " + currentPath + " when requested was " + requestedPath;
        }

        @Override
        public String toString() {
            return "JTreeOperator.findPath.Waitable{description = " + getDescription() + '}';
        }
    });
    loadedWaiter.setTimeoutsToCloneOf(timeouts, "JTreeOperator.WaitNextNodeTimeout");
    loadedWaiter.setOutput(output.createErrorOutput());
    return findPathPrimitive(rootPath, chooser, loadedWaiter);
}