Skip to content

Commit d811d2f

Browse files
committed
feat: 有化测试控制
1 parent 122f6ff commit d811d2f

File tree

6 files changed

+130
-52
lines changed

6 files changed

+130
-52
lines changed

Android/app/src/main/java/com/didichuxing/doraemondemo/mc/MCActivity.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,23 @@ class MCActivity : AppCompatActivity() {
6464
DoKit.sendCustomEvent(
6565
"un_lock",
6666
view,
67-
mapOf("unlock" to "custom unlock")
67+
mapOf(
68+
"unlock" to "custom unlock",
69+
"testRecording" to "true"
70+
)
6871
)
6972
}
7073

7174
override fun progress(view: View?, leftMargin: Int) {
7275
DoKit.sendCustomEvent(
7376
"lock_process",
7477
view,
75-
mapOf("progress" to "$leftMargin")
78+
mapOf(
79+
"progress" to "$leftMargin",
80+
"testRecording" to "false"
81+
)
7682
)
7783
}
78-
7984
})
8085

8186
val spinner = findViewById<Spinner>(R.id.spinner)

Android/app/src/main/java/com/didichuxing/doraemondemo/test/ScreenRecordingService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.didichuxing.doraemondemo.test;
22

3+
import android.annotation.SuppressLint;
34
import android.app.Activity;
45
import android.app.Notification;
56
import android.app.NotificationChannel;
@@ -86,6 +87,7 @@ public void onDestroy() {
8687
DoKit.removeFloating(ScreenRecordingDoKitView.class);
8788
}
8889

90+
@SuppressLint("WrongConstant")
8991
@RequiresApi(api = Build.VERSION_CODES.O)
9092
@Override
9193
public int onStartCommand(Intent intent, int flags, int startId) {
@@ -127,7 +129,12 @@ public int onStartCommand(Intent intent, int flags, int startId) {
127129
int windowHeight = metrics.heightPixels;
128130
float mScreenDensity = metrics.density;
129131

130-
ImageReader mImageReader = ImageReader.newInstance(windowWidth, windowHeight, PixelFormat.RGBA_8888, 2, HardwareBuffer.USAGE_CPU_WRITE_OFTEN); //ImageFormat.RGB_565
132+
ImageReader mImageReader = null; //ImageFormat.RGB_565
133+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
134+
mImageReader = ImageReader.newInstance(windowWidth, windowHeight, PixelFormat.RGBA_8888, 2, HardwareBuffer.USAGE_CPU_WRITE_OFTEN);
135+
} else {
136+
mImageReader = ImageReader.newInstance(windowWidth, windowHeight, PixelFormat.RGBA_8888, 2);
137+
}
131138
VirtualDisplay mVirtualDisplay = mMediaProjection.createVirtualDisplay("screen-mirror",
132139
windowWidth, windowHeight, (int) mScreenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
133140
mImageReader.getSurface(), null, null);

Android/dokit-autotest/src/main/java/com/didichuxing/doraemonkit/kit/autotest/AutoTestManager.kt

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.didichuxing.doraemonkit.kit.autotest
33
import android.app.Activity
44
import android.graphics.Bitmap
55
import android.view.View
6-
import android.view.accessibility.AccessibilityEvent
76
import com.didichuxing.doraemonkit.DoKit
87
import com.didichuxing.doraemonkit.autotest.R
98
import com.didichuxing.doraemonkit.kit.autotest.ui.RecordingCaseDoKitView
@@ -116,9 +115,9 @@ object AutoTestManager {
116115
}
117116
}
118117

119-
private var diffEventTask: EventTask? = null
118+
private var diffEventTask: EventScreenShotTask? = null
120119

