Associate a device with a Perfecto Connect tunnel

Let's have a quick look at the following Appium script.

public class AppiumTest {
    public static void main(String[] args) throws MalformedURLException, IOException {
        System.out.println("Run started");
         String browserName = "mobileOS";
         DesiredCapabilities capabilities = new DesiredCapabilities(browserName, "", Platform.ANY);
         String host = "";
         // capabilities.setCapability("user", "");
         // capabilities.setCapability("password", "testpass");
         capabilities.setCapability("securityToken", "eyJhbGciOiJSUzI1o...XcK7BRhmkEo7qrA");
         capabilities.setCapability("deviceName", "DEVICEID");
         capabilities.setCapability("automationName", "Appium");
         capabilities.setCapability("tunnelId", "0a334599-210a-4d42-aa8e-445071a4070b");

         AndroidDriver driver = new AndroidDriver(new URL("http://" + host + "/nexperience/perfectomobile/wd/hub"), capabilities);
         driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
         // Reporting client. For more details, see
         PerfectoExecutionContext perfectoExecutionContext = new PerfectoExecutionContext.PerfectoExecutionContextBuilder()
            .withProject(new Project("My Project", "1.0"))
            .withJob(new Job("My Job", 45))

         ReportiumClient reportiumClient = new ReportiumClientFactory().createPerfectoReportiumClient(perfectoExecutionContext);
         try {
            reportiumClient.testStart("My test name", new TestContext("tag2", "tag3"));
             // write your code here


         } catch (Exception e) {
            reportiumClient.testStop(TestResultFactory.createFailure(e.getMessage(), e));
         } finally {
            try {
             } catch (Exception e) {
        System.out.println("Run ended");

Following is a list of the capabilities we are setting for this execution:

  • securityToken - your Perfecto security token
  • user - your Perfecto username (use only if security token not supported for your Perfecto Lab)
  • password - your password (use only if security token not supported for your Perfecto Lab)
  • deviceName - the Device ID which you'd like to use (we're using a single device for demonstration purposes, but you may use several)
  • tunnelId - the Tunnel ID received from perfectoconnect

This script makes use of the tunnelId capabilitywhich configures the system to associate the device with this tunnel when opened. This means that all HTTP/S requests and responses generated by and for the device, during the execution of the script, are routed through the tunnel created earlier by perfectoconnect. This allows the device to access your local network. In the example above, http://local-web-server is a local web server that resides within your local network.

Important: Perfecto Connect for fast web devices is only supported with Selenium scripts. The script should provide the tunnel-id using the tunnelid capability, as shown above.