Jemmy FAQ


Why does my test stop during modal dialog appearance?

Q: When I use my JButtonOperator to push the "New" button, the application immediately displays the Dialog Box and it seems like my code looses process control until the Dialog box is closed. What can I do to prevent that?

A: You have to use "nonblocking" methods to get it working. Read more about it in the Jemmy Tutorial.

How can I change the matching criteria?

Q: I have a JList that has the items "LIGHT, POLE_SMALL, POLE_SMALL2, SMALL, SMALL2". When I try to select "SMALL", the item actually selected is "POLE_SMALL". How can I change the matching behavior?

A: The criteria for string comparison are defined in an Operator.StringComparator instance that is assigned to an operator.

How can I interact with an AWT Menu component?

Q: How can I interact with the an AWT Menu component? I can only find operators for the Swing JMenu component.

A: Jemmy does not have functionality to work with AWT menus because AWT menus are not Java components - they are implemented natively. The general problem is that it is impossible to find the menu item coordinates. It means that it is impossible to click on the component, and thus, to automate anything. The only way is to use keyboard shortcuts, or Alt key sequences (using [Alt], arrows and [Enter]).

What is the difference between the find... and the wait... methods?

Q: What is the difference between the find... and the wait... methods?

A: The find... methods immediately return a result if they cannot find a component that matches. The wait... methods wait until either a component is found that matches or a timeout expires and then throw the TimeoutExpiredException.

How does one get/know the index of a component?

Q: How does one get/know the index of a component? Am I supposed to get it from the source code of the Swing app I am testing? Do I need to use trial/error approach?

A: The most accurate way to get the index, would be to create a dump (by using Dumper class) and count the fields. This is the approach guaranteed to work.

Better is to use different constructors. But sometimes it also depends whether source code is written "correctly" by developers (it means to be testable). Let's say your dialog to be tested contains this two components (within others):

        JLabel myLabel = new JLabel("My label");
        JTextField myTextField = new JTextField();

If the label is connected to the text field (myLabel.setLabelFor (myTextField);), you can find it in test the following way:

    JDialogOperator contOper = new JDialogOperator("Dialog Title");
    JLabelOperator labelOper = new JLabelOperator(contOper, "My  label");
    JTextFieldOperator txtOper =
          new JTextFieldOperator((JTextField)labelOper.getLabelFor());

Or if the text field has a name set (myTextField.setName ("textFieldName");), you can use this:

    JTextFieldOperator txtOper1 = new JTextFieldOperator(
                      new NameComponentChooser("textFieldName"));

Or if the text field has some initial value, use this:

    JTextFieldOperator txtOper2 =
                    new JTextFieldOperator(contOper, "Initial text");
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo