Write a Java test

Use the information and the examples shown here to begin writing your own test scenarios. A sample program is provided to assist you in writing your own Java tests.

Note:

The complete details of the packages and classes that make up the Genero Ghost Client can be found in the /doc directory of your GGC package. Please see the help file by launching the /doc/index.html file in your browser.

  1. Begin your Java code by importing the Genero Ghost Client Java classes.

    Your session manager function manages the whole test session life cycle. It requires these classes:

    • The SessionManager class.
    • The Scenario class. You need to instantiate a scenario by including a getScenario() function. You can have a sequence of scenarios, if required, to run your tests.

    In this example, the scenario instance created is given to the main application. This is the first application that will be launched when the test is run.

    If child applications are run by the main application, the SessionManager will also get each of them a scenario and instantiate them, as shown in the example.
    import com.fourjs.ggc.Scenario;
    import com.fourjs.ggc.SessionManager;
    
    public class mySessionManager
    		implements SessionManager
    {
    	boolean mStarted = false;
    	public Scenario getScenario()
        {   
            if (!mStarted) {
                mStarted = true;
                return new FirstScenario(); << will be given to the first 4gl application, 
                                               the mother
            } else {
                return new SecondScenario(); << will be given to the second 4gl application, 
                                                the child launched via run 
                                                or run without waiting by the mother
            }
        }
    }
  2. Write a function to test your application.
    Your test function or scenario requires these methods:
    • A play(GhostRunner runner) method, which describes the user interaction to play; that is the sequence of tests it plays.

      You decide what tests are to be carried out by providing within the play(GhostRunner runner) function the required user interactions.

    • An InvokeFrontcall(String module, String name, String[] args) method, which describes how to handle the call to the front-end client when and if it is required by the application.
    • A getScenarioListener() method. This method is called by the GhostRunner framework to perform runtime monitoring.

    In this code sample the CustOrders application from the FGLGWS demo is being tested for integrity.

    The mRunner.getActions() method passes details about the form's menu actions into an array and checks these against an expected list of actions. If an action menu is missing, the runner.log().error method outputs the information to the standard output.
    /**
     * The Scenario to test the "CustOrders" application from the FGLGWS demo
     */
    public void play(GhostRunner runner)
    	{
    	mRunner = runner;
    	try {
    
    		// at least, we expect these actions
    		String[] expected = { "zoom_city", "cust_query", "cust_next", 
    		                      "cust_last", "dialogtouched", "cust_append",
    					 "cust_delete", "ord_append", "ord_modify", 
    					 "ord_delete", "close" };
    		ArrayList<ActionInfo> actions = mRunner.getActions();
    		for (String act : expected) {
    			boolean present = false;
    			for (ActionInfo action : actions) {
    				if (act.equals(action.getName())) {
    					present = true;
    					break;
    				}
    			}
    			if (!present) {
    				runner.log().error("CustomerOrderScenario: 
    		                action [", act, "] is missing");
    			}
    				…
    		}
             }