Skip to main content
Welcome to JemmyFX

JemmyFX Getting Started Guide

 


September, 2012

This document provides basic information about JemmyFX and helps you get started with testing your application's UI.

Contents

 

What is JemmyFX

JemmyFX provides an API for testing JavaFX user interface in your application. JemmyFX provides unique UI testing capabilities and high test stability.

For more information refer to JemmyFX Website.

System Requirements

The following is required to install and use JemmyFX:

  • JavaFX 2.2
  • JDK 6 or later
  • Apache Ant
  • Mercurial client
  • IDE of your choice
  • Test framework (JUnit, TestNG, JTHarness)

Downloading and Installing JemmyFX

JemmyFX is developed as an open-source project. You can download the source files from the Mercurial repository and build JemmyFX using Ant command. Perform the following steps to download and build JemmyFX:

  1. Using a Mercurial client, clone JemmyTest repository to your local folder from http://hg.openjdk.java.net/openjfx/2.2/master/tests/
  2. Once the files are copied from the JemmyTest repository, navigate to tools\Jemmy\JemmyFX folder in the JemmyTest repository using a command-line tool.
  3. Run the following Ant command to build JemmyFX:
    ant jar

    For example:
    C:\JemmyTests\tools\Jemmy\JemmyFX>ant jar
    This command creates JemmyCore.jar file in the dist folder under JemmyFX.

    Note: When the Ant command builds JemmyCore.jar, it downloads several necessary JemmyCore libraries from the Web. If Ant cannot get the libraries automatically, download them manually from the following location:
    http://jemmy.java.net/dist/<jemmy.core.version>
    Where <jemmy.core.version> is specified in tools/Jemmy/JemmyFX/depend.properties file.

    For example:
    http://jemmy.java.net/dist/20120709

    Copy downloaded files to tools/Jemmy/JemmyFX/lib/jemmy folder and run the Ant command to build JemmyCore.jar.
  4. To build Javadoc, run ant javadoc in the JemmyFX folder. This command will generate javadoc and create JemmyFX.zip file in the dist folder. To see JemmyFX javadoc, add JemmyFX.zip to your IDE.
  5. To build JemmyFX Browser, navigate to tools\Jemmy\JemmyFXBrowser in the JemmyTest repository on your computer and run ant jar.

Note: Refer to JemmyFX Readme for further details.

Getting Started With JemmyFX

This is how to start using JemmyFX.

JemmyFX Browser

JemmyFX Browser provides detailed information about UI elements hierarchy in your application. It is a good practice to run your application with enabled JemmyFX Browser before creating tests for your UI.

JemmyFX Browser

Using JemmyFX to Test Your Application

The following section provides details about JemmySample, which is one of the available sample testing projects. You can download JemmySample at the following location:

http://hg.openjdk.java.net/openjfx/2.2/master/tests/

The JemmySample testing example consists of two projects created in NetBeans: Explorer and Tests. The Explorer project is a simple file explorer application created as a JavaFX project. The Tests project is created as a Java project and consists of ExplorerTest and BrowserLauncher classes. When you run BrowserLauncher, it starts JemmyFX browser together with the Explorer application. ExplorerTest contains code for testing the UI of the Explorer application. You will learn how to use JemmyFX API to test some UI elements in the application.

Creating a Test Project

Note: You can skip the following steps by just unzipping the entire JemmySample project with preserved paths and opening the projects in your IDE.

