├── .gitignore ├── .idea ├── .gitignore ├── compiler.xml ├── gradle.xml ├── misc.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── huruwo │ │ └── fasttest │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── huruwo │ │ │ └── fasttest │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── huruwo │ └── fasttest │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib_test_core ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── huruwo │ │ └── lib_test_core │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── huruwo │ │ │ └── lib_test_core │ │ │ ├── AutoHelper.java │ │ │ ├── TestAccessibilityService.java │ │ │ └── tools │ │ │ ├── ActionFilter.java │ │ │ ├── ActionNode.java │ │ │ └── FindNode.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── values-night │ │ └── themes.xml │ │ ├── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ │ └── xml │ │ └── accessibility.xml │ └── test │ └── java │ └── com │ └── huruwo │ └── lib_test_core │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## AndAutoBox 2 | 3 | ## 是什么 4 | 5 | 一个轻量级【简洁的免ROOT自动化Andorid端脱机测试框架】 6 | 基于无障碍服务 方便测试二次开发导入即可 7 | 8 | ### 写在前面 9 | 10 | #### 为什么要重新造轮子? 11 | 12 | 并不是 是一种补充。原本就是个人日常使用的工具。我不太喜欢那些现成的工具和框架。 13 | 明明我只想写一个轻轻的点击事件却要下载一堆文件和依赖。 14 | 又要连接电脑又要下载PC客户端,还要学会写另外一种脚本语言(js/lua/python)来契合 15 | 我是使用纯java实现一个版本 只关注点击 16 | 17 | ##### 和其他框架比有什么优势吗? 18 | 19 | 更轻量级 只专注与自动化点击测试 不需要考虑更多 20 | 21 | ### 特点 22 | 23 | 1.相对于Appium不需要链接电脑 24 | 25 | 2.相对于Auto.js更加轻量级 26 | 27 | 3.核心类只有5个,但是功能齐全 方便定制 28 | 29 | 4.纯java实现 依赖于无障碍服务 30 | 31 | 32 | ### 支持的Auto操作 33 | 34 | 1.点击事件 传入类型 35 | 36 | ```java 37 | public static boolean actionClickNode(String viewId,String text,int index,ClickAction clickAction,long sleep) 38 | ``` 39 | 40 | 2.单击 41 | 42 | ```java 43 | public static boolean performAutoClick(AccessibilityNodeInfo nodeInfo) 44 | ``` 45 | 46 | 3.双击 47 | 48 | ```java 49 | public static boolean performAutoDoubleClick(AccessibilityNodeInfo nodeInfo) 50 | ``` 51 | 52 | 4.滑动 53 | 54 | 不建议使用这个滑动 很怪 还是基于GestureDescription的path滑动好用 55 | 56 | ```java 57 | public static boolean performAutoSlide(AccessibilityNodeInfo nodeInfo, boolean direction) 58 | ``` 59 | 60 | 5.输入文本 61 | 62 | ```java 63 | public static boolean inputAutoText(AccessibilityNodeInfo nodeInfo, String text) 64 | ``` 65 | 66 | ### 一些全局操作 67 | 68 | 1.回到桌面 69 | 70 | ```java 71 | public static void goAutoHome(long sleep) 72 | ``` 73 | 74 | 2.按下返回按钮 75 | 76 | ```java 77 | public static void performAutoBack(long sleep) 78 | ``` 79 | 80 | 81 | ### 基于 GestureDescription支持的手势( 系统必须7.0以上) 82 | 83 | GestureDescription支持path和持续时间 84 | 85 | 在这个基础上可以做出很多动作 86 | 87 | 比如path只是一个点 就是单击 来两次就是双击 持续时间比较长是长按 88 | 89 | 比如path是一段段长距离的线 加上时间就是滑动 90 | 91 | 比如path是三条滑动 就可以实现类似小米那种三指截屏操作 92 | 93 | #### 1.点击任意位置point 94 | 95 | 96 | ``` 97 | public static boolean useGestureClickPoint(Point point) 98 | ``` 99 | 100 | 101 | #### 2.点击控件的中心 102 | 103 | 基于点击任意位置操作 可以点击任意控件,我们先找到控件的中心就行 104 | 105 | ```java 106 | Rect rect = new Rect(); 107 | info.getBoundsInScreen(rect); 108 | useGestureClickPoint(new Point(rect.centerX(), rect.centerY())); 109 | ``` 110 | 111 | #### 3.进阶演示基于path的操作 112 | 113 | ##### 1.miui三指截屏 114 | 115 | ##### 2.画布上绘制五边形 116 | 117 | 118 | ### 针对无id控件的优化 119 | 120 | 对于 webview 和 flutter 等框架做起来的view界面,会由于缺少对应的ViewId导致难以定位。 121 | 122 | 为此我们只能通过几种方式来确定: 123 | 124 | #### 1.文本文字确定 125 | 126 | #### 2.控件层次确定 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | } 4 | 5 | android { 6 | compileSdk 30 7 | 8 | defaultConfig { 9 | applicationId "com.huruwo.fasttest" 10 | minSdk 24 11 | targetSdk 30 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | compileOptions { 25 | sourceCompatibility JavaVersion.VERSION_1_8 26 | targetCompatibility JavaVersion.VERSION_1_8 27 | } 28 | } 29 | 30 | dependencies { 31 | 32 | implementation 'androidx.appcompat:appcompat:1.2.0' 33 | implementation 'com.google.android.material:material:1.3.0' 34 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 35 | implementation project(path: ':lib_test_core') 36 | testImplementation 'junit:junit:4.+' 37 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 38 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 39 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/huruwo/fasttest/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.huruwo.fasttest; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | assertEquals("com.huruwo.fasttest", appContext.getPackageName()); 25 | } 26 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/huruwo/fasttest/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.huruwo.fasttest; 2 | 3 | import static com.huruwo.lib_test_core.tools.ActionNode.actionPause; 4 | import static com.huruwo.lib_test_core.tools.ActionNode.mAS; 5 | 6 | import androidx.appcompat.app.AppCompatActivity; 7 | 8 | import android.content.Intent; 9 | import android.graphics.Color; 10 | import android.os.Bundle; 11 | import android.provider.Settings; 12 | import android.view.View; 13 | import android.widget.Button; 14 | import android.widget.TextView; 15 | 16 | import com.huruwo.lib_test_core.TestAccessibilityService; 17 | import com.huruwo.lib_test_core.tools.ActionNode; 18 | 19 | public class MainActivity extends AppCompatActivity { 20 | 21 | private Button button1; 22 | private Button button2; 23 | private Button button3; 24 | private TextView textView; 25 | 26 | 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_main); 32 | 33 | 34 | textView = (TextView) findViewById(R.id.textView); 35 | 36 | button1 = (Button) findViewById(R.id.button1); 37 | button2 = (Button) findViewById(R.id.button2); 38 | button3 = (Button) findViewById(R.id.button3); 39 | 40 | 41 | textView.setOnClickListener(new View.OnClickListener() { 42 | @Override 43 | public void onClick(View v) { 44 | startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)); 45 | } 46 | }); 47 | 48 | 49 | 50 | button1.setOnClickListener(view -> { 51 | 52 | new Thread(new Runnable() { 53 | @Override 54 | public void run() { 55 | ActionNode.goAutoHome(2000); 56 | ActionNode.actionClickNode("","相机",0,ActionNode.ClickAction.AutoClick,5000); 57 | ActionNode.actionClickNode("com.meizu.media.camera:id/shutter_button","",0,ActionNode.ClickAction.AutoClick,2000); 58 | } 59 | }).start(); 60 | 61 | }); 62 | 63 | 64 | button2.setOnClickListener(view -> { 65 | 66 | ActionNode.goAutoHome(2000); 67 | ActionNode.actionClickNode("","信息",0,ActionNode.ClickAction.AutoClick,2000); 68 | 69 | 70 | }); 71 | 72 | button3.setOnClickListener(view -> { 73 | 74 | }); 75 | 76 | 77 | new Thread(new Runnable() { 78 | @Override 79 | public void run() { 80 | while (true){ 81 | if(isAccessibilitySettingsOn()){ 82 | runOnUiThread(new Runnable() { 83 | @Override 84 | public void run() { 85 | textView.setText("已正常授予应用无障碍权限"); 86 | textView.setTextColor(Color.GREEN); 87 | } 88 | }); 89 | }else { 90 | runOnUiThread(new Runnable() { 91 | @Override 92 | public void run() { 93 | textView.setText("要正常运行请先授予应用无障碍权限(点击前往)"); 94 | textView.setTextColor(Color.RED); 95 | } 96 | }); 97 | } 98 | actionPause(3000); 99 | } 100 | } 101 | }).start(); 102 | 103 | } 104 | 105 | public static boolean isAccessibilitySettingsOn() { 106 | if (mAS!= null) { 107 | return true; 108 | } 109 | return false; 110 | } 111 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |