AdbServer
Adb Server for Espresso tests
Install / Use
/learn @KasperskyLab/AdbServerREADME
[DEPRECATED] Autotests Adb Server
Please, use Kaspresso where AdbServer was migrated. <br> Detailed information is available here.
What is it?
When you are writing ui-tests you need do some actions with device sometimes. You may to execute a big part of those actions by ADB. But Espresso doesn't contain a mechanism allowing Adb commands fulfilling although Appium does. <br> Why? In Espresso your app and tests are in device. In Appium your tests are in Desktop or Server. So in Espresso you can't call adb because you can't call adb from inside the device. <br> That's why we have created Autotests Adb Server to compensate for the Espresso disadvantage. <br> <br> The main idea of the tool is so similar with idea of Appium. We need an ability to include in our tests some external thing from where we would send adb-commands to a device. This external thing can be Desktop or Server. <br> That's why the tool is consist of two parts: Desktop and Device. <br> Desktop - is the server listening commands from devices to execute adb-commands. <br> Device - is the client sending commands to the server from your tests.
Usage
Server/Desktop
You need to start the Desktop on your host (desktop/server) before tests' start to execute. <br> To start the Desktop please copy built library from /artifacts/desktop.jar to convenient for you place. <br> The next is to execute a simple command in your host's cmd:
java -jar desktop.jar
Also, you can set additional options as it's shown in the example below:
java -jar desktop.jar emulators=emulator-5554,emulator-5556 adbServerPort=5041
where: <br> emulators - you set a list of emulators that can be captured by desktop.jar <br> adbServerPort - you set the adb server port number (the default value is 5037)
Device
- Add
adbserver-devicedependency in your project - Give permissions for an access to the Internet
<uses-permission android:name="android.permission.INTERNET" />
- Use the class:
object AdbTerminal {
fun connect() { }
fun disconnect() { }
/**
* Please first of all call [connect] method to establish a connection
*/
fun executeAdb(command: String): CommandResult { }
/**
* Please first of all call [connect] method to establish a connection
*/
fun executeCmd(command: String): CommandResult { }
}
As you are seeing you need to establish connection by connect method calling before to execute adb or simple cmd command. <br>
For a reminder: adb-command is also cmd command but it starts with adb key word. <br>
After the session please close the connection by disconnect method. <br>
executeAdb and executeCmd are synchronous methods to not reorder a line of commands because if commands were completed in incorrect order it may to lead inconsistent state of the app and the device. <br>
Also these methods don't throw any exception. All possible results are mapping into CommandResult. <br>
All methods of AdbTerminal may be call from any thread. <br>
So, please observe example module.
Logs
Let's consider what the developer looks in the logs on the host and the device. <br>
The host logs
desktop.jar is running and waiting devices. But no one device exists in the current environment.
INFO:_____tag=MAIN______________________________________message => arguments: emulators=[], adbServerPort=null
INFO:_____tag=Desktop___________________________________method=startDevicesObserving___________________message => start
There has been new emulator in the current environment - emulator-5554. <br>
The main moment is port forwarding. <br>
Next step is a WatchdogThread's start that is responsible to establish socket connection between the client (the host forwarded to device port) and the server (the device).
INFO:_____tag=Desktop_________________________________method=startDevicesObserving___________________message => New device has been found: emulator-5554. Initialize connection to it...
INFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message => calculated desktop client port=11866
INFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=forwardPorts(fromPort=11866, toPort=8500)_message => started
INFO:_____tag=CommandExecutorImpl_____________________method=execute_________________________________message => adbCommand=adb -s emulator-5554 forward tcp:11866 tcp:8500
INFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=forwardPorts(fromPort=11866, toPort=8500)_message => result=CommandResult(status=SUCCESS, description=exitCode=0, message=11866
)
INFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message => desktop client port=11866 is forwarding with device server port=8500
INFO:_____tag=DeviceMirror____________________________method=startConnectionToDevice_________________message => connect to device=emulator-5554 start
INFO:_____tag=DeviceMirror.WatchdogThread_____________method=run_____________________________________message => WatchdogThread is started from Desktop to Device=emulator-5554
Further, you can observer a lot of attempts to establish connection between the client and the server. <br> It's right behavior. Don't worry.
INFO:_____tag=DeviceMirror.WatchdogThread_____________method=run_____________________________________message => Try to connect to Device=emulator-5554...
INFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message => start
INFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message => start
INFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message => current state=DISCONNECTED
INFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message => started with ip=127.0.0.1, port=11866
INFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message => completed with ip=127.0.0.1, port=11866
INFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message => updated state=CONNECTED
INFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message => start handleMessages
INFO:_____tag=SocketMessagesTransferring______________method=startListening__________________________message => start
ERROR:____tag=SocketMessagesTransferring______________method=startListening__________________________message => java.io.EOFException
INFO:_____tag=ConnectionServerImplBySocket____________method=tryDisconnect___________________________message => start
INFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message => start
INFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message => current state=CONNECTED
INFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message => updated state=DISCONNECTING
INFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message => updated state=DISCONNECTED
INFO:_____tag=ConnectionServerImplBySocket____________method=tryDisconnect___________________________message => attempt completed
INFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message => attempt completed
INFO:_____tag=DeviceMirror.WatchdogThread_____________method=run_____________________________________message => Try to connect to Device=emulator-5554...
INFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message => start
INFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message => start
INFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message => current state=DISCONNECTED
INFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message => started with ip=127.0.0.1, port=11866
INFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message => completed with ip=127.0.0.1, port=11866
INFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message => updated state=CONNECTED
INFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message => start handleMessages
INFO:_____tag=SocketMessagesTransferring______________method=startListening__________________________message => start
ERROR:____tag=SocketMessagesTransferring______________method=startListening__________________________message => java.io.EOFException
INFO:_____tag=ConnectionServerImplBySocket____________method=tryDisconnect___________________________message => start
INFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message => start
INFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message => current state=CONNECTED
INFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message => updated state=DISCONNECTING
INFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message => updated state=D
Related Skills
node-connect
339.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.8kCommit, push, and open a PR
