Skip to main content

Jemmy lookup principles

The document describes principles of Jemmy lookup API. Such principles are the same for any extension built on JemmyCore for any particular component library. The idea here is to provide searching capabilities so that

  • Any possible criteria could be used

  • Any number or criteria could be used consequently

  • Access both to control instance and a wrapper instance is provided

  • No casting needed

Search criteria

Search criteria specified by implementing LookupCriteria interface. There are several implementations of the criteria in JemmyCore which are abstract. Naturally, any kind of custom search criteria could be specified my creating an implementation if the interface.


        public class ByTextSearch<T extends JTextComponent> implements LookupCriteria<T> {
            String text;
            public ByTextSearch(String text) {
                this.text = text;
            public boolean check(T control) {
                return control.getText().equals(text);

Search functionality


Parent interface represents the start point for a component lookup. Parent could be a

  • root of control hierarchy (Stage or Scene in JavaFX, Frame in AWT)

  • A container in the middle (such as Container in AWT)

from the lookup perspective, parent only is able to get an access to a Lookup instance.


The search capabilities are presented by Lookup interface. Most importantly the interface defines methods to narrow the search with another search criteria and optionally control type, which (the methods) return an instance on the same interface. That allows to implement any number of search criteria.


        button = ... .wrap(0);
        lookup(JTextField.class, new TrueLookup<JTextField>()).

Besides that, the interface defines methods to get the control, to wrap it, to get the number of controls found, etc. .


This is an internal yet very important class. It implements creating the sub-lookups. This particular implementation does it in a way that the actual component hierarchy is not requested up until the moment it has to be. It's only when there is a question on the actual control list is asked, the hierarchy is explored.

Example. This does not query the AWT hierarchy:

        import org.jemmy.awt.FrameOperator;
        FrameOperator frame = ...
        Lookup<JTextField> lookup = frame.lookup(JTextField.class, new TrueLookup<JTextField>());

These do:


AbstractLookup does not implement the functionality of getting the control list, which is implemented by next two classes:

HierarchyLookup and PlainLookup

As it is clear from the names, the classes provide logic to deal with hierarchical control structure and plain control list, correspondentelly. Doing so, the implementation rely on two other interfaces which specific to the component library: ControlHierarchy and ControlList.

Accessing/wrapping the controls

Two methods get(int) and wrap(int) return the control itself and the wrapper of it. The type of the returned control is the CONTROL type parameter of Lookup<CONTROL> interface. Control type is Wrap<CONTROL>, hence there is no need to cast the results to get the control itself. There is no need to cost the wrapper either, but this is described in a separate document: Jemmy control interfaces

Please Confirm