|The information below concerns legacy mobile tests that work with mobile devices connected to the local computer. For new mobile tests, we recommend using the newer cloud-compatible approach.
TestComplete works with Android applications via Android Debug Bridge (ADB). Before you start test creation or playback, you should connect ADB to your Android device or virtual machine. This will make the device (or machine) available to TestComplete too. This topic explains details of the connection procedure.
|Android emulators do not require connection steps. Run the emulator, and TestComplete will access it automatically.
In This Topic
When Do You Need to Connect?
Connect before you start working with your device from TestComplete. For example, before you start recording or running tests for the first time or before you view the application in the Mobile Screen or explore in the Object Browser. There is no need to set up the connection before each test run or before each test recording. You can do that once in your operating system’s user session and use the existing connection until it is broken.
Connecting Physical Devices
1. Prepare Device and TestComplete
Make sure your mobile device has been prepared for testing as it is described in TestComplete documentation. Remember to enable the developer settings on the device and install device drivers on your computer if necessary. See Preparing Physical Android Devices for Testing (Legacy).
Make sure you have installed Android SDK on your computer and specified the path to it in TestComplete settings. See Preparing Test Computers and TestComplete for Android Testing (Legacy).
2. Connect the Device
You can connect a physical device via USB or Wi-Fi.
Turn on your device and connect it to your computer with a USB cable. Android Debug Bridge will detect the connection and will automatically connect to the device.
By default, the debug service on a device is configured to work via USB. You need to configure it to accept commands via TCP/IP:
Turn on your device, enable Wi-Fi on it and connect the device to your local network via Wi-Fi.
Explore Wi-Fi settings on the device to find out the device IP address. Write down or remember the device IP address.
The actual search steps to perform depend on your device and the Android version it has. Typically, you open Wi-Fi settings on the device and tap the Wi-Fi connection that you set up – Android will display the connection details including the IP address your device got. For more information, please see documentation on your device and Android version.
Important: Connect your device to your computer via USB cable.
On your computer, press Win+R to open the Run dialog, and then type
cmdand press Enter to open the Windows command prompt.
Run the following command in the command prompt. Make sure to replace <Android SDK> with the path to Android SDK on your computer:
<Android SDK>\platform-tools\adb tcpip port-number
This command tells the debug service on your device to listen to debug commands on the specified TCP port. You can enter any port that is free on your device, but we would recommend using default port
Note: The example above implies that you have only one device connected to your computer via USB. If you have multiple devices, you need to specify the device for the
More information on this is available in Android documentation (https://developer.android.com/studio/command-line/adb.html#directingcommands).
In the command prompt, run the
adb connectcommand to connect to your device:
<Android SDK>\platform-tools\adb connect your-device-IP:port
c:\android-sdk\platform-tools\adb connect 192.168.0.34:5555
Important: After ADB connects to your device via Wi-Fi, disconnect the USB cable. If you keep the cable plugged in, ADB will recognize two devices instead of one, which may cause errors during testing.
Also, it is important that you plug the device in to a power outlet. This will prevent accumulator discharge and screen blackout during testing. (Despite the fact you enabled the Stay awake option on your device that disables screen blackout, many Android systems ignore this option if there is no USB connection).
When do I need to repeat these steps? Repeat them every time the connection between the device and the Debug Bridge running on your computer is lost. For example, after you reboot your computer, or after you stop the ADB service running on it, after your device loses the Wi-Fi connection to your network, and so on.
Some devices may require a restart to switch from the Wi-Fi mode back to the USB one.
During test recording, TestComplete is actively exchanging data with the tested Android application. In case your physical device is connected via Wi-Fi, the data goes through your local network. You might experience some slowdown when interacting with the tested application, especially, if your local network is busy. So, we would recommend recording tests on USB-connected devices, and use Wi-Fi connections for test runs.
Connecting Virtual Machines
1. Prepare Virtual Machine and TestComplete
Make sure your Android virtual machine has been prepared for testing as it is described in TestComplete documentation. Make sure it is available in your local network and accessible for TestComplete. See Preparing Android Virtual Machines for Testing (Legacy).
Make sure you installed Android SDK on your computer and specified the path to it in TestComplete settings. See Preparing Test Computers and TestComplete for Android Testing (Legacy).
2. Get the IP Address of the Virtual Machine
Start your virtual machine and wait until Android is loaded.
In the virtual machine screen, press Alt+F1. This will open the console.
netcfgin the command line and press Enter. This will display network addresses assigned to your virtual machine. For example:
A N D R O I D root@x86:/ # netcfg
ip6tn10 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00
sit0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00
eth0 UP 192.168.56.101/24 0x00001043 08:00:27:eb:38:d9
lo UP 127.0.0.1/8 0x00000049 00:00:00:00:00:00
root@x86:/ # _
Copy or write down the IP address (in the example above it is 192.168.56.101).
Press Alt+F7 to return back to the graphic mode if necessary.
3. Connect the Android Debug Bridge to the Virtual Machine
On your computer, press Win+R to open the Run dialog. In the Run dialog, type
cmdand press Enter. This will open Windows command prompt.
Run the following command in the command prompt. Make sure to replace <Android SDK> with the path to Android SDK on your computer and specify the actual IP address of your virtual machine that you got on the previous step:
<Android SDK>\platform-tools\adb connect 192.168.56.101
Now the virtual machine is connected to Android Debug Bridge and TestComplete.
Checking the Connection
Using TestComplete IDE
If you are working with one device or virtual machine, the fastest and easiest way to check whether the device or virtual machine is connected to Android Debug Bridge is to click the Show Mobile Screen toolbar item in the TestComplete IDE. The Mobile Screen window will open if at least one mobile device or virtual machine is connected to the Bridge.
If you have several devices or virtual machines connected, a click on the Show Mobile Screen item will open the Select Local Device dialog. In the dialog, specify the needed device to view its screen.
If the Mobile Screen window is visible, the newly connected devices are added to the drop-down list on its toolbar.
Using the ADB Devices Command
Alternatively, you can check if your device is listed in the output of the
adb devices command (
adb being the name of the Android Debug Bridge executable). To do this:
On your computer, press Win+R to open the Run dialog.
In the Run dialog, type
cmdand press Enter. This will open Windows command prompt.
Enter the following command in the command prompt (replace <Android SDK> with the path to Android SDK on your computer) and press Enter:
<Android SDK>\platform-tools\adb devices
This will display a list of physical and virtual devices connected to ADB. Physical devices connected via USB are specified by their serial number, devices connected via Wi-Fi – by the IP address, virtual machines - by the IP address, emulators - by an identifier in the emulator-port format. For example:
List of devices attached
Check whether your device is on the list.