Improving Script Execution Speed
When you begin writing longer SenseTalk scripts and using advanced scripting techniques in Eggplant Functional, you might soon need to address the overall execution speed of your tests. Adjusting your runtime by even a few seconds here and there can make a huge difference when you’re running a large number of complex scripts.
SenseTalk provides many methods for speeding script execution. The methods described here should all help your scripts run faster, but you will need to determine which ones best suit your specific testing scenarios.
Lowering the SUT Interaction Time
One of the best things you can do to improve script execution time is to adjust the RemoteWorkInterval
global property. This property controls the amount of time between events before Eggplant Functional sends the next event to the system under test (SUT). By lowering the RemoteWorkInterval
global property value in your scripts, your scripts should run quicker.
The default value for this global property is .7 seconds. To reduce the RemoteWorkInterval to, for example, .3 seconds, add the following SenseTalk command to your scripts:
set the remoteWorkInterval to .3
With this adjustment, the time that the SenseTalk script pauses between events decreases to .3 seconds.
The optimal value for the RemoteWorkInterval global property depends on environmental factors, such as server resources and network speed. After testing your scripts, you might need to further adjust the RemoteWorkInterval value to suit your environment.
Setting the RemoteWorkInterval global property within your script makes it easy to increase and decrease this property value during runtime. You can use this method if you have sections of a script that require different delay times between actions. Additionally, putting the timing adjustment within the script makes the adjustment portable if you are sharing scripts or suites across a team.
Remote Work Interval Preference Setting
If runtime adjustments are not important to your scripting, you can adjust the RemoteWorkInterval global property through Eggplant Functional Preferences:
- Select eggPlant > Preferences
- Select the Run tab, then the System tab.
- Set your preferred value for the Remote Work Interval.
Setting a Remote Work Interval value in Preferences is a local user value only and does not affect the timing of scripts you might share with other users. Like all Preference settings, however, it applies to all scripts and suites for this user account.
If you change the Remote Work Interval preference, you can still adjust the remoteWorkInterval
global property within a script to affect that runtime. Changing the global property during runtime does not change the user preference value.
Lowering Image Search Times
Although Eggplant Functional is intended to be an image-based tool, image searching can be a time-consuming part of your script execution. By default, Eggplant Functional searches for each image up to six times, then performs a full screen refresh and one more search before it reports that the image was not found. Between each image search in this process, there is a delay equal to the ImageSearchDelay
global property value.
Lowering the ImageSearchDelay
value increases the frequency of the scans, and therefore speeds your script execution. To adjust this property, add the following SenseTalk command to your script:
Set the imageSearchDelay to 0.1
The SenseTalk script attempts to search the area at this frequency, but if the area is large or you are searching for an image collection (which can take longer because there are multiple images to search for), it automatically adjusts the frequency to allow each scan to complete.
Your overall search time is also affected by the ImageSearchCount
and the ImageSearchTime
global properties. See the ImageSearchCount
, the ImageSearchDelay
, and the ImageSearchTime
for more information about the way these properties interact to affect image search times.
Using the WaitFor Property
You can speed script execution by using the WaitFor
property value with image search commands. Similar to the WaitFor
command, the WaitFor
property sets the maximum amount of time Eggplant Functional waits for a given image to appear on the SUT. You can shorten this wait time by using the WaitFor
property with a short time value as shown in the following example.
Example:
Click (ImageName:"Done_button", waitFor: 2) // Wait for a maximum of two seconds for the image to appear on the SUT
put "The test is complete."
The script executes the next command as soon as the image appears; it does not wait for the WaitFor
time to pass before continuing execution.
If you know at a certain point in your script that an image is already there, or it is not going to be there, you don't need to wait for a long search. To speed script execution time, set the WaitFor
time to a zero value, which tells Eggplant Functional to scan for the image only once instead of the default of seven times. This technique is particularly useful within repeat loops and other iteration methods, as shown in the following example:
Example:
repeat 1 minute
If imagefound (imageName:"Notification", waitFor: 0) then
Logwarning "The warning is still present."
wait 2
else
Log "The warning is gone."
Exit Repeat
End If
end repeat
Using Image Functions
Use the following image functions to speed script execution, save search time, and gather information about your script execution.
FoundImageLocation()
The FoundImageLocation()
function returns the screen coordinates of the last image that was found. When your next action refers to the same image as the previous search, you can save time by using this function to call it directly from its coordinates, which is much faster than searching the screen again.
Example:
WaitFor 8, "Save Button", "OK Button","Retry Button" -- Waits up to 8 seconds for one of the button images to be found
Click FoundImageLocation() -- Clicks the hot spot of whichever image was found.
In the example shown above, Eggplant Functional finds one of the buttons during the WaitFor
command. Then, already knowing the location of that button, it clicks it immediately, reducing the script execution time.
If you use the image names in the script instead of the FoundImageLocation()
function, Eggplant Functional performs the search again for the Click
command, which adds time to the script execution.