Skip to content

Commit 68f25bc

Browse files
committed
feat: 优化自动化测试,页面查找
1 parent c1531e7 commit 68f25bc

File tree

10 files changed

+117
-13
lines changed

10 files changed

+117
-13
lines changed

Android/app/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,9 @@ dependencies {
201201
releaseImplementation rootProject.ext.dependencies["okgo"]
202202
//高德地图定位
203203
implementation rootProject.ext.dependencies["amap_location"]
204-
//高德地图
205-
// implementation rootProject.ext.dependencies["amap_map3d"]
206204
//高德搜索
207205
implementation rootProject.ext.dependencies["amap_search"]
206+
//高德地图
208207
implementation rootProject.ext.dependencies["amap_navi"]
209208
//腾讯地图定位
210209
// implementation rootProject.ext.dependencies["tencent_location"]

Android/config.gradle

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ext {
1313
//是否使用本地仓库,需要使用绝对路径,仓库地址在 local.properties 中添加 LOCAL_REPOSITORY_URL
1414
use_local : true,
1515
group_id : 'io.github.didi.dokit',
16-
version : '3.7.2'
16+
version : '3.7.3'
1717
]
1818

1919
android = [compileSdkVersion : 29,
@@ -132,12 +132,10 @@ ext {
132132
"didi_rpc" : 'com.didichuxing.foundation:rpc:2.1.0.86',
133133
"okgo" : "com.lzy.net:okgo:3.0.4",
134134
//高德地图定位
135-
"amap_location" : 'com.amap.api:location:latest.integration',
135+
"amap_location" : 'com.amap.api:location:6.1.0',
136136
//高德地图
137-
"amap_map2d" : 'com.amap.api:map2d:latest.integration',
138-
"amap_map3d" : 'com.amap.api:map3d:latest.integration',
139-
"amap_search" : 'com.amap.api:search:latest.integration',
140-
"amap_navi" : 'com.amap.api:navi-3dmap:latest.integration',
137+
"amap_search" : 'com.amap.api:search:9.2.0',
138+
"amap_navi" : 'com.amap.api:navi-3dmap:8.1.0_3dmap8.1.0',
141139
//腾讯地图定位
142140
"tencent_location" : 'com.tencent.map.geolocation:TencentLocationSdk-openplatform:7.2.5',
143141
"tencent_map" : 'com.tencent.map:tencent-map-vector-sdk:4.4.0',

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,17 @@ object AutoTestManager {
425425
}
426426

427427
override fun onControlEventProcessFailed(activity: Activity?, view: View?, controlEvent: ControlEvent, code: Int, message: String) {
428+
// 解决轻微滑动导致的回放滑动异常问题,当作正常响应继续流程
429+
if (controlEvent.eventType == EventType.WSE_COMMON_EVENT) {
430+
controlEvent.viewC12c?.let {
431+
if (it.actionType == ActionType.ON_SCROLL) {
432+
LogHelper.e("AutoTestManager","ON_SCROLL ERROR!")
433+
onControlEventProcessSuccess(activity, view, controlEvent)
434+
return
435+
}
436+
}
437+
}
438+
428439
val msg = AutoTestMessage(command = "action_response", message = "failed")
429440
msg.params["eventId"] = controlEvent.eventId
430441
msg.params["message"] = message

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ object ControlEventManager {
2828

2929
private val controlEventProcessor: ControlEventProcessor = ControlEventProcessor()
3030

31+
private var lastEventDiffTime: Long = 0
32+
3133
fun updateEventId(id: String) {
3234
if (id.isNullOrEmpty()) {
3335
currentEventId = createNextEventId()
@@ -51,7 +53,8 @@ object ControlEventManager {
5153
fun onControlEventAction(activity: Activity?, view: View?, controlEvent: ControlEvent) {
5254
if (!onControlEventActionIntercept(activity, view, controlEvent)) {
5355
updateEventId(controlEvent.eventId)
54-
controlEvent.diffTime = getEventDiffTime()
56+
controlEvent.diffTime = lastEventDiffTime
57+
lastEventDiffTime = getEventDiffTime()
5558
onControlEventActionListenerSet.forEach {
5659
it.onControlEventAction(activity, view, controlEvent)
5760
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ data class ViewC12c(
1515
val actionName: String = ActionType.UNKNOWN.getDesc(),
1616
val params: Map<String, String> = mutableMapOf(),
1717
val windowIndex: Int = -1,
18+
val windowNode: WindowNode? = null,
1819
val viewPath: String = "",
1920
val viewPaths: MutableList<SystemViewNode>? = null,
2021
val accEventType: Int = -1,
@@ -27,5 +28,5 @@ data class ViewC12c(
2728
var inputValue: String = "",
2829
var position: Position? = null,
2930
val doKitViewNode: DoKitViewNode? = null,
30-
val doKitViewPanelNode:DoKitViewPanelNode? = null
31+
val doKitViewPanelNode: DoKitViewPanelNode? = null
3132
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.didichuxing.doraemonkit.kit.test.event
2+
3+
/**
4+
* didi Create on 2022/4/13 .
5+
*
6+
* Copyright (c) 2022/4/13 by didiglobal.com.
7+
*
8+
* @author <a href="[email protected]">zhangjun</a>
9+
* @version 1.0
10+
* @Date 2022/4/13 3:07 下午
11+
* @Description 窗口信息,帮助精确查找
12+
*/
13+
data class WindowNode(
14+
val name: String = "", //通常获取到的是 activity 的类名称
15+
val windowId: String = "",//window 唯一识别id,通过id来实现快速查找窗口
16+
val type: Int = 0,//窗口类型 0,其他,1:activity ,2:Dialog
17+
val rootViewName: String = "",
18+
var index: Int = 0
19+
20+
)

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.didichuxing.doraemonkit.kit.test.event.monitor;
22

33
import android.os.Build
44
import android.view.View
5+
import android.view.ViewParent
56
import android.view.accessibility.AccessibilityEvent
67
import android.widget.*
78
import com.didichuxing.doraemonkit.extension.tagName
@@ -106,6 +107,7 @@ object AccessibilityEventMonitor {
106107
actionName = actionType.getDesc(),
107108
accEventType = acc.eventType,
108109
windowIndex = viewRootImplIndex,
110+
windowNode = createWindowNode(view.rootView),
109111
viewPaths = ViewPathUtil.createViewPathOfWindow(view),
110112
accEventInfo = transformAccEventInfo(acc),
111113
text = if (view is TextView) {
@@ -118,6 +120,15 @@ object AccessibilityEventMonitor {
118120
)
119121
}
120122

123+
private fun createWindowNode(rootView: View): WindowNode {
124+
val windowNode: WindowNode = WindowPathUtil.createWindowNode(rootView)
125+
val parents: List<ViewParent> = WindowPathUtil.filterViewRoot(XposedHookUtil.ROOT_VIEWS)
126+
val windows: List<ViewParent> = WindowPathUtil.filterWindowViewRoot(parents, windowNode)
127+
val index = windows.indexOf(rootView.parent)
128+
windowNode.index = index
129+
return windowNode
130+
}
131+
121132
private fun createDoKitViewPanel(view: View): DoKitViewPanelNode? {
122133
if (view.rootView is DoKitFrameLayout) {
123134
val viewParents = WindowPathUtil.filterDoKitViewRoot(XposedHookUtil.ROOT_VIEWS)

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,25 @@ abstract class AbstractEventProcessor {
127127
LogHelper.e("DoKit", "findWindowRootView() check failed.")
128128
}
129129
} else {
130-
if (viewC12c.windowIndex > 0) {
131-
viewParent = WindowPathUtil.findViewRoot(XposedHookUtil.ROOT_VIEWS, viewC12c.windowIndex)
130+
if (viewC12c.windowIndex >= 0) {
131+
val windowNode = viewC12c.windowNode
132+
if (windowNode != null) {
133+
val parents: List<ViewParent> = WindowPathUtil.filterViewRoot(XposedHookUtil.ROOT_VIEWS)
134+
val windows: List<ViewParent> = WindowPathUtil.filterWindowViewRoot(parents, viewC12c.windowNode)
135+
if (windowNode.index >= 0 && windowNode.index < windows.size) {
136+
viewParent = windows[windowNode.index]
137+
} else {
138+
if (windows.isNotEmpty()) {
139+
viewParent = windows.last()
140+
}
141+
}
142+
} else {
143+
viewParent = WindowPathUtil.findViewRoot(XposedHookUtil.ROOT_VIEWS, viewC12c.windowIndex)
144+
}
132145
}
133146
}
134-
135147
return viewParent
136148
}
137149

150+
138151
}

Android/dokit-test/src/main/java/com/didichuxing/doraemonkit/kit/test/utils/WindowPathUtil.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import android.text.TextUtils;
44
import android.view.View;
55
import android.view.ViewParent;
6+
import android.view.Window;
67

78
import com.didichuxing.doraemonkit.kit.core.DoKitFrameLayout;
9+
import com.didichuxing.doraemonkit.kit.test.event.WindowNode;
10+
import com.didichuxing.doraemonkit.test.R;
11+
import com.didichuxing.doraemonkit.util.RandomUtils;
812
import com.didichuxing.doraemonkit.util.ReflectUtils;
913

1014
import java.util.ArrayList;
@@ -70,6 +74,49 @@ public static List<ViewParent> filterViewRoot(List<ViewParent> viewParents) {
7074
}
7175

7276

77+
public static List<ViewParent> filterWindowViewRoot(List<ViewParent> viewParents, WindowNode windowNode) {
78+
List<ViewParent> parents = new ArrayList<>();
79+
if (viewParents != null) {
80+
for (ViewParent parent : viewParents) {
81+
WindowNode node = createWindowNode(parent);
82+
if (TextUtils.equals(node.getName(), windowNode.getName())
83+
&& node.getType() == windowNode.getType()
84+
&& TextUtils.equals(node.getRootViewName(), windowNode.getRootViewName())) {
85+
parents.add(parent);
86+
}
87+
}
88+
}
89+
return parents;
90+
}
91+
92+
93+
public static WindowNode createWindowNode(ViewParent parent) {
94+
WindowNode windowNode;
95+
View rootView = ReflectUtils.reflect(parent).field("mView").get();
96+
windowNode = createWindowNode(rootView);
97+
return windowNode;
98+
}
99+
100+
public static WindowNode createWindowNode(View rootView) {
101+
WindowNode windowNode;
102+
Object node = rootView.getTag(R.id.dokit_test_windowNode);
103+
if (node == null) {
104+
Window window = ReflectUtils.reflect(rootView).field("mWindow").get();
105+
windowNode = new WindowNode(
106+
window.getAttributes().getTitle().toString(),
107+
RandomUtils.random16HexString(),
108+
window.getAttributes().type,
109+
rootView.getClass().getName(),
110+
0
111+
);
112+
rootView.setTag(R.id.dokit_test_windowNode, windowNode);
113+
} else {
114+
windowNode = (WindowNode) node;
115+
}
116+
return windowNode;
117+
}
118+
119+
73120
/**
74121
* 过滤出Window上的Activity 和Dialog
75122
*/

Android/dokit/src/main/res/values/ids.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@
3535
<item name="dokit_baseQuickAdapter_swiping_support" type="id"/>
3636
<item name="dokit_baseQuickAdapter_dragging_support" type="id"/>
3737
<item name="dokit_baseQuickAdapter_databinding_support" type="id"/>
38+
<item name="dokit_test_windowNode" type="id"/>
3839
</resources>

0 commit comments

Comments
 (0)