ℹ️ Info: Class:
co.verisoft.fw.perfecto.PerfectoAIUtilsPlatform: Perfecto AI-Based Testing
Reference: Perfecto AI-Based Testing
Overview
PerfectoAIUtils is a utility class in the VeriSoft framework that exposes Perfecto's AI-based testing engine. It allows you to perform natural-language UI actions and validations on real devices hosted on the Perfecto cloud — without relying on XPath/CSS selectors.
Results are returned via AIActionResult, a companion class that holds both the success flag and any output variables captured from the screen during the AI action.
Configuration (config.properties)
⚙️ All properties below are optional. If not defined, the framework uses the defaults listed.
| Property | Type | Default | Description |
|---|---|---|---|
perfecto.ai.reasoning |
boolean | false |
Enables Perfecto's AI reasoning mode for more complex decisions |
perfecto.ai.max.retries |
int | 1 |
Number of retry attempts when an AI action fails |
Example (optional):
perfecto.ai.reasoning=true
perfecto.ai.max.retries=3
Class: AIActionResult
Returned by performAIAction(String, boolean). Contains:
| Method | Returns | Description |
|---|---|---|
isSuccess() |
boolean |
Whether the AI action succeeded |
getOutputVariables() |
Map<String, Object> |
Raw map of all captured output variables |
getOutputValue(String variableName) |
String |
The string value of a specific captured variable (e.g. "temp") |
Class: PerfectoAIUtils – API Reference
Constructor
PerfectoAIUtils utils = new PerfectoAIUtils((JavascriptExecutor) driver);
Throws IllegalArgumentException if the driver is null.
performAIAction(String action) → boolean
Performs a natural-language UI action on the device. Retries automatically up to perfecto.ai.max.retries times.
boolean success = utils.performAIAction("Tap the Login button");
Returns true on success, throws RuntimeException after all retries are exhausted.
performAIAction(String action, boolean useOutputVariable) → AIActionResult
Same as above, but when useOutputVariable = true the AI engine captures values visible on screen into named variables (e.g. ${temp}), which you can retrieve from the result.
AIActionResult result = utils.performAIAction("Read the OTP code into ${otp}", true);
if (result.isSuccess()) {
String otp = result.getOutputValue("otp");
}
| Parameter | Description |
|---|---|
action |
Natural language instruction (may include ${variableName} placeholders) |
useOutputVariable |
true to capture output variables from the screen |
validateWithAI(String validation) → Object
Validates a UI condition using Perfecto's AI engine. Throws RuntimeException if the validation fails.
utils.validateWithAI("The home screen is displayed");
Does not retry — throws immediately on failure.
Quick Example
import co.verisoft.fw.perfecto.PerfectoAIUtils;
import co.verisoft.fw.perfecto.AIActionResult;
import org.openqa.selenium.JavascriptExecutor;
// Assume 'driver' is an AppiumDriver connected to a Perfecto device
PerfectoAIUtils ai = new PerfectoAIUtils((JavascriptExecutor) driver);
// 1. Perform a simple tap action
ai.performAIAction("Tap the Sign In button");
// 2. Fill a text field
ai.performAIAction("Enter 'user@example.com' in the email field");
// 3. Capture a value from screen (OTP, price, label, etc.)
AIActionResult result = ai.performAIAction("Read the account balance into ${balance}", true);
if (result.isSuccess()) {
String balance = result.getOutputValue("balance");
System.out.println("Balance: " + balance);
}
// 4. Validate UI state
ai.validateWithAI("The dashboard screen is visible");
Retry Behavior
Both performAIAction overloads retry on:
falseresult returned by the AI engine- Any exception thrown during script execution
validateWithAI does not retry.
Notes
- All actions are executed via
driver.executeScript("perfecto:ai:user-action", params)/"perfecto:ai:validation"— standard Perfecto AI commands. - The
reasoningflag enables the Perfecto AI engine's extended reasoning mode, useful for complex or ambiguous screens. - Natural language instructions should be concise and describe what is visible on the screen.
For the full Perfecto AI command reference, see: https://help.perfecto.io/perfecto-help/content/perfecto/ai-based-testing.htm