{"id":18755811,"url":"https://github.com/kasperskylab/adbserver","last_synced_at":"2025-04-13T01:57:25.319Z","repository":{"id":38364832,"uuid":"208071551","full_name":"KasperskyLab/AdbServer","owner":"KasperskyLab","description":"Adb Server for Espresso tests","archived":false,"fork":false,"pushed_at":"2022-09-29T12:56:49.000Z","size":4406,"stargazers_count":123,"open_issues_count":2,"forks_count":13,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-13T01:56:59.880Z","etag":null,"topics":["adb","espresso","kaspresso","ui-tests"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KasperskyLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null}},"created_at":"2019-09-12T14:31:32.000Z","updated_at":"2025-02-28T12:43:48.000Z","dependencies_parsed_at":"2022-08-25T04:51:39.155Z","dependency_job_id":null,"html_url":"https://github.com/KasperskyLab/AdbServer","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KasperskyLab%2FAdbServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KasperskyLab%2FAdbServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KasperskyLab%2FAdbServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KasperskyLab%2FAdbServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KasperskyLab","download_url":"https://codeload.github.com/KasperskyLab/AdbServer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654049,"owners_count":21140235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adb","espresso","kaspresso","ui-tests"],"created_at":"2024-11-07T17:34:01.481Z","updated_at":"2025-04-13T01:57:25.275Z","avatar_url":"https://github.com/KasperskyLab.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CircleCI](https://circleci.com/gh/KasperskyLab/AdbServer.svg?style=svg)](https://circleci.com/gh/KasperskyLab/AdbServer)\n\n# [DEPRECATED] Autotests Adb Server\n\nPlease, use [Kaspresso](https://github.com/KasperskyLab/Kaspresso) where AdbServer was migrated. \u003cbr\u003e\nDetailed information is available [here](https://github.com/KasperskyLab/Kaspresso/blob/master/wiki/06_AdbServer.md).\n\n## What is it?\nWhen you are writing ui-tests you need do some actions with device sometimes. \nYou may to execute a big part of those actions by [ADB](https://developer.android.com/studio/command-line/adb).\nBut Espresso doesn't contain a mechanism allowing Adb commands fulfilling although Appium does. \u003cbr\u003e \nWhy? In Espresso your app and tests are in device. In Appium your tests are in Desktop or Server. \nSo in Espresso you can't call adb because you can't call adb from inside the device. \u003cbr\u003e\nThat's why we have created **Autotests Adb Server** to compensate for the Espresso disadvantage. \u003cbr\u003e\n\u003cbr\u003e\nThe main idea of the tool is so similar with idea of Appium. \nWe need an ability to include in our tests some external thing from where we would send adb-commands to a device. \nThis external thing can be Desktop or Server. \u003cbr\u003e\nThat's why the tool is consist of two parts: **Desktop** and **Device**. \u003cbr\u003e\n**Desktop** - is the server listening commands from devices to execute adb-commands. \u003cbr\u003e\n**Device** - is the client sending commands to the server from your tests.\n\n## Usage\n\n#### Server/Desktop\nYou need to start the **Desktop** on your host (desktop/server) **before** tests' start to execute. \u003cbr\u003e\nTo start the **Desktop** please copy built library from */artifacts/desktop.jar* to convenient for you place. \u003cbr\u003e\nThe next is to execute a simple command in your host's cmd:\n```\njava -jar desktop.jar\n```\nAlso, you can set additional options as it's shown in the example below:\n```\njava -jar desktop.jar emulators=emulator-5554,emulator-5556 adbServerPort=5041\n```\nwhere: \u003cbr\u003e\nemulators - you set a list of emulators that can be captured by desktop.jar \u003cbr\u003e\nadbServerPort - you set the adb server port number (the default value is 5037)\n\n#### Device\n1) [Add `adbserver-device` dependency in your project](https://github.com/KasperskyLab/AdbServer#integration)\n2) Give permissions for an access to the Internet \n```gradle\n\u003cuses-permission android:name=\"android.permission.INTERNET\" /\u003e\n``` \n3) Use the class:\n```kotlin\nobject AdbTerminal {\n\n    fun connect() { }\n\n    fun disconnect() { }\n\n    /**\n     * Please first of all call [connect] method to establish a connection\n     */\n    fun executeAdb(command: String): CommandResult { }\n\n    /**\n     * Please first of all call [connect] method to establish a connection\n     */\n    fun executeCmd(command: String): CommandResult { }\n\n}\n```\nAs you are seeing you need to establish connection by ```connect``` method calling before to execute adb or simple cmd command. \u003cbr\u003e\nFor a reminder: adb-command is also cmd command but it starts with ```adb``` key word. \u003cbr\u003e\nAfter the session please close the connection by ```disconnect``` method. \u003cbr\u003e\n```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. \u003cbr\u003e\nAlso these methods don't throw any exception. All possible results are mapping into ```CommandResult```. \u003cbr\u003e\nAll methods of ```AdbTerminal``` may be call from any thread. \u003cbr\u003e\nSo, please observe **example** module.\n\n### Logs\nLet's consider what the developer looks in the logs on the host and the device. \u003cbr\u003e\n\n#### The host logs\n*desktop.jar* is running and waiting devices. But no one device exists in the current environment.\n```\nINFO:_____tag=MAIN______________________________________message =\u003e arguments: emulators=[], adbServerPort=null\nINFO:_____tag=Desktop___________________________________method=startDevicesObserving___________________message =\u003e start\n```\n\nThere has been new emulator in the current environment - ```emulator-5554```. \u003cbr\u003e\nThe main moment is port forwarding. \u003cbr\u003e\nNext 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).\n```\nINFO:_____tag=Desktop_________________________________method=startDevicesObserving___________________message =\u003e New device has been found: emulator-5554. Initialize connection to it...\nINFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message =\u003e calculated desktop client port=11866\nINFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=forwardPorts(fromPort=11866, toPort=8500)_message =\u003e started\nINFO:_____tag=CommandExecutorImpl_____________________method=execute_________________________________message =\u003e adbCommand=adb -s emulator-5554 forward tcp:11866 tcp:8500\nINFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=forwardPorts(fromPort=11866, toPort=8500)_message =\u003e result=CommandResult(status=SUCCESS, description=exitCode=0, message=11866\n)\nINFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message =\u003e desktop client port=11866 is forwarding with device server port=8500\nINFO:_____tag=DeviceMirror____________________________method=startConnectionToDevice_________________message =\u003e connect to device=emulator-5554 start\nINFO:_____tag=DeviceMirror.WatchdogThread_____________method=run_____________________________________message =\u003e WatchdogThread is started from Desktop to Device=emulator-5554\n```\n\nFurther, you can observer a lot of attempts to establish connection between the client and the server. \u003cbr\u003e\nIt's right behavior. Don't worry.\n```\nINFO:_____tag=DeviceMirror.WatchdogThread_____________method=run_____________________________________message =\u003e Try to connect to Device=emulator-5554...\nINFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message =\u003e start\nINFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message =\u003e start\nINFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message =\u003e current state=DISCONNECTED\nINFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message =\u003e started with ip=127.0.0.1, port=11866\nINFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message =\u003e completed with ip=127.0.0.1, port=11866\nINFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message =\u003e updated state=CONNECTED\nINFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message =\u003e start handleMessages\nINFO:_____tag=SocketMessagesTransferring______________method=startListening__________________________message =\u003e start\nERROR:____tag=SocketMessagesTransferring______________method=startListening__________________________message =\u003e java.io.EOFException\nINFO:_____tag=ConnectionServerImplBySocket____________method=tryDisconnect___________________________message =\u003e start\nINFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message =\u003e start\nINFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message =\u003e current state=CONNECTED\nINFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message =\u003e updated state=DISCONNECTING\nINFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message =\u003e updated state=DISCONNECTED\nINFO:_____tag=ConnectionServerImplBySocket____________method=tryDisconnect___________________________message =\u003e attempt completed\nINFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message =\u003e attempt completed\nINFO:_____tag=DeviceMirror.WatchdogThread_____________method=run_____________________________________message =\u003e Try to connect to Device=emulator-5554...\nINFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message =\u003e start\nINFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message =\u003e start\nINFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message =\u003e current state=DISCONNECTED\nINFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message =\u003e started with ip=127.0.0.1, port=11866\nINFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message =\u003e completed with ip=127.0.0.1, port=11866\nINFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message =\u003e updated state=CONNECTED\nINFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message =\u003e start handleMessages\nINFO:_____tag=SocketMessagesTransferring______________method=startListening__________________________message =\u003e start\nERROR:____tag=SocketMessagesTransferring______________method=startListening__________________________message =\u003e java.io.EOFException\nINFO:_____tag=ConnectionServerImplBySocket____________method=tryDisconnect___________________________message =\u003e start\nINFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message =\u003e start\nINFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message =\u003e current state=CONNECTED\nINFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message =\u003e updated state=DISCONNECTING\nINFO:_____tag=ConnectionMaker_________________________method=disconnect______________________________message =\u003e updated state=DISCONNECTED\nINFO:_____tag=ConnectionServerImplBySocket____________method=tryDisconnect___________________________message =\u003e attempt completed\nINFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message =\u003e attempt completed\n```\n\nWhen a developer runs the application containing *Device* part of AdbServer and starts this part then the connection is successfully established.\n```\nINFO:_____tag=DeviceMirror.WatchdogThread_____________method=run_____________________________________message =\u003e Try to connect to Device=emulator-5554...\nINFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message =\u003e start\nINFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message =\u003e start\nINFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message =\u003e current state=DISCONNECTED\nINFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message =\u003e started with ip=127.0.0.1, port=11866\nINFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDesktopSocketLoad____________________message =\u003e completed with ip=127.0.0.1, port=11866\nINFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message =\u003e updated state=CONNECTED\nINFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message =\u003e start handleMessages\nINFO:_____tag=SocketMessagesTransferring______________method=startListening__________________________message =\u003e start\nINFO:_____tag=SocketMessagesTransferring______________method=startListening__________________________message =\u003e IO Streams were created\nINFO:_____tag=ConnectionServerImplBySocket____________method=tryConnect______________________________message =\u003e attempt completed\nINFO:_____tag=SocketMessagesTransferring.MessagesListeningThread_method=run_____________________________________message =\u003e start to work\n```\n\nAnd an example of one command execution:\n```\nINFO:_____tag=SocketMessagesTransferring.MessagesListeningThread_method=peekNextMessage_________________________message =\u003e with message=TaskMessage(command=AdbCommand(body=shell input text 1))\nINFO:_____tag=ConnectionServerImplBySocket____________method=handleMessages__________________________message =\u003e received taskMessage=TaskMessage(command=AdbCommand(body=shell input text 1))\nINFO:_____tag=CommandExecutorImpl_____________________method=execute_________________________________message =\u003e adbCommand=adb -s emulator-5554 shell input text 1\nINFO:_____tag=ConnectionServerImplBySocket____________method=handleMessages.backgroundExecutor_______message =\u003e result of taskMessage=TaskMessage(command=AdbCommand(body=shell input text 1)) =\u003e result=CommandResult(status=SUCCESS, description=exitCode=0, message=)\nINFO:_____tag=SocketMessagesTransferring______________method=sendMessage_____________________________message =\u003e where sendModel=ResultMessage(command=AdbCommand(body=shell input text 1), data=CommandResult(status=SUCCESS, description=exitCode=0, message=))\n```\n\n#### The device logs\nThe device with *Device* part is running and waiting host with working AdbServer (*Desktop* part). But no one host exists in the current environment.\n```\nINFO:_____tag=Device__________________________________method=start___________________________________message =\u003e start\nINFO:_____tag=Device.WatchdogThread___________________method=run_____________________________________message =\u003e WatchdogThread starts from Device to Desktop\nINFO:_____tag=Device.WatchdogThread___________________method=run_____________________________________message =\u003e Try to connect to Desktop...\nINFO:_____tag=ConnectionClientImplBySocket____________method=tryConnect______________________________message =\u003e start\nINFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message =\u003e start\nINFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message =\u003e current state=DISCONNECTED\nINFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDeviceSocketLoad_____________________message =\u003e started\n```\n\nThere has been appropriate host.\n```\nINFO:_____tag=DesktopDeviceSocketConnectionForwardImplmethod=getDeviceSocketLoad_____________________message =\u003e completed\nINFO:_____tag=ConnectionMaker_________________________method=connect_________________________________message =\u003e updated state=CONNECTED\nINFO:_____tag=ConnectionClientImplBySocket____________method=tryConnect______________________________message =\u003e start handleMessages\nINFO:_____tag=SocketMessagesTransferring______________method=startListening__________________________message =\u003e start\nINFO:_____tag=SocketMessagesTransferring______________method=startListening__________________________message =\u003e IO Streams were created\nINFO:_____tag=ConnectionClientImplBySocket____________method=tryConnect______________________________message =\u003e attempt completed\nINFO:_____tag=SocketMessagesTransferring.MessagesListeningThread_method=run_____________________________________message =\u003e start to work\n```\n\nAnd an example of one command execution:\n```\nINFO:_____tag=Device__________________________________method=execute_________________________________message =\u003e Start to execute the command=AdbCommand(body=shell input text 1)\nINFO:_____tag=ConnectionClientImplBySocket____________method=executeAdbCommand_______________________message =\u003e started command=AdbCommand(body=shell input text 1)\nINFO:_____tag=SocketMessagesTransferring______________method=sendMessage_____________________________message =\u003e where sendModel=TaskMessage(command=AdbCommand(body=shell input text 1))\nINFO:_____tag=SocketMessagesTransferring.MessagesListeningThread_method=peekNextMessage_________________________message =\u003e with message=ResultMessage(command=AdbCommand(body=shell input text 1), data=CommandResult(status=SUCCESS, description=exitCode=0, message=))\nINFO:_____tag=ConnectionClientImplBySocket____________method=handleMessages__________________________message =\u003e received resultMessage=ResultMessage(command=AdbCommand(body=shell input text 1), data=CommandResult(status=SUCCESS, description=exitCode=0, message=))\nINFO:_____tag=ConnectionClientImplBySocket____________method=executeAdbCommand_______________________message =\u003e command=AdbCommand(body=shell input text 1) completed with commandResult=CommandResult(status=SUCCESS, description=exitCode=0, message=)\nINFO:_____tag=Device__________________________________method=execute_________________________________message =\u003e The result of command=AdbCommand(body=shell input text 1) =\u003e CommandResult(status=SUCCESS, description=exitCode=0, message=)\n```\n\n## Additional info\n\n[RU] [Дмитрий Мовчан, Евгений Мацюк — Как начать писать автотесты и не сойти с ума](https://youtu.be/q_8UUhVDV7c?t=1285) \u003cbr\u003e\n[RU] [Егор Курников — Единственное, что вам нужно для UI-тестирования](https://youtu.be/cTykctRSmuA?t=963) \u003cbr\u003e\n\n## Integration\n\nTo use AdbServer device library, include the `jcenter` repository to your root `build.gradle` file (if it does not exist already):\n\n```\nallprojects {\n    repositories {\n        jcenter()\n    }\n}\n```\n\nAnd then add dependency to your module `build.gradle`:\n\n```\nandroidTestImplementation 'com.kaspersky.android-components:adbserver-device:1.0.0'\n```\n\n## Support\nRussian support in telegram - t.me/kaspresso\n\n## Contribution Policy\nAdbServer is an open source project, and depends on its users to improve it. We are more than happy to find you interested in taking the project forward. \u003cbr\u003e\nKindly refer to the [Contribution Guidelines](https://github.com/KasperskyLab/AdbServer/blob/master/CONTRIBUTING.md) for detailed information.\n\n## License\nAdbServer is open source and available under the [Apache License, Version 2.0](https://github.com/KasperskyLab/AdbServer/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkasperskylab%2Fadbserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkasperskylab%2Fadbserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkasperskylab%2Fadbserver/lists"}