Working with snapshots

A snapshot records the state of an application at the time it is taken. You have options in how that snapshot can is when generating and customizing your tests.

Important:

Taking snapshots require GBC 4.00-EAP2!

What is a snapshot?

A snapshot records the application state by writing the details of the AUI tree to the log file. A snapshot also writes an event to the log file, that can be used to identify when the snapshot was taken.

You can have more than one snapshot in a log file. Each snapshot has an integer as an identifier, starting with zero and numbering sequentially for each subsequent snapshot.

When a test is generated from a log file containing a snapshot, a snapshot XML file is generated (in addition to the test scenario). This snapshot XML file is the representation of the Genero AUI tree at the time the snapshot was taken.

How to take a snapshot

To take a snapshot, you must be using either the Genero Browser Client (GBC) or Genero Desktop Client (GDC). While recording the application log, use the ALT+F12 keyboard shortcut to create a snapshot. Depending on the Genero front-end, you may receive visual feedback that the snapshot occurred.

Limit the code generation to the snapshots only

When you generate a test scenario using a non-snapshot check option, the template code for the check is inserted at each interaction captured in the log. That can result in a lot of checks. By using the --check-on-snapshot option, the code for the check is inserted only for interactions that are snapshot events.

For example, consider a scenario where two snapshots were fired when recording the log file guilog.log. To check the name of the window at the time of the snapshots only, you would generate a scenario using the command ggcgen --check-on-snapshot=window guilog.log. The generated test would insert the template code that checks the window name twice, at each point where a snapshot was taken.

Two snapshot XML files are created when you run the ggcgencommand; however, in our example they are not used and can be deleted.

Use the snapshot XML file in your test

When you generate a test scenario that includes snapshots, snapshot XML files are created. A snapshot XML file is the representation of the Genero AUI tree at the time the snapshot was taken. The first snapshot XML file is named guisnapshot-0.xml; the filename increments (guisnapshot-id.xml) with each additional snapshot recorded in the log.

You can edit your scenario and load the values from the guisnapshot-id.xml file using classes of the xml library, to compare those values against the state of the application you are testing.

  • Load the snapshot file into a DomDocument object using methods from the xml.DomDocument class.
  • Load the current AUI tree into a DomDocument object using the ggc.getAuiTree() method.
  • Use methods of the xml.DomNodeList class to navigate and compare the AUI tree in the snapshot to the AUI tree of the application being tested.

Next, add a template named event_guisnapshot.4gl that calls this new Genero module. Save it in your custom template directory.

Finally, use the ggcgen command to generate the test scenario. You must use the --template-directory option to specify which directory holds your custom templates.

For a complete example, see Using a snapshot to compare the number of nodes.