Skip to main content

Autosnippet Generation in Eggplant Functional

The Autosnippet feature is part of an Autoscan session that lets you automatically generate SenseTalk scripts from detected elements in your system under test (SUT). The scripts that Eggplant Functional generates contain short code snippets to perform common actions such as clicking buttons or entering text in a field.

Autosnippet scripts are divided into short sections for each detected element. Each section consists of one or more action handlers. The handlers in the generated script can be called to perform the action or validation on the element identified in the Autoscan session on your SUT.

Autosnippets are useful for modularizing scripts, and can be imported as snippets in Eggplant AI.

Step by Step: Generate Autosnippets

  1. Perform an Autoscan session of a SUT, then open the session when the scan is complete.
  2. Set the Element Type for any elements in the scan for which you want code snippets generated. If you are testing against a desktop SUT, this can be done using the Classify Images button displayed below the element code list during the session. If your Autoscan session is for a mobile device SUT connected through Android Gateway or iOS Gateway, the Element Type might be detected and set automatically. However, you should make sure that the setting matches your intended use. For more information on how the Classify Images button works, see the step-by-step instructions for Using Autoscan to Capture Images.

The types of elements that can be selected from the Element Type drop-down list are:

  • None: Use to generate an image but no code.
  • Checkpoint: Generates two handlers that can be used to validate the presence of the element.
  • Button: Generates a handler to click the element.
  • Field: Generates two handlers, one for entering text in a field and one for reading text from a field.
  • Checkbox: Generates a handler to select a checkbox.
  • RadioButton: Generates a handler to select a radio button.
  • DropDown_Mobile: Generates a handler, optimized for mobile device SUTs and mobile browsers, to select an item from a drop-down menu.
  • DropDown_Desktop: Generates a handler, optimized for desktop SUTs and browsers, to select an item from a drop-down menu.
  1. Set the Element Name. This field is required for Autosnippets. It is incorporated in the handler names generated in the script.

    If your Autoscan session is for a mobile device SUT connected through Android Gateway or iOS Gateway, the Element Name might be detected and set automatically. Otherwise, the Element Name gets set to match the Image Name when you set the Element Type. If you haven't set the Image Name, the value is a default in the form image0005.

    In any case, you can update the Element Name field to ensure the name makes sense and matches any naming conventions you have established. For instance, you might not want the handler name and the image name to match.

  2. Proceed through the list of elements you want to include. You can use the up and down arrows on the right side of the session tab to move through the detected elements. You can also click any of the rectangles in the scan in the center pane to select it. If you have processed all the elements that you want to keep and have additional elements that you don't want to keep, you can use the Delete unnamed images button to delete the unnecessary ones.

    note

    When you select an element, either by using the arrows or directly in the center pane, the default name is autofilled. At that point, it won't be removed if you use the Delete unnamed images button. However, you can remove those elements if you don't need them by clicking the X in the rectangle's upper left corner.

  3. Make sure the Script and Images checkboxes are both selected to generate scripts and images at the same time, then click Generate.

Eggplant Functional creates a new script with the name of the Autoscan session. The generated script opens in the Suite window.

The Autosnippet Script

The generated Autosnippet script contains the code snippets—handlers—for each item with an Element Type other than None when you generate the Autoscan session. This script is a typical SenseTalk script in all respects. You can edit it and add additional code as you require.

In the generated script, Autosnippets are delineated by comment headers and dashed lines. The example below shows the generated Autosnippet for an image called Sprout that's been assigned the Checkpoint type, which includes two handlers:

(* Autosnippets for Checkpoint "sprout" *)

to handle sprout_Validate duration
if duration is not a number then set duration to 8
WaitFor duration, imageName:"sprout"
end sprout_Validate

to handle sprout_IsFound duration
if duration is not a number then set duration to 8
return imageFound(imageName:"sprout", waitFor:duration)
end sprout_IsFound

-----------------------------------

Autosnippet Templates

The default templates used to generate action handlers are stored in the AutosnippetTemplates.txt file in Eggplant Functional. This file is stored in different places based on your computer's operating system:

  • Mac:/Applications/Eggplant.app/Contents/Resources
  • Windows: C:\Program Files\Eggplant\Eggplant.app\Contents\Resources\

If you want to customize the templates, first create a local copy of the file, then adjust the code as needed:

  1. In Eggplant Functional, go to Eggplant > Preferences > Script.
  2. On the General tab, click Customize in the Autosnippet Template File section.
  3. A Save As window opens. Choose where to save a copy of the template file, and what to name that copy. Eggplant Functional saves the customized file and stores its location.
  4. Edit the file as needed. There are instructions in the file to guide you.

To select a different template file, click Browse and select the file to use, or enter its file path directly in the field. To revert to the default templates, delete the file path from the field.