To test the UI of the Explorer application, perform the following steps:

  1. Unzip the Explorer project from the JemmySample zip file. Adjust this project to your working environment. Make sure the Explorer.java class of the Explorer project resides in the org.jemmy.samples.explorer source package (src\org\jemmy\samples\explorer).
  2. Create a new Tests Java project and add Jemmy libraries and jfxrt.jar library to the project.
    1. In the Tests project, create BrowserLauncher.java in the org.jemmy.samples.explorer source package (src\org\jemmy\samples\explorer) and paste the following code in the file:
      package org.jemmy.samples.explorer;
      
      import java.awt.AWTException;
      import org.jemmy.fx.AppExecutor;
      import org.jemmy.fx.Browser;
      
      
      public class BrowserLauncher {
          public static void main(String[] args) throws AWTException {
              AppExecutor.executeNoBlock(Explorer.class);
              Browser.runBrowser();
          }
      }
      This code starts JemmyFX Browser together with the Explorer application when you run the BrowserLauncher.java.
    2. Create a new ExplorerTest.java in the org.jemmy.samples.explorer test package under test\org\jemmy\samples\explorer and paste the following code in the file:
      package org.jemmy.samples.explorer;
      
      
      import java.io.File;
      import org.jemmy.control.Wrap;
      import org.jemmy.fx.AppExecutor;
      import org.jemmy.fx.SceneDock;
      import org.jemmy.fx.control.ComboBoxDock;
      import org.jemmy.fx.control.LabeledDock;
      import org.jemmy.fx.control.ListItemDock;
      import org.jemmy.fx.control.ListViewDock;
      import org.jemmy.fx.control.TextInputControlDock;
      import org.jemmy.lookup.LookupCriteria;
      import org.junit.After;
      import org.junit.AfterClass;
      import org.junit.Before;
      import org.junit.BeforeClass;
      import org.junit.Test;
      import static org.junit.Assert.*;
      import static org.jemmy.interfaces.Keyboard.KeyboardButtons.*;
      import static org.jemmy.resources.StringComparePolicy.*;
      
      
      public class ExplorerTest {
      
          @BeforeClass
          public static void setUpClass() {
              AppExecutor.executeNoBlock(Explorer.class);
          }
      
          @Test
          public void hello() {
      
              SceneDock scene = new SceneDock();
              
      
              ListViewDock list = new ListViewDock(scene.asParent());
              
      
              final TextInputControlDock address = new TextInputControlDock(scene.asParent());
              String location = address.getText();
      
              address.asSelectionText().to(address.getText().length());
              address.type(File.separator + "test_data");
              address.keyboard().pushKey(ENTER);
      
      
              new ListItemDock(list.asList(), new LookupCriteria() {
      
                  @Override
                  public boolean check(Object cntrl) {
                      return cntrl.toString().endsWith("folder1");
                  }
              }).mouse().click(2);
      
              new ComboBoxDock(scene.asParent()).asSelectable().selector().
                      select(new File(location));
      
              address.wrap().waitProperty(Wrap.TEXT_PROP_NAME, location);
      
              new LabeledDock(scene.asParent(), "back_btn").mouse().click();
      
              new ListItemDock(list.asList(), "file.txt", SUBSTRING).mouse().click(1);
          }
      }
      
  3. If you are creating this project from scratch, in the Tests project folder create test_data/folder1 subfolder and place an empty file.txt file in it.

Now you are ready to test the UI in the Explorer application.

  • To explore the UI of the Explorer application, run BrowserLauncher.java that will start the Explorer application together with JemmyFX Browser.
  • To perform the test of the UI, run ExplorerTest.java.

In the next section we will explore the test code of ExplorerTest.java.

Exploring Test Code

This section provides details about the test code that is used to test the UI elements of the Explorer application. The test code in the sample application is located in the ExplorerTest.java file.

  1. When you start creating a test code for your application, first you need to find the necessary scene. Because Explorer application contains one scene, there is no need to provide any lookup criteria as in the following code:
     SceneDock scene = new SceneDock();
  2. Next step is to find a list element within the scene:
     ListViewDock list = new ListViewDock(scene.asParent());
  3. Then, the test finds the text field (there is only one in the application) and saves the original location to return to it later:
     final TextInputControlDock address = new TextInputControlDock(scene.asParent());
    String location = address.getText();
  4. After finding the text field location, the cursor goes to the end of the path, adds /test_data/folder1 to the path, and emulates pressing Enter.
    address.asSelectionText().to(address.getText().length());
    address.type(File.separator + "test_data");
    address.keyboard().pushKey(ENTER);
  5. Then, we check the existence of the folder1 item in the drop-down list and a text file in the folder.
    new ListItemDock(list.asList(), new LookupCriteria() {
         @Override
         public boolean check(Object cntrl) {
            return cntrl.toString().endsWith("folder1");
        }
    }).mouse().click(2);
  6. In the next cycle the test goes several levels up to the original location that we saved in one of the previous steps:
    new ComboBoxDock(scene.asParent()).asSelectable().selector().
            select(new File(location));
    Check that we got to the original location by inspecting the location field
    address.wrap().waitProperty(Wrap.TEXT_PROP_NAME, location);
  7. In this step we find the Back button by its ID, click the button, which gets back to the folder1 folder.
    new LabeledDock(scene.asParent(), "back_btn").mouse().click();
  8. In the final step, the test locates the file.txt file in the file list and selects it by emulating a mouse click.
    new ListItemDock(list.asList(), "file.txt", SUBSTRING).mouse().click(1);
    

 


Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

 
 
Close
loading
Please Confirm
Close