{"id":48581369,"url":"https://github.com/gb112211/adb-for-robotium","last_synced_at":"2026-04-08T17:02:09.964Z","repository":{"id":27910486,"uuid":"31402374","full_name":"gb112211/Adb-For-Robotium","owner":"gb112211","description":"修改Adb-For-Test项目，在Robotium中实现跨进程操作","archived":false,"fork":false,"pushed_at":"2015-12-24T04:19:54.000Z","size":17350,"stargazers_count":40,"open_issues_count":0,"forks_count":40,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-07-22T01:10:37.620Z","etag":null,"topics":["java","robotium"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gb112211.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-27T03:48:05.000Z","updated_at":"2023-04-28T06:39:11.000Z","dependencies_parsed_at":"2022-07-24T15:31:57.796Z","dependency_job_id":null,"html_url":"https://github.com/gb112211/Adb-For-Robotium","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gb112211/Adb-For-Robotium","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gb112211%2FAdb-For-Robotium","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gb112211%2FAdb-For-Robotium/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gb112211%2FAdb-For-Robotium/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gb112211%2FAdb-For-Robotium/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gb112211","download_url":"https://codeload.github.com/gb112211/Adb-For-Robotium/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gb112211%2FAdb-For-Robotium/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31564915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["java","robotium"],"created_at":"2026-04-08T17:02:09.274Z","updated_at":"2026-04-08T17:02:09.952Z","avatar_url":"https://github.com/gb112211.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# adb-For-Robotium\n修改 Adb-For-Test 项目，在 Robotium 中实现跨进程操作\n\n模拟器上无效果，需要真机并且 root。因为使用 uiautomaor 命令获取 uidump.xml 时需要 root 权限，chomd 时也需要 root 权限。\n例子可参考 CrossProcessDemo_Robotium.zip 中的例子\u003cbr\u003e\ndemo 提供者 [http://my.csdn.net/qingchunjun](http://my.csdn.net/qingchunjun)\n\n原理、使用方法及常见问题见后文。\n\n## 2015.12.23\n*\t修复一些已发现的问题\n*\t增减部分方法，增加长按、缩放、截屏等方法\n*\t修改某些方法的实现方式，具体请阅读源码\n*\t增加 readme 内容\n\n## 2015.06.08\n*\t修改 `ByText` 方法定位元素，修改后支持中文。jar包 自行用 jdk1.7 编译，如果出现 jdk 版本兼容问题，麻烦请自行重新编译下！！\n*\t有部分方法可能无法使用，后续会抽时间完善，也可自行修改源码，该项目主要传达的是一个跨进程的方法！欢迎交流\n\n## 原理\n简单的说，就是让被测应用执行 `su` 命令进行提权，被测应用在拥有 root 权限后就能执行 Android 系统中的 adb shell 命令对设备进行操作，如 input、uiautomator 等命令，因此就可在跨进程之后，调用 adb shell 命令完成类似点击、长按、缩放、截屏、元素定位等操作，最终实现跨进程操作。\n\n## 使用方法\n*\t克隆该项目至本地，或者 DownloadZip\n\t```\n\tgit clone https://github.com/gb112211/Adb-For-Robotium.git\n\t```\n\n*\t在 Eclipse 中导入该项目，或者在测试项目中引入 jar 目录中的 jar 包\n*\t调用方法及部分方法使用示例,以下图手机桌面为例，场景为在被测应用界面按下Home键返回到桌面，此时已不能通过 Solo 去控制设备\n\n\t![launcher image](/image/launcher.png)  \n初始化：\n\t```\n\tAdbDevice adb = new AdbDevice();\n\t```\n需要依靠元素定位时：\n\t```\n\tPosition position = new Position();\n\t```\n按下物理按键\n\t```\n\t//按下Home键\n\tadb.sendKeyEvent(AndroidKeyCode.HOME);\n\t//按下菜单键\n\tadb.sendKeyEvent(AndroidKeyCode.MENU);\n\t//按下返回键\n\tadb.sendKeyEvent(AndroidKeyCode.BACK);\n\t//按下电源键\n\tadb.sendKeyEvent(AndroidKeyCode.POWER);\n\t//长按Home键盘\n\tadb.longPressKey(AndroidKeyCode.HOME);\n\t//长按电源键\n\tadb.longPressKey(AndroidKeyCode.POWER);\n\t```\n点击某个位置\n\t```\n\t//通过坐标点击相机图标\n\tadb.tap(160, 1060)\n\t//通过相机图标的名称这个元素进行点击（还可通过class、resource id 等属性定位）\n\tadb.tap(position.findElementByText(\"相机\"))\n\t//长按相机图标1.5s\n\tadb.longPress(160, 1060, 1500);\n\t//或者\n\tadb.longPress(position.findElementByText(\"相机\"))\n\t```\n滑动屏幕\n\t```\n\t//左滑屏幕，持续500ms\n\tadb.swipe(900, 1060, 160, 1060, 500);\n\t或者，从“个性主题”图标位置滑动至“相机图标位置”\n\tadb.swipe(position.findElementByText(\"个性主题\"), position.findElementByText(\"相机\"), 500)\n\t```\n缩放屏幕\n\t```\n\t//第一个起始点的位置(500, 700),该点滑动至(800,400)\n\t//第二个起始点的位置(500,1200),该点滑动至(200,1600)\n\t//持续1s\n\tadb.pinchZoom(500,700,800,400,500,1200,200,1600,1000);\n\t```\n启动其它应用\n\t```\n\t//启动相机\n\tadb.startActivity(\"com.android.camera/.Camera\");\n\t```\n截屏\n\t```\n\t//截屏并保存至sd卡\n\tadb.getSceenshot().writeToFile(\"sdcard\");\n\t```\n剩余方法请查看源码。\n\n## FAQ\n*\t`java.lang.NoClassDefFoundError: com.robotium.solo.Solo`  \n\n\t解决方法：\n右键项目 \u003e Build Path \u003e Config Build Path \u003e Order and Export,\n选中 robotium 的 jar 包并勾选，点击 Top 移动到顶部。\n\n\t![robotium-bulid-path](/image/robotium_build_path.png)\n\n*\t`java.lang.NoClassDefFoundError: xuxu.autotest.element.Position`  \n\n\t解决方法：\n与上面的解决方法相同。\n\n*\t`xuxu.autotest.TestException: 未在当前界面找到元素`  \n\n\t解决方法：\n\t*\t确定是使用真机，并且使用第三方 root 软件 root，并且在 root 权限管理中对被测应用进行授权\n\t*\t确定已跳转至目标界面，使用 sdk 自带工具 uiautomatorviewer，确认需要定位的元素的属性是否有误\n\t\n\t\t![uiautomatorviewer](/image/uiautomatorviewer.png)\n\t*\t在进入目标页面进行定位之前，增加延时。\n\t\n\t\t![throttle](/image/throttle.png)\n*\t`Test run failed: Instrumentation run failed due to 'Process crashed.'`\n  \n\t解决方法：\n\n\t```\n\tF:\\git-project\u003eadb shell ps | grep com.example.crossprocessdemo\n\tu0_a464   10875 246   888732 45320 ffffffff 400468b8 S com.example.crossprocessdemo\n\n\tF:\\git-project\u003eadb shell kill 10875\n\n\t```\nWindows 如果没有 grep 命令，用 findstr 命令，杀掉未正常结束掉的被测应用进程。\n*\tEclipse 查看源码出现乱码\n\n\t解决方法：\n更改 Eclipse 的编码格式为 utf-8.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgb112211%2Fadb-for-robotium","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgb112211%2Fadb-for-robotium","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgb112211%2Fadb-for-robotium/lists"}