Write a Genero BDL test

To write a test in Genero BDL, one file may contain the function that manages the session and the function or functions that run tests.

Note: In Genero Studio you can write tests using Genero BDL and compile them to Java using the Genero Ghost Client infrastructure through the Java Bridge. The Java Bridge allows you to import GGC classes. See the The Java interface section of the Genero Business Development Language User Guide.
  1. Begin your program code by importing the Genero Ghost Client Java classes.
    Your test requires these classes:
    • The Session class is the entry point for Genero BDL tests. A session needs to be created to give the URL to start the main application.
    • The Application class is got from the Session. It uses methods that reference the interface form objects such as fields, actions. etc. Values can be retrieved and set.
    • The Log class implements the logging mechanism used to display errors, warnings, and information as output from the tests.
    IMPORT JAVA com.fourjs.ggc.fgl.Application
    IMPORT JAVA com.fourjs.ggc.fgl.Session
    IMPORT JAVA com.fourjs.ggc.util.Log
    IMPORT JAVA java.lang.String
  2. Create a function that manages the test session.
    In our sample code your can see:
    • The Session.create(url) method takes the argument of the URL of the application to test.
    • The s.getNextApplication(10) method gets the session's next pending application to test. Timeout is set to ten seconds.
    • The launchDemo function represents the test scenario. In our case we choose to pass arguments of the app class that represents the application we want to test. The test is targeting the "IA demo" application in the application tree of the gwc-demo.
    • The childApp variable gets another instance of the application, which is run while the main application is still running, as shown in the example.
    • The app.enqueueAction("cancel") method takes as argument an action name as defined in your 4GL dialog statement (on action ...). The EnqueueAction method uses the underlying GhostRunner to interact with the application but it uses an intermediate queue to free up the runner for the program using the application object to do something else while the runner is executing the requested operation. The app.synchronize(10) method waits ten seconds for this application interface queue to empty.
    • The getApplicationListener().getLogger() method gets the logger for monitoring the application. If the application fails to run or an application is missing, etc., the messageFromBdl method is invoked to output the information to the standard output.
    /**
     * Sample function to manage a test of the "IA Demo" application from the FGLGWS demo
     */
         FUNCTION testSession(url)
    	DEFINE s            Session
    	DEFINE app          Application
    	DEFINE childApp     Application
    	DEFINE childApp2    Application
    	...
           DEFINE sLog         Log
           DEFINE aLog         Log
    
    	LET msg = SFMT("Running DemoTests on %1 ...", url)
    
    	-- Run main application and make some basic introspection -----------------
    
    	LET s = Session.create(url)
            LET sLog = s.getSessionListener().getLogger()
    	 CALL sLog.messageFromBdl(msg)
    
    	LET app = s.getNextApplication(10)
    	IF app IS NULL THEN
    	   CALL sLog.errorFromBdl("Main Runner not spawned")
    	   EXIT PROGRAM 1
    	END IF
    
           LET aLog = app.getApplicationListener().getLogger()
    	LET v = app.getApplicationName()
    	CALL sLog.messageFromBdl("Main application name:", v)
    	IF v != "demo" THEN
    	   CALL sLog.errorFromBdl("Incorrect application name. Expecting [demo]")
    	   EXIT PROGRAM 1
    	END IF
    	...
    
    	-- Running the IADemo application -----------------------------------------
    	
    	CALL launchDemo(app, "Compatibility/IADemo", "The IA demo")
           
    	LET childApp = s.getNextApplication(10)  
    	IF childApp IS NULL THEN
    	   CALL sLog.errorFromBdl("Unable to get the expected child application [ia]")
    	   EXIT PROGRAM 1
    	END IF
            -- RUN WAITING a new IADemo instance from IADemo --------------------------
    
    	LET v = childApp.getApplicationName()
    	CALL sLog.messageFromBdl("Child application name:", v)
    	IF v != "ia" THEN
    	   CALL sLog.errorFromBdl("Incorrect application name. Expecting [ia]")
    	   EXIT PROGRAM 1
    	END IF
    	
    	CALL sLog.messageFromBdl("We successively made a run without waiting!")
    
    	CALL app.enqueueAction("cancel")
    	CALL app.synchronize(10)
    
           ...
           IF app.isRunning() THEN
             CALL sLog.messageFromBdl("app is still running!")
           ELSE
             CALL sLog.messageFromBdl("app successfully ended!")
           END IF
    
           IF s.getSessionListener().computeResult("DemoTests") THEN
             LET msg = SFMT("DemoTests successful on %1", url)
             CALL sLog.messageFromBdl(msg)
             LET success = TRUE
           ELSE
             LET msg = SFMT("DemoTests not successful on %1", url)
             CALL sLog.messageFromBdl(msg)
             LET success = FALSE
           END IF
      END FUNCTION
    Note:

    The complete source code for the example can be found in the DemoTests.4gl file of the Genero Studio GGC_Sample.4pw project included in the samples/BDL directory.