121-
class EventTask(private val event: ControlEvent) : Runnable {
120+
class EventScreenShotTask(private val event: ControlEvent) : Runnable {
122121
override fun run() {
123122
val state = autoTestStateSet[event.eventId]
124123
state?.let {
@@ -344,16 +343,18 @@ object AutoTestManager {
344343
webSocketClient.send(byteString)
345344
stream.close()
346345
}
347-
348-
// webSocketClient?.let {
349-
// it.send(JsonParser.toJson(PackageType.AUTOTEST, autoTestMessage, "action"))
350-
// }
351346
}
352347

353348
private fun isDiffTimeEvent(event: ControlEvent): Boolean {
354349
when (event.eventType) {
355-
EventType.WSE_CUSTOM_EVENT->{
356-
return false
350+
EventType.WSE_CUSTOM_EVENT -> {
351+
event.params?.let {
352+
var testRecording: String? = it["testRecording"]
353+
if (testRecording == "false") {
354+
return false
355+
}
356+
}
357+
return true
357358
}
358359
EventType.APP_ON_FOREGROUND,
359360
EventType.APP_ON_BACKGROUND,
@@ -362,22 +363,10 @@ object AutoTestManager {
362363
}
363364
EventType.WSE_COMMON_EVENT -> {
364365
event.viewC12c?.let {
365-
when (it.accEventType) {
366-
//点击
367-
AccessibilityEvent.TYPE_VIEW_CLICKED,
368-
//长按
369-
AccessibilityEvent.TYPE_VIEW_LONG_CLICKED,
370-
//滚动
371-
AccessibilityEvent.TYPE_VIEW_SCROLLED -> {
372-
return true
373-
}
374-
else -> {
375-
376-
}
377-
}
378366
when (it.actionType) {
379367
ActionType.ON_LONG_CLICK,
380368
ActionType.ON_SCROLL,
369+
ActionType.ON_INPUT_CHANGE,
381370
ActionType.ON_CLICK -> {
382371
return true
383372
}
@@ -391,6 +380,29 @@ object AutoTestManager {
391380
return false
392381
}
393382

383+
384+
private fun getDiffTimeByEvent(event: ControlEvent, diffTime: Long): Long {
385+
when (event.eventType) {
386+
EventType.WSE_COMMON_EVENT -> {
387+
event.viewC12c?.let {
388+
when (it.actionType) {
389+
ActionType.ON_SCROLL,
390+
ActionType.ON_INPUT_CHANGE -> {
391+
return if (diffTime > 100){
392+
diffTime
393+
}else{
394+
100
395+
}
396+
}
397+
else -> {
398+
}
399+
}
400+
}
401+
}
402+
}
403+
return 1000
404+
}
405+
394406
/**
395407
* 接收到自动化测试事件
396408
*/
@@ -400,11 +412,11 @@ object AutoTestManager {
400412

401413
if (isDiffTimeEvent(event)) {
402414
val diff: Long = if (event.diffTime < 1000) {
403-
1000
415+
getDiffTimeByEvent(event, event.diffTime)
404416
} else {
405417
event.diffTime
406418
}
407-
val eventTask = EventTask(event)
419+
val eventTask = EventScreenShotTask(event)
408420
diffEventTask = eventTask
409421
delayHandler.postDelayed(eventTask, diff)
410422
}

Android/dokit-mc/src/main/java/com/didichuxing/doraemonkit/kit/mc/AbstractMultiController.kt

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.didichuxing.doraemonkit.kit.mc
22

33
import android.graphics.Bitmap
4-
import android.view.accessibility.AccessibilityEvent
54
import com.didichuxing.doraemonkit.kit.connect.data.PackageType
65
import com.didichuxing.doraemonkit.kit.connect.parser.ByteParser
76
import com.didichuxing.doraemonkit.kit.connect.parser.JsonParser
@@ -52,10 +51,32 @@ abstract class AbstractMultiController(private val webSocketClient: WebSocketCli
5251
lastControlEvent = controlEvent
5352
val task = EventTask(controlEvent)
5453
screenShotEventTask = task
55-
delayHandler.postDelayed(task, 1000)
54+
delayHandler.postDelayed(task, getDiffTimeByEvent(controlEvent,0))
5655
}
5756
}
5857

58+
private fun getDiffTimeByEvent(event: ControlEvent, diffTime: Long): Long {
59+
when (event.eventType) {
60+
EventType.WSE_COMMON_EVENT -> {
61+
event.viewC12c?.let {
62+
when (it.actionType) {
63+
ActionType.ON_SCROLL,
64+
ActionType.ON_INPUT_CHANGE -> {
65+
return if (diffTime > 100){
66+
diffTime
67+
}else{
68+
100
69+
}
70+
}
71+
else -> {
72+
}
73+
}
74+
}
75+
}
76+
}
77+
return 1000
78+
}
79+
5980
/**
6081
* 从机事件处理结果
6182
*/
@@ -97,30 +118,26 @@ abstract class AbstractMultiController(private val webSocketClient: WebSocketCli
97118

98119
private fun isDiffTimeEvent(controlEvent: ControlEvent): Boolean {
99120
when (controlEvent.eventType) {
100-
EventType.WSE_CUSTOM_EVENT,
121+
EventType.WSE_CUSTOM_EVENT -> {
122+
controlEvent.params?.let {
123+
var testRecording: String? = it["testRecording"]
124+
if (testRecording == "false") {
125+
return false
126+
}
127+
}
128+
return true
129+
}
101130
EventType.APP_ON_FOREGROUND,
102131
EventType.APP_ON_BACKGROUND,
103132
EventType.ACTIVITY_BACK_PRESSED -> {
104133
return true
105134
}
106135
EventType.WSE_COMMON_EVENT -> {
107136
controlEvent.viewC12c?.let {
108-
when (it.accEventType) {
109-
//点击
110-
AccessibilityEvent.TYPE_VIEW_CLICKED,
111-
//长按
112-
AccessibilityEvent.TYPE_VIEW_LONG_CLICKED,
113-
//滚动
114-
AccessibilityEvent.TYPE_VIEW_SCROLLED -> {
115-
return true
116-
}
117-
else -> {
118-
119-
}
120-
}
121137
when (it.actionType) {
122138
ActionType.ON_LONG_CLICK,
123139
ActionType.ON_SCROLL,
140+
ActionType.ON_INPUT_CHANGE,
124141
ActionType.ON_CLICK -> {
125142
return true
126143
}

Android/dokit-test/src/main/java/com/didichuxing/doraemonkit/kit/test/event/ActionType.kt

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.didichuxing.doraemonkit.kit.test.event
22

3+
import android.view.accessibility.AccessibilityEvent
4+
35

46
/**
57
* didi Create on 2022/4/13 .
@@ -20,6 +22,7 @@ enum class ActionType(private val id: Int, private val nameText: String) {
2022
ON_SCROLL(3, "滑动"),
2123
ON_FOCUS_CHANGE(4, "焦点改变"),
2224
ON_INPUT_CHANGE(5, "输入"),
25+
ON_INPUT_SELECTION_CHANGE(5, "输入光标位置"),
2326
ON_TOUCH(6, "TOUCH"),
2427
ON_TOUCH_START(7, "TOUCH START"),
2528
ON_TOUCH_END(8, "TOUCH END"),
@@ -28,7 +31,7 @@ enum class ActionType(private val id: Int, private val nameText: String) {
2831
ON_CUSTOM_EVENT(30, "自定义");
2932

3033

31-
val map:Map<Int,ActionType> = mutableMapOf()
34+
val map: Map<Int, ActionType> = mutableMapOf()
3235

3336
fun getID(): Int {
3437
return id
@@ -37,4 +40,41 @@ enum class ActionType(private val id: Int, private val nameText: String) {
3740
fun getDesc(): String {
3841
return nameText
3942
}
43+
44+
companion object {
45+
fun valueOf(acc: AccessibilityEvent): ActionType {
46+
47+
var actionType: ActionType
48+
when (acc.eventType) {
49+
AccessibilityEvent.TYPE_VIEW_CLICKED -> {
50+
actionType = ON_CLICK
51+
}
52+
AccessibilityEvent.TYPE_VIEW_LONG_CLICKED -> {
53+
actionType = ON_LONG_CLICK
54+
}
55+
AccessibilityEvent.TYPE_VIEW_SCROLLED -> {
56+
actionType = ON_SCROLL
57+
}
58+
AccessibilityEvent.TYPE_VIEW_FOCUSED -> {
59+
actionType = ON_FOCUS_CHANGE
60+
}
61+
AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED -> {
62+
actionType = ON_INPUT_CHANGE
63+
}
64+
AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED -> {
65+
actionType = ON_INPUT_SELECTION_CHANGE
66+
}
67+
AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED -> {
68+
actionType = UNKNOWN
69+
}
70+
AccessibilityEvent.TYPE_VIEW_SELECTED -> {
71+
actionType = UNKNOWN
72+
}
73+
else -> {
74+
actionType = UNKNOWN
75+
}
76+
}
77+
return actionType
78+
}
79+
}
4080
}

Android/dokit-test/src/main/java/com/didichuxing/doraemonkit/kit/test/event/monitor/AccessibilityEventMonitor.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ import android.widget.*
77
import com.didichuxing.doraemonkit.extension.tagName
88
import com.didichuxing.doraemonkit.kit.core.DokitFrameLayout
99
import com.didichuxing.doraemonkit.kit.test.DoKitTestManager
10-
import com.didichuxing.doraemonkit.kit.test.event.ControlEventManager
10+
import com.didichuxing.doraemonkit.kit.test.event.*
1111
import com.didichuxing.doraemonkit.kit.test.utils.XposedHookUtil
12-
import com.didichuxing.doraemonkit.kit.test.event.ControlEvent
13-
import com.didichuxing.doraemonkit.kit.test.event.AccessibilityEventNode
14-
import com.didichuxing.doraemonkit.kit.test.event.DoKitViewNode
15-
import com.didichuxing.doraemonkit.kit.test.event.ViewC12c
16-
import com.didichuxing.doraemonkit.kit.test.event.EventType
1712
import com.didichuxing.doraemonkit.kit.test.utils.ViewPathUtil
1813
import com.didichuxing.doraemonkit.kit.test.utils.WindowPathUtil
1914
import com.didichuxing.doraemonkit.util.ConvertUtils
@@ -79,7 +74,6 @@ object AccessibilityEventMonitor {
7974
}
8075

8176
private fun onViewHandleEvent(view: View, accessibilityEvent: AccessibilityEvent) {
82-
8377
val activity = ViewPathUtil.getActivity(view)
8478
val actionId = ControlEventManager.createNextEventId()
8579
val viewC12c: ViewC12c = createViewC12c(view, accessibilityEvent)
@@ -106,7 +100,10 @@ object AccessibilityEventMonitor {
106100
it.indexOf(view.rootView.parent)
107101
}
108102
}
103+
val actionType: ActionType = ActionType.valueOf(acc)
109104
return ViewC12c(
105+
actionType = actionType,
106+
actionName = actionType.getDesc(),
110107
accEventType = acc.eventType,
111108
windowIndex = viewRootImplIndex,
112109
viewPaths = ViewPathUtil.createViewPathOfWindow(view),

0 commit comments

Comments
 (0)