• Adb Change Device Serial Number

    Adb Change Device Serial Number

    Automating Android Over The ADB 21/06/18 Last update: 5 January 2018 Contents: 1. 2.1 2.2 2.3 2.4 2.5 3.

    4.1 4.2 4.3 4.4 1. Introduction T-Plan Robot Enterprise version 3.1 and higher supports automation of Android devices over the ADB (Android Debug Bridge).

    Generally speaking, the serial number as reported by adb get-serialno will be different to fastboot as determined by: Manufacturer Make and model of device in question. The XDA App is the fastest way to access the forums on mobile.

    ADB is a tool delivered as part of the Android SDK which provides connectivity to Android devices attached to the USB. Version 4.2 delivers support of screen mirroring on MS Windows which provides a better option for automation of applications requiring fast screen response such as games etc. Java -Xmx512m -classpath robot.jar;jh.jar;activation.jar;mail.jar; poi-3.6-20091214.jar; cron4j-2.2.5.jar;gson-2.5.jar;jna-3.5.1.jar;platform-3.5.1.jar;JNativeHook.jar;'C: Android Studio SDK tools lib sdklib.jar';' C: Android Studio SDK tools lib guavalib.jar ';' C: Android Studio SDK tools lib ddmlib.jar '; 'C: Android Studio SDK tools lib chimpchat.jar' com.tplan.robot.ApplicationSupport If you are using Robot packaged as an Mac OS X application and start it from the Mac menu the best option is to create symbolic links to the above libraries. Start a terminal and execute the following commands (substitute for the real path): cd /Applications/TPlanRobot.app/Contents/Java ln /tools/lib/sdklib.jar sdklib.jar ln /tools/lib/guavalib.jar guavalib.jar ln /tools/lib/ddmlib.jar ddmlib.jar ln /tools/lib/chimpchat.jar chimpchat.jar 2.2 Android Device Set Up. Enable the 'USB Debugging' option on your Android device:.

    Android 4.1 and lower: Go to Menu-Settings-Applications-Development and set on the 'USB Debugging' option. Android 4.2 and higher:. Go to Menu-Settings. Select the About menu in the More or General group. On some devices it is located under Settings-About-Software-Information-More. Scroll to Build Number and tap it 7 times until you see a message saying “You are now a developer” or ”Developer mode has been enabled”.

    Go back to the Settings menu, select the Developer Options and turn on the slider at the top to enable the options:. Set on USB Debugging.

    Set on OEM Unlocking if it's present. Set the USB Configuration option to PTP (Picture Transfer Protocol).

    The device is unlikely to connect if this option is set to MTP (Media Transfer Protocol). It is recommended to set on the Stay Awake option to prevent screen locking while the device is connected to the PC. 2.3 Connecting To Robot. Connect the Android device through the USB cable to the computer.

    It is not recommended to connect the device after the connection is initiated from Robot because it leads to intermittent connection crashes. Start T-Plan Robot Enterprise. If your system is a Linux/Unix one you will have to start it from the root account (sudo may not be sufficient). In the Login Window set the 'Connection Type' to 'Android over ADB' and provide the path to the Android SDK.

    This path will be saved to the user preferences and it will get populated automatically onwards. If you have two or more Android devices connected to the computer set the 'Device Serial No.' Field to the serial number of your device. You may find it out through clicking of the '.' Button or by executing 'adb devices' from the platform-tools/ folder of your Android SDK. Alternatively leave the field on 'default' to connect to the first detected device. T-Plan Robot Enterprise version 4.2 or higher: Select the 'Screen transfer method':.

    The 'ADB (default)' option is the slowest one but requires no additional application on the device. As the screen data is transferred over the USB cable the device doesn't have to be connected to the network. The 'Screen Stream Mirroring' option will mirror the screen using the H.264 video stream.

    See the next paragraph for instructions. Hit Connect to connect to the device. If the connection fails refer to the chapter. 2.4 Screen Stream Mirror Mirroring is an optional screen transfer method supported for Robot v4.2 or higher running on MS Windows Vista or newer. It requires to install the Screen Stream Mirr oring application by Mobzapp on the Android device. The screen data may be transferred over the network or the USB cable alone.

    Steps to enable screen mirroring:. Install the application on the Android device.

    The is OK for evaluation purposes (it displays ads and shuts down after a few minutes). Start the app to verify it works. If you are connected to a network it must display an address like 'rtsp://:5000/screen'. If the displayed URL is like 'or other than RTSP perform the following steps:. Tap the top left button.

    Select Media Players. Switch back and make sure the URL has changed appropriately. No other steps are required if your device is connected to a network visible to Robot and you prefer the screen data transfer over TCP/IP. There's no need to start the app manually prior to connecting. Should you want to avoid the network and set up the USB screen data transfer:. Start the app and tap the top left button to open the app menu.

    Choose Preferences. Scroll down to the bottom and set on 'Advanced settings'. Set on the 'Stream through USB' option and tap the top left button to save the changes. The main screen must display the address of 'rtsp://localhost:5000/screen'. 2.5 Performance Considerations Performance of the mirror stream is subject to the following factors:. Some machines are equipped with both the USB 2.0 and 3.0 ports. Make sure that the device is plugged to a 3.0 one.

    When the screen mirror is used for video transfer the data travels over the local network. The network speed affects the performance.

    Decoding of the mirror stream relies on the CPU. The graphic card (GPU) plays a very minor role.

    Upgrade the CPU to boost the performance. The RAM is not a factor as long as there is enough of it. According to our performance stats Robot mirroring a full-HD Android device needs only 50-60 MB of RAM in the idle state.

    The memory may double or triple in peaks while executing a test script with image comparison where copies of the screen image are being processed. Unless the machine is overloaded or there is little free RAM it should not be a problem.

    To verify it please observe:. Check the memory usage indicator at the right bottom corner of the Robot GUI.

    If it's in green and occasionally in yellow the program has enough RAM. If the usage is high please raise the limit as is described. Start the Windows' Task Manager and check the CPU and RAM usage. If it's too high reduce the number of other programs and/or services running on the machine. If the video is slow or lags behind considerably:. Stop Stream Screen Mirroring as well as any unnecessary applications running on the device and reconnect.

    Go to Edit-Preferences in the Robot menu. Select the Android Over ADB screen and raise the parameter called 'Process only every video frame' option. This will decrease the load and RAM required on the Robot machine.

    Animations and fast motion scenes will be blurred but still screens will retain the original image quality. Image comparison searching the screen for stable displayed components will not be affected.

    As the very last resort modify the video quality parameters in the Screen Mirroring Application. Be aware that a major decrease of the video quality is likely to break image comparison.

    Tap the gear wheel to the right from the 'Mirroring available at:' label (see the above image) and choose ' Video Preferences':. The Resolution is set to 640p. Any resolution update will lead to the screen size change which will invalidate all component images created so far.

    Avoid changing of this parameter when you already have some automation in place. The Encoding bitrate is typically 2048 kb/s. You may decrease it to save resources but don't set less than 1024 kb/s. The Max framerate is typically set to 30 fps. This limit is rarely achieved in real environments.

    You may not see any effect unless you reduce it to 2-5 fps. It is recommended to leave the default value. To apply the preferences leave the screen using the top left 'back' arrows. If mirroring is on it will restart to apply the changes.

    You will have to reconnect then. Troubleshooting To resolve issues with the Android connection take advantage of settings available under the 'Android over ADB' panel of the Edit-Preferences window:. Should you experience any issues please set on the Debug mode to produce logs. These can be viewed in the console (command prompt) or the log file through the Help-Log Viewer window. When the device screen image is distorted or displays in wrong colors change the decoding method:.

    The default 'Android SDK' decoder relies on the Android SDK to decode the image data into the Java format. This approach is known to fail for some devices, for example Samsung Galaxy GT-I5500 which displays with a greenish screen. The 'Robot' one decodes the data on its own. This method is slightly slower but seems to work for most failing devices.

    On unresolvable screen issues set on the 'Create the screen image dump' option, make an attempt to connect to create the dump and then send the log file through the Help-Log Viewer window to T-Plan Ltd support. Then set off the option. The dump will allow us to reconstruct the image from the raw pixel data and inspect why the decoder fails. If Robot fails to connect to the target device for no obvious reason and the log or the Login Window provides no reasonable explanation:. Disconnect the device from the USB cable and connect it again. Restart the ADB server manually:. Open a console/command prompt and switch to the platform-tools folder under the Android SDK installation path.

    Execute: adb kill-server adb devices. Make sure the device is listed in the output.

    If it is not there your environment is not configured properly:. Make sure the USB Debugging and other options are enabled as is described in the chapter.

    Some devices may require specific USB drivers to enable communication with the Android Studio, for example. Search documentation provided by your device vendor for details. Restart your PC after driver installation and reconnect your device even if it is not required. Should everything fail retry with another USB cable.

    Limitations of the keyboard and touch screen support are listed in the Automation chapter. Should you experience any outstanding issues please contact the T-Plan Ltd support and attach the log file. Automation 4.1 Connecting To The Device To connect to an Android device from a test script use the command (TPR scripts) or the method (Java test scripts). The argument URL must be in form of either 'adb://default' or 'adb://'. The Android SDK path must be configured prior to running the script either by providing the path in the and connecting to the device once or by setting it in the 'Android over ADB' panel of the window.

    For example, the following command/method call will connect you to the first detected device using the ADB screen transfer. TPR test scripts: Connect adb://MB104PY10519 Java test scripts: connect( 'adb:// MB104PY10519 ' ); To set on the screen mirror data transfer use: TPR test scripts: Connect adb://MB104PY10519 screen = mirror Java test scripts: connect( 'adb:// MB104PY10519 ', 'screen ', 'mirror '); Another alternative is to encode the parameters to the connect URL query. This form is also suitable for the CLI connection.

    You may copy the URL of any of your recent connections from the Tools-CLI Wizard window. Another alternative is to give your connection a name in the window and then use it instead of the URL. TPR test scripts: Connect adb://MB104PY10519?screen=mirror Java test scripts: connect( 'adb:// MB104PY10519?screen=mirror' ); 4.2 Dealing With Screen Rotation The ADB connection supports two screen rotation modes. To change the mode go to the 'Android over ADB' panel of the window. Auto screen rotation (default). In this mode the screen must be rotated in the Robot view manually (or from the script) through pressing of the F4 key. This behavior is compatible with the Droid VNC server.

    To ensure that the touch screen events are properly placed and the image comparison works as expected always keep the view in Robot consistent with the real device state: Correct view Incorrect view Search for components using the image comparison will not work and the touch screen events will be misplaced. 4.3 Touch Screen Automation The touch screen actions are mapped as follows: Device Action Computer Action Test Script Action Tap (touch) Left mouse click Call the command (TPR scripts) or one of the methods (Java scripts). Long tap (touch) Long left mouse click Call a sequence of, and Mouse release commands or the corresponding Java methods. Swipe (drag) Mouse drag (left button down) Call the command (TPR scripts) or one of the methods (Java scripts). Pinch (zooming with 2 fingers) Call the command (TPR scripts) or one of the or methods (Java scripts). Supported since Robot 3.5.

    Requires device running Android OS 4.3 or higher. Back Right mouse click Call the command (TPR scripts) or one of the methods (Java scripts). Alternatively use. Robot v3.5.2 and newer supports an option to perform mouse clicks over the UIAutomator interface. This usually resolves occasional touch screen failures for certain app controls. It requires Android 4.1.2 or newer.

    To set on the UIAutomator driven mouse clicks globally select the ' Enable click/tap over the UIAutomator API' user preference in the Edit-Preferences-Android Over ADB screen. As this gets saved to the user preferences file it will affect all Robot instances running on the local PC. The option may be tweaked for a single Robot instance through the CLI option. To control the UIAutomator clicks temporarily from the script using Robot 4.0.1 or higher set the UIACLICK variable to true ('enable') or false ('disable'). This mechanism overrides the above user preference. It has no impacts on other test scripts executing concurrently within the same Java process.

    For example, to enable it just for one particular click use: Var UIACLICK =true Mouse 'click' Var UIACLICK =false 4.4 Keyboard Automation To make the script type a text call the or commands or the / Java methods. To press a keyboard key call the command or the method. The keyboard events are supported as follows:. All printable ASCII 7-bit characters (codes 32-127) and part of the keys from the 0-31 range (Enter, Backspace.) are supported except for greater than , less than (. For example ' Press Alt+Z' generates the Euro character on some devices.

    These composed keys are subject to the device, its language and keyboard settings and they must be explored per device. The PC keyboard action keys are mapped onto the native Android keys as follows.

    Support of these keys is subject to the particular Android device and some keys may not have any effect: Android Device Key Computer/Script Key (Action) Description BACK Escape, Right mouse click Back key. CALL PageDown Call key. CAMERA F6 Camera key. Used to launch a camera application or take pictures. CLEAR F7 Clear key. DEL Backspace Backspace key.

    Deletes characters before the insertion point. DPADDOWN Down (Arrow Down), Mouse wheel down Directional Pad Down key. May also be synthesized from trackball motions.

    DPADLEFT Left (Arrow Left) Directional Pad Left key. May also be synthesized from trackball motions. DPADRIGHT Right (Arrow Right) Directional Pad Right key.

    May also be synthesized from trackball motions. DPADUP Up (Arrow Up), Mouse wheel up Directional Pad Up key. May also be synthesized from trackball motions. ENDCALL End End Call key. FOCUS F5 Camera Focus key.

    Used to focus the camera. HOME Home Home key.

    This key is handled by the framework and is never delivered to applications. MENU PageUp Menu key. NOTIFICATION F9 Notification key.

    Used to display the list of notifications. POWER F10 Power key. SEARCH F3 Search key. SOFTLEFT F1 Soft Left key.

    Usually situated below the display on phones and used as a multi-function feature key for selecting a software defined function shown on the bottom left of the display. SOFTRIGHT F2 Soft Right key.

    Adb Change Device Serial Number

    Number

    Usually situated below the display on phones and used as a multi-function feature key for selecting a software defined function shown on the bottom right of the display. SYM F8 Symbol modifier key.

    Change Device Name

    Used to enter alternate symbols. On most devices it pops up the 'Select input method' window. VOLUMEDOWN F11 Volume Down key. Adjusts the speaker volume down.

    VOLUMEUP F12 Volume Up key. Adjusts the speaker volume up.

    Adb Change Device Serial Number