AI validation (FR)

Perfecto Command

perfecto:ai:validation

Purpose

Use the perfecto:ai:validation command in Appium, Selenium, or Quantum tests while running tests on real and virtual Perfecto devices.

To learn more about working with AI-powered validations, see the following resources:

To have this functionality set up in your cloud, contact your Perfecto account representative. A separate license is required to access this feature.

Parameters

Name Type Possible Values Description

Validation

String

You can type any yes-no question of up to 2000 characters.

The yes-no question to validate the device screen information. The result is always pass or fail.

To learn more, see Create AI-powered validations.

Reasoning

Boolean

true, false

Enable this option to allocate additional AI resources for tasks that require multi-step logical processing, such as counting elements, sorting items, or determining order. This may improve accuracy for commands involving structured analysis or decision-making.

Default is false.

Return Value

True or False

Test failure

A test doesn't fail if something is not correct. You can implement an additional assertion and fail the test manually if needed.

Exceptions

The following message appears when your cloud does not have the consent to use AI:

Failed to execute command ai:validation: Unexpected error occurred while processing command 'ai:validation'. Error message: AI commands are disabled. To use these commands, contact your administrator. Status: Forbidden

Examples

Copy

JavaScript

const result = await driver.executeScript("perfecto:ai:validation", {validation: "Is there a Save button?" , reasoning: false });

if (result.toString().toLowerCase() === "true"
{
    // Start the reporting step
    reportiumClient.stepStart("Save expense");

    // Wait for the Save button to become clickable
    const saveExpenseButton = await driver.$("#layout_buttons");
    await saveExpenseButton.waitForClickable({ timeout: 5000 });
    await saveExpenseButton.click();

    // End the reporting step
    reportiumClient.stepEnd();

else
{
    console.log("There is no Save button");
}

 

Copy
Java
 Object result = driver.executeScript("perfecto:ai:validation", Map.of("validation", "Is there a Save button?", "reasoning", false ));
                   
if ("true".equalsIgnoreCase(result.toString()))  
    {        
        reportiumClient.stepStart("Save expense");
        AndroidElement save_expense = (AndroidElement) wait.until(ExpectedConditions.elementToBeClickable(
            driver.findElement(By.id("layout_buttons")) ) );
        save_expense.click();
        reportiumClient.stepEnd();
    }
else 
    {
        System.out.println("There is no Save button");
    }