Write a Java test

Write a simple test scenario, compile it, and execute it.

Before you begin:
  1. Begin by running the Genero Ghost Client ggcgen tool to generate a scenario from a log file.
    ggcgen java --package-name test2scenario --check-form myapp_test2.guilog 
    The myapp_test2_provider.java file is created in the package named "test2scenario".
    Note:

    If you do not specify a package name, the GGC creates the package name "scenario" by default.

    The user actions recorded from the log are generated for the test. The --check-form option in the command adds tests for the app's form names and titles:
    /*
     * Generated using Genero Ghost Client 4.00.04-202201201755
     */
    package test2scenario;
    
    import com.fourjs.ggc.ScenarioProvider;
    import com.fourjs.ggc.Scenario;
    import com.fourjs.ggc.Client;
    import com.fourjs.ggc.generator.ScenarioChecks;
    import java.util.concurrent.ConcurrentLinkedDeque;
    import com.fourjs.ggc.DependencyHandler;
    
    public class myapp_test2_provider implements ScenarioProvider
    {
      private final ConcurrentLinkedDeque<Scenario> scenarios;
      DependencyHandler dh = null;
    
      /*  */
      /* Instance initializer */
      public myapp_test2_provider()
      {
        scenarios = new ConcurrentLinkedDeque<>();
    
        /* Register scenario functions */
        scenarios.add(new scenario_0());
    
      }
    
      /* Scenario myapp_test2 id: 0 */
      private class scenario_0 implements Scenario
      {
        @Override
        public void play(Client client)
        {
          ScenarioChecks.checkFormName(client, "price");
          ScenarioChecks.checkFormTitle(client, "Product and prices");
          client.wait(70);
          client.sortTable("sr_prices", "price".equals("null") ? null : "price", com.fourjs.ggc.auitree.SortType.get("desc"));
    
          ScenarioChecks.checkFormName(client, "price");
          ScenarioChecks.checkFormTitle(client, "Product and prices");
          client.wait(88);
          client.setTableSize("sr_prices", 12);
    
          ScenarioChecks.checkFormName(client, "price");
          ScenarioChecks.checkFormTitle(client, "Product and prices");
          client.wait(63);
          client.action("sr_prices.edit"); /* sr_prices.edit */
    
          ScenarioChecks.checkFormName(client, "edit_price");
          ScenarioChecks.checkFormTitle(client, "Edit product price");
          client.wait(89);
          client.setFocus("formonly.price");
    
          client.setValue("$25.00");
    
          client.action("accept"); /* OK */
    
          ScenarioChecks.checkFormName(client, "price");
          ScenarioChecks.checkFormTitle(client, "Product and prices");
          client.wait(81);
          client.action("cancel"); /* Exit */
        }
      }
    
      @Override
      public Scenario nextScenario()
      {
        return scenarios.removeFirst();
      }
    }
    
    In this scenario:
    1. The code begins by importing the Genero Ghost Client Java classes.
    2. The myapp_test2_provider() method implements the com.fourjs.ggc.ScenarioProvider interface.
    3. A function (scenario_0) with the id of 0 is registered in the scenarios variable. A test may register multiple test scenarios in this variable. They run in the sequence registered.
    4. A scenario_0 class is declared. This implements the com.fourjs.ggc.Scenario interface, which requires the method play to run the test.
    5. Tests for the user actions are implemented by the com.fourjs.ggc.Client interface. In between these tests, there are request for the client to "wait" for periods (measured in 100 milliseconds). These are delays between user actions as recorded in the log.

    6. The com.fourjs.ggc.ScenarioChecks interface is implemented to test for the app's form names and titles.

  2. To the play method of the scenario_0 class add code to retrieve the window name from the client.
    Note:

    The window name must be retrieved before the action to cancel is triggered.

    /*
     * Generated using Genero Ghost Client 4.00.04-202201201755
     */
    package test2scenario;
    
    import com.fourjs.ggc.ScenarioProvider;
    import com.fourjs.ggc.Scenario;
    import com.fourjs.ggc.Client;
    import com.fourjs.ggc.generator.ScenarioChecks;
    import java.util.concurrent.ConcurrentLinkedDeque;
    import com.fourjs.ggc.DependencyHandler;
    
    public class myapp_test2_provider implements ScenarioProvider
    {
      private final ConcurrentLinkedDeque<Scenario> scenarios;
      DependencyHandler dh = null;
    
      /*  */
      /* Instance initializer */
      public myapp_test2_provider()
      {
        scenarios = new ConcurrentLinkedDeque<>();
    
        /* Register scenario functions */
        scenarios.add(new scenario_0());
    
      }
    
      /* Scenario myapp_test2 id: 0 */
      private class scenario_0 implements Scenario
      {
        @Override
        public void play(Client client)
        {
          ScenarioChecks.checkFormName(client, "price");
          ScenarioChecks.checkFormTitle(client, "Product and prices");
          client.wait(70);
          client.sortTable("sr_prices", "price".equals("null") ? null : "price", com.fourjs.ggc.auitree.SortType.get("desc"));
    
          ScenarioChecks.checkFormName(client, "price");
          ScenarioChecks.checkFormTitle(client, "Product and prices");
          client.wait(88);
          client.setTableSize("sr_prices", 12);
    
          ScenarioChecks.checkFormName(client, "price");
          ScenarioChecks.checkFormTitle(client, "Product and prices");
          client.wait(63);
          client.action("sr_prices.edit"); /* sr_prices.edit */
    
          ScenarioChecks.checkFormName(client, "edit_price");
          ScenarioChecks.checkFormTitle(client, "Edit product price");
          client.wait(89);
          client.setFocus("formonly.price");
    
          client.setValue("$25.00");
    
          client.action("accept"); /* OK */
    
          ScenarioChecks.checkFormName(client, "price");
          ScenarioChecks.checkFormTitle(client, "Product and prices");
          client.wait(81);
    	  
          String windowTitle = client.getUserInterface().getCurrentWindow().getTitle();
          System.out.println("Window title is: " + windowTitle);
          System.out.println("Exiting with action 'cancel'");
          
          client.action("cancel"); /* Exit */
        }
      }
    
      @Override
      public Scenario nextScenario()
      {
        return scenarios.removeFirst();
      }
    }