Quick start: Run your first Appium test with Perfecto

If you are already familiar with Appium, use the following quick-start information to run a simple Appium test on Perfecto with minimal setup. If you need more guidance, see the main Appium article.

Prerequisites

Before you get started, make sure you have installed the following:

  • Java 11

  • An IDE of your choice, such as Eclipse or IntelliJ IDEA (consider using IntelliJ IDEA for a better Appium and Maven integration)

  • Maven

Additional setup per IDE

If you use Eclipse with the following:

If you use IntelliJ IDEA with Apache Maven, install the Maven plugin for IDEA. IntelliJ IDEA versions 7 and later include the TestNG plugin as a built-in plugin.

Optional installations

For source control management, you can install git.

This plugin is usually bundled with the IDE, but ensure it is enabled.

Step 1: Set up desired capabilities

For iOS or Android, specify the relevant desired capabilities. Following is an example in JSON format for running a mobile web test (Safari on iPhone). Replace your_perfecto_security_token with your actual token from the Perfecto UI (from the menu at the top right, select My Profile > Security Token).

Copy
{
  "platformName": "iOS",
  "browserName": "mobileSafari",
  "deviceName": "iPhone.*",
  "automationName": "XCUITest",
  "securityToken": "your_perfecto_security_token"
}

Step 2: Start a session

The following code example illustrates how to start a session using Appium with Java (TestNG/WebDriver).

Copy
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.ios.options.XCUITestOptions;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.URL;

public class PerfectoSafariTestAppium2 {
    public static void main(String[] args) throws Exception {
        // Set up XCUITest-specific options
        XCUITestOptions options = new XCUITestOptions();
        options.setPlatformName("iOS");
        options.setBrowserName("mobileSafari");
        options.setDeviceName("iPhone.*"); // regex for any iPhone
        options.setAutomationName("XCUITest");
        options.setCapability("securityToken", "your_perfecto_security_token");

        // Replace <cloud> with your actual Perfecto cloud name
        URL url = new URL("https://<cloud>.perfectomobile.com/nexperience/perfectomobile/wd/hub");

        // Initialize AppiumDriver with XCUITestOptions
        WebDriver driver = new AppiumDriver(url, options);

        // Navigate to a website
        driver.get("https://example.com");

        // Print the page title
        System.out.println("Page Title: " + driver.getTitle());

        // Quit the driver
        driver.quit();
    }
}

Step 3: Configure optional capabilities for advanced use

Optionally, you can add the following capabilities to align the session with Appium's behavior inside Perfecto. To learn more, see Supported Appium capabilities.

Copy
{
  "useAppiumForWeb": "true",
  "enableAppiumBehavior": "true"
}

Step 4: Review test reports

After running a test, you can view the test results in the Perfecto Report Library, including video, logs, screenshots, and device vitals.