Using a snapshot to compare the number of nodes

This example illustrates how to compare the AUI tree from the snapshot to the AUI tree of the application under testing.

This example results in a Genero BDL test scenario.

Create the Genero module to perform the test

This Genero module compares the number of nodes of a specified table in the current AUI tree with the number of nodes in the AUI tree recorded in the snapshot. It only completes this task for the first of two snapshots. This code is provided as an example, to illustrate how one loads and works with the AUI trees in the test scenario. It creates a function named CheckComplexForm() in the Genero module Callback.4gl.

# For this example, this file is named "Callback.4gl"

IMPORT FGL ggc
IMPORT xml

MAIN
  CALL CheckComplexForm(0)
END MAIN

PUBLIC FUNCTION CheckComplexForm(id STRING)
  DEFINE doc xml.DomDocument
  LET doc = xml.DomDocument.Create()
  CALL doc.load(SFMT("guisnapshot-%1.xml",id))
  CASE id
    WHEN 0
      CALL CheckFormStep0(doc)
    WHEN 1
      CALL CheckFormStep1(doc)
    OTHERWISE
      DISPLAY "Error: unexpected"
      EXIT PROGRAM 1
  END CASE
END FUNCTION

PRIVATE FUNCTION CheckFormStep0(snapshot_doc xml.DomDocument)
  DEFINE app_doc xml.DomDocument
  DEFINE app_list xml.DomNodeList
  DEFINE snapshot_list xml.DomNodeList
  
  DISPLAY "AUI tree checking step 0"
  
  # Retrieve current application aui tree
  LET app_doc = ggc.getAuiTree()
  
  # Execute XPath to retrieve the aui nodes of the Topic table of the current AUI tree.
  # Line break added for documentation, this should be in one line.
  LET app_list = app_doc.selectByXPath("/UserInterface/Window[@text='Demos']/
Form[@text='Demos']/Grid/VBox/HBox/Table/TableColumn[@text='Topic']/ValueList/Value",NULL)
  
  # Execute XPath to retrieve the aui nodes of the Topic table on snapshot reference file.
  # Line break added for documentation, this should be in one line.
  LET snapshot_list = snapshot_doc.selectByXPath("/UserInterface/Window[@text='Demos']/
Form[@text='Demos']/Grid/VBox/HBox/Table/TableColumn[@text='Topic']/ValueList/Value",NULL)
    
  # Ensure there are the same numbers in both case
  IF app_list.getCount()!=snapshot_list.getCount() THEN
    DISPLAY SFMT("Expected %1 elements in Topic table but got %2",
snapshot_list.getCount(),app_list.getCount())
    EXIT PROGRAM 1
  END IF
  
END FUNCTION

PRIVATE FUNCTION CheckFormStep1(doc xml.DomDocument)
  DISPLAY "AUI tree checking step 1"
END FUNCTION

Create the template for a snapshot event

To insert code each time a snapshot event occurs, you create a template named event_guisnapshot.4gl. In this example, the custom code calls the CheckComplexForm() function in the Genero module Callback.4gl.

!! A GUI snapshot event occurs
!!
!! Parameters:
!!    . id          : The snapshot id.
!!
    # GUI snapshot id: ${id}
    CALL Callback.CheckComplexForm($(id))

Generating the test scenario

When generating the test scenario, ensure you point to the template directory holding your custom template. For example, if your custom template file is located in C:\my_templates, your command would be ggcgen bdl --template-directory "C:\my_templates" guilog.log.

Modify the test scenario

The generated scenario includes the snapshot event template code for each snapshot event.

You must import any custom modules by adding the IMPORT FGL statement to reference your Genero module.

In this example, the generated test scenario includes the snapshot event template code twice; once for each snapshot. The statement IMPORT FGL Callback has been added by the developer.

# =============================================================================
# Generated using Genero Ghost Client 4.00.XX
# =============================================================================
IMPORT FGL ggc
IMPORT FGL Callback

MAIN
    CALL ggc.setApplicationName("demo")
    CALL ggc.parseOptions()

    # Register scenario functions
    CALL ggc.registerScenario(FUNCTION play_0)

    # Start execution
    CALL ggc.play()

    EXIT PROGRAM 0
END MAIN

# Scenario guilog2 id : 0
PRIVATE FUNCTION play_0()
   
    # code removed for this example

    CALL ggc.wait(2793)
    # GUI snapshot id: ${id}
    CALL Callback.CheckComplexForm(0)

    CALL ggc.wait(2197)
    # GUI snapshot id: ${id}
    CALL Callback.CheckComplexForm(1)

    # code removed for this example 

    CALL ggc.end()
END FUNCTION