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.
- Perform an Autoscan session of a SUT, then open the session when the scan is complete.
- Set the Element Type for any elements in the scan for which you want code snippets generated. The types you can choose on the drop-down menu 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.
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.
The handler code that gets generated for each Element Type is defined in the Autosnippet Templates file. When at least one item has an Element Type other than None selected, the Script checkbox is enabled.
- 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.
- 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.
- 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"
to handle sprout_IsFound duration
if duration is not a number then set duration to 8
return imageFound(imageName:"sprout", waitFor:duration)
The default templates used to generate action handlers are stored in the AutosnippetTemplates.txt file in Eggplant Functional. If you want to customize the templates, create a local copy of the file, then adjust the code as needed:
- In Eggplant Functional, go to Eggplant > Preferences > Script.
- On the General tab, click Customize in the Autosnippet Template File section.
- 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.
- 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.