AWS Device Farm
Developer Guide (API Version 2015-06-23)

Use a Remote Debugging Session in AWS Device Farm

Prerequisites

To create a remote debugging session, follow the instructions in Create a Remote Debugging Session in AWS Device Farm, and then return to this page.

View and Interact with Devices Remotely

After the device that you requested for a remote debugging session becomes available, choose Interact to open the device window and interact with the device (but not debug it).


                Device Farm - Connect button

The device window opens and allows you to view and control the device via streaming video.

Note

The device won't be visible in Android Studio or Xcode until you connect to it.


                The Device Farm device window

By using the device window, you can interact remotely with the device as you would the actual physical device. For touch actions, use your mouse or a comparable input device. For keyboard actions, use the device's on-screen keyboard or use the physical keyboard or a comparable input device for your computer.

The session has a default timeout value of 150 minutes. To learn how to change this value, see Set the Execution Timeout for Test Runs in AWS Device Farm.

Connect to Remote Devices

You can connect to your remote devices and debug them locally, as if they were connected directly to your computer. To connect to remote devices, choose Connect. This creates an ssh tunnel to the EC2 instance that hosts your devices, and you can now access them locally by using your preferred debugging tools. You will lose any local device connections that you already had.

Now the devices are visible to your IDE, such as Android Studio or Xcode, and other tools, such as ADB for Android and Instruments for iOS.

Note

The first time you connect to the ssh tunnel on a Macintosh, you'll need to enter the local machine's Macintosh root password.


                The Device Farm Connect button

If you encounter a Connect to remote devices failed error, you can troubleshoot the error as follows:

  1. From the Advanced menu, choose View Logs.

    
                        Device Farm - View Logs menu item
  2. In the logs, look for the following line, where host_ip is the host IP address:

    [date time] [info] Creating ssh tunnel to host address: host_ip

    Copy the host IP address.

  3. Open a terminal window and run the following command, where host_ip is the host IP address you copied from the logs:

    ssh –v –N -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null –L 5037:localhost:5038 –i “~/.aws/devicefarm/prikey.pem” device-farm@host_ip
  4. Check the command output to see why the connection attempt failed.

Switching Between Remote and Local Devices

To disconnect from a remote device, choose Disconnect. When you disconnect from your remote devices, you will no longer see them in your debugger. You will see only your local devices.


                Device Farm - Connect button

To reconnect to your remote devices, choose Connect.

Debugging Your App Remotely with Android Studio

After you connect to a remote device in the Device Farm app, you can begin to debug your app with Android Studio as follows:

  1. Launch Android Studio.

  2. Choose the Run button to run your app. A dialog box will appear that lists your connected devices. Your remote Device Farm devices will appear as if they are local devices that are physically connected to your computer.

  3. Connect to a device and debug your app.


                The Device Farm device window

Debugging Your App Remotely with Xcode

After you connect to a remote device in the Device Farm app, you can begin to debug your app with Xcode as follows:

  1. Launch Xcode. Your remote Device Farm devices will appear in device selection menus as if they are local devices that are physically connected to your computer.

  2. Connect to a device and debug your app.

Note

The following guidelines can help you debug your app remotely by using Xcode:

  • When you use the remote iOS device for the first time, you may see the warning "Processing symbol files" in Xcode. This will take some time and prevent you from running or debugging your app on the remote device. Wait until it is done before you use your remote device.

  • When you connect to a remote device, you might not see the device in Xcode if Xcode was open before you connected to the first remote device. If this happens, restart Xcode, and you should see the device in Xcode.

  • If you get a failure interacting with the device by using the libimobiledevice library, open the video stream for the device and accept the trust pop-up if one appears. You should then be able to list the device by using the libimobiledevice library.

  • To launch an app on the iOS device, you can use either the Xcode-managed provisioning profile or your own provisioning profile. If you want to use your own provisioning profile, add the udid of the device to your provisioning profile. You can get the udid of the device by hovering over the device name in the Active Sessions list in the Device Farm client app. After adding the udid of the device to your provisioning profile, update your Xcode to use the latest provisioning profile.

    
                            The Device Farm device window
    
                            The Device Farm device window

Using Test Automation

After you connect to your remote devices, they should appear as if they were connected locally. You can run your test in concurrent fashion against multiple Android and iOS devices by using your preferred test automation framework, such as Calabash, Appium, or Spoon.

To verify that your device is connected, use a command such as adb or instrument.

Verifying a Device Connection Using ADB for Android

To verify a device connection, enter adb devices at the command prompt. After you can list the devices locally, you should be able to run test automation as if the devices are connected locally.


                    The Device Farm device window

Verifying a Device Connection Using Instruments for iOS

To verify a device connection by using instruments for iOS, enter instruments -s at the command prompt. After you can list the devices locally, you should be able to run test automation as if the devices are connected locally.


                    The Device Farm iOS device window

Using Spoon Test Automation to Debug Multiple Android Devices

The following screenshot shows test automation running on multiple devices on Spoon:


                    The Device Farm Android device window

Using Xcode-Build Automation to Debug Multiple iOS Devices

The following screenshot shows test automation running on multiple iOS devices on Xcode-Build:


                    Device Farm - iOS XCUITest

Debugging Web Apps

In addition to native apps, you can also debug web apps on remote devices.

Debugging Web Apps on Android

After you connect to a remote Android device in the Device Farm app, you can begin to debug your web app as follows:

  1. Open the Chrome browser on your computer and navigate to chrome://inspect#devices to see if you're connected to the remote device.

    
                            The DevTools Devices page
  2. In the Device Farm app device window, choose Interact to get a device window.

  3. Open the Chrome browser on the remote device.

  4. Open the UI for your web app, for example, www.google.com.

  5. In the Chrome browser on your computer, you should now see that Chrome is also running on the remote device:

    
                            Device Farm - Chrome inspect
  6. In the chrome://inspect#devices window on your computer, choose Inspect to open the Chrome developer tools.

    
                            Device Farm - Chrome inspect

    Here's what the tools look like:

    
                            Device Farm - Chrome inspect - device window
  7. Start debugging your app.

Debugging Web Apps on iOS

After you connect to a remote iOS device in the Device Farm app, you can begin to debug your web app as follows:

  1. Open the Safari browser on your computer.

  2. From the Develop menu, choose the entry that corresponds to your remote device.

    
                            Device Farm - Safari Web Inspector
  3. In the Device Farm app device window, choose Interact to get a device window.

  4. Open the Safari browser.

  5. Open the UI for your web app, for example, www.google.com.

  6. In the Safari window on your computer, from the Develop menu, open the UI for your web app by choosing the entry that corresponds to the remote device.

    
                            Device Farm - Safari Web Inspector

    This opens a Web Inspector window that shows the source code for the web page on the remote device:

    
                            Device Farm - Chrome inspect - device window
  7. Start debugging your app.