appium-espresso-driver 9.3.12 → 9.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/espresso-server/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk +0 -0
- package/espresso-server/buildSrc/.gradle/9.7.1/executionHistory/executionHistory.bin +0 -0
- package/espresso-server/buildSrc/.gradle/9.7.1/executionHistory/executionHistory.lock +0 -0
- package/espresso-server/buildSrc/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/espresso-server/buildSrc/.gradle/buildOutputCleanup/cache.properties +1 -1
- package/espresso-server/buildSrc/build/kotlin/compileKotlin/cacheable/last-build.bin +0 -0
- package/espresso-server/library/src/composeOff/java/io/appium/espressoserver/lib/compose/ComposeHandlerBridge.kt +8 -0
- package/espresso-server/library/src/composeOn/java/io/appium/espressoserver/lib/compose/ComposeHandlerBridge.kt +38 -0
- package/espresso-server/library/src/composeOn/java/io/appium/espressoserver/lib/compose/ComposeResourceIds.kt +83 -0
- package/espresso-server/library/src/composeOn/java/io/appium/espressoserver/lib/http/Server.kt +8 -0
- package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/handlers/Keys.kt +3 -1
- package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/handlers/PerformAction.kt +21 -1
- package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/helpers/SizeHelpers.kt +11 -0
- package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/helpers/Version.kt +1 -1
- package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/helpers/w3c/adapter/espresso/AndroidKeyEvent.kt +4 -2
- package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/helpers/w3c/adapter/espresso/EspressoW3CActionAdapter.kt +9 -1
- package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/helpers/w3c/adapter/espresso/NonAsciiTextInserter.kt +15 -7
- package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/helpers/w3c/dispatcher/W3CKeyEvent.kt +3 -1
- package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/helpers/w3c/state/KeyInputState.kt +1 -1
- package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/http/Router.kt +6 -1
- package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/viewaction/UiControllerPerformer.kt +8 -0
- package/espresso-server/library/src/test/java/io/appium/espressoserver/test/helpers/WindowOriginTest.kt +51 -0
- package/espresso-server/library/src/test/java/io/appium/espressoserver/test/helpers/w3c/adapter/AndroidKeyEventTest.kt +22 -1
- package/espresso-server/library/src/test/java/io/appium/espressoserver/test/helpers/w3c/adapter/KeyLogRedactionTest.kt +33 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [9.3.13](https://github.com/appium/appium-espresso-driver/compare/v9.3.12...v9.3.13) (2026-11-04)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* **server:** make W3C actions work in compose mode ([#1241](https://github.com/appium/appium-espresso-driver/issues/1241)) ([c8a6e59](https://github.com/appium/appium-espresso-driver/commit/c8a6e599a286214ef792a7d09f3ec58cf1a94ecf))
|
|
6
|
+
|
|
1
7
|
## [9.3.12](https://github.com/appium/appium-espresso-driver/compare/v9.3.11...v9.3.12) (2026-11-03)
|
|
2
8
|
|
|
3
9
|
### Bug Fixes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#
|
|
1
|
+
#Wed Nov 04 06:38:06 UTC 2026
|
|
2
2
|
gradle.version=9.7.1
|
|
Binary file
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
package io.appium.espressoserver.lib.compose
|
|
18
18
|
|
|
19
|
+
import android.graphics.Point
|
|
20
|
+
import android.view.View
|
|
19
21
|
import io.appium.espressoserver.lib.handlers.exceptions.ComposeNotSupportedException
|
|
20
22
|
import io.appium.espressoserver.lib.model.AppiumParams
|
|
21
23
|
import io.appium.espressoserver.lib.model.BaseElement
|
|
@@ -29,6 +31,12 @@ import io.appium.espressoserver.lib.model.TextValueParams
|
|
|
29
31
|
internal object ComposeHandlerBridge {
|
|
30
32
|
private fun unsupported(): Nothing = throw ComposeNotSupportedException()
|
|
31
33
|
|
|
34
|
+
fun hasFocusedEditableNode(view: View): Boolean = false
|
|
35
|
+
|
|
36
|
+
fun insertTextIntoFocusedNode(view: View, text: String): Boolean = false
|
|
37
|
+
|
|
38
|
+
fun getElementCenterPoint(elementId: String?): Point = unsupported()
|
|
39
|
+
|
|
32
40
|
fun findElement(params: Locator): BaseElement = unsupported()
|
|
33
41
|
|
|
34
42
|
fun findElements(params: Locator): List<BaseElement> = unsupported()
|
|
@@ -16,6 +16,15 @@
|
|
|
16
16
|
|
|
17
17
|
package io.appium.espressoserver.lib.compose
|
|
18
18
|
|
|
19
|
+
import android.graphics.Point
|
|
20
|
+
import android.view.View
|
|
21
|
+
import androidx.compose.ui.semantics.SemanticsActions
|
|
22
|
+
import androidx.compose.ui.semantics.SemanticsNode
|
|
23
|
+
import androidx.compose.ui.semantics.SemanticsProperties
|
|
24
|
+
import androidx.compose.ui.semantics.getAllSemanticsNodes
|
|
25
|
+
import androidx.compose.ui.semantics.getOrNull
|
|
26
|
+
import androidx.compose.ui.text.AnnotatedString
|
|
27
|
+
import androidx.compose.ui.platform.ViewRootForTest
|
|
19
28
|
import androidx.compose.ui.test.assertIsDisplayed
|
|
20
29
|
import androidx.compose.ui.test.performClick
|
|
21
30
|
import androidx.compose.ui.test.performGesture
|
|
@@ -34,6 +43,7 @@ import io.appium.espressoserver.lib.helpers.AndroidLogger
|
|
|
34
43
|
import io.appium.espressoserver.lib.helpers.getNodeInteractionById
|
|
35
44
|
import io.appium.espressoserver.lib.helpers.getSemanticsNode
|
|
36
45
|
import io.appium.espressoserver.lib.helpers.toNodeInteractionsCollection
|
|
46
|
+
import io.appium.espressoserver.lib.helpers.windowOriginOnScreen
|
|
37
47
|
import io.appium.espressoserver.lib.model.AppiumParams
|
|
38
48
|
import io.appium.espressoserver.lib.model.BaseElement
|
|
39
49
|
import io.appium.espressoserver.lib.model.ComposeElement
|
|
@@ -46,6 +56,34 @@ import io.appium.espressoserver.lib.model.Size
|
|
|
46
56
|
import io.appium.espressoserver.lib.model.TextValueParams
|
|
47
57
|
|
|
48
58
|
internal object ComposeHandlerBridge {
|
|
59
|
+
fun hasFocusedEditableNode(view: View): Boolean = findFocusedEditableNode(view) != null
|
|
60
|
+
|
|
61
|
+
/** Inserts at the cursor of the focused Compose text field; must run on the main thread. */
|
|
62
|
+
fun insertTextIntoFocusedNode(view: View, text: String): Boolean =
|
|
63
|
+
findFocusedEditableNode(view)
|
|
64
|
+
?.config?.getOrNull(SemanticsActions.InsertTextAtCursor)?.action
|
|
65
|
+
?.invoke(AnnotatedString(text)) ?: false
|
|
66
|
+
|
|
67
|
+
private fun findFocusedEditableNode(view: View): SemanticsNode? =
|
|
68
|
+
(view as? ViewRootForTest)?.semanticsOwner?.getAllSemanticsNodes(true)?.firstOrNull {
|
|
69
|
+
it.config.getOrNull(SemanticsProperties.Focused) == true &&
|
|
70
|
+
it.config.contains(SemanticsActions.InsertTextAtCursor)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
fun getElementCenterPoint(elementId: String?): Point {
|
|
74
|
+
val node = try {
|
|
75
|
+
getNodeInteractionById(elementId).fetchSemanticsNode()
|
|
76
|
+
} catch (e: AssertionError) {
|
|
77
|
+
throw StaleElementException(elementId ?: "null")
|
|
78
|
+
}
|
|
79
|
+
val bounds = ComposeNodeElement(node).bounds
|
|
80
|
+
val root = node.root as? ViewRootForTest
|
|
81
|
+
?: throw InvalidElementStateException("The element is not attached to a window")
|
|
82
|
+
// The bounds are relative to the window, not to the (possibly offset) Compose view
|
|
83
|
+
val windowOrigin = root.view.windowOriginOnScreen()
|
|
84
|
+
return Point(windowOrigin.x + bounds.centerX(), windowOrigin.y + bounds.centerY())
|
|
85
|
+
}
|
|
86
|
+
|
|
49
87
|
fun findElement(params: Locator): BaseElement {
|
|
50
88
|
val nodeInteractions = toNodeInteractionsCollection(params)
|
|
51
89
|
if (nodeInteractions.fetchSemanticsNodes(false).isEmpty()) {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
* you may not use this file except in compliance with the License.
|
|
4
|
+
* See the NOTICE file distributed with this work for additional
|
|
5
|
+
* information regarding copyright ownership.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
package io.appium.espressoserver.lib.compose
|
|
18
|
+
|
|
19
|
+
import android.content.res.Resources
|
|
20
|
+
import androidx.test.platform.app.InstrumentationRegistry
|
|
21
|
+
import dalvik.system.DexFile
|
|
22
|
+
import io.appium.espressoserver.lib.helpers.AndroidLogger
|
|
23
|
+
import java.lang.reflect.Modifier
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The server APK comes first on the class path, so its generated Compose `R` classes shadow
|
|
27
|
+
* the app's ones and hold IDs that do not exist in the app. This makes Compose fail to resolve
|
|
28
|
+
* its own resources (e.g. the text field cursor handle popup title), which breaks recomposition.
|
|
29
|
+
* Point these fields to the IDs of the app under test, matched by name.
|
|
30
|
+
*/
|
|
31
|
+
internal object ComposeResourceIds {
|
|
32
|
+
private const val COMPOSE_PACKAGE_PREFIX = "androidx.compose."
|
|
33
|
+
private val SKIPPED_TYPES = setOf("id", "attr", "styleable")
|
|
34
|
+
|
|
35
|
+
@Suppress("DEPRECATION")
|
|
36
|
+
fun alignWithTarget() {
|
|
37
|
+
val instrumentation = InstrumentationRegistry.getInstrumentation()
|
|
38
|
+
val targetContext = instrumentation.targetContext
|
|
39
|
+
var aligned = 0
|
|
40
|
+
try {
|
|
41
|
+
val dexFile = DexFile(instrumentation.context.packageCodePath)
|
|
42
|
+
try {
|
|
43
|
+
dexFile.entries().asSequence()
|
|
44
|
+
.filter { it.startsWith(COMPOSE_PACKAGE_PREFIX) && it.contains(".R$") }
|
|
45
|
+
.forEach { className ->
|
|
46
|
+
val type = className.substringAfter(".R$")
|
|
47
|
+
if (type !in SKIPPED_TYPES) {
|
|
48
|
+
aligned += alignClass(className, type, targetContext.resources, targetContext.packageName)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} finally {
|
|
52
|
+
dexFile.close()
|
|
53
|
+
}
|
|
54
|
+
} catch (e: Throwable) {
|
|
55
|
+
// Best effort: never fail the server start
|
|
56
|
+
AndroidLogger.info("Could not align Compose resource IDs with the app: $e")
|
|
57
|
+
}
|
|
58
|
+
AndroidLogger.info("Aligned $aligned Compose resource IDs with the app under test")
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private fun alignClass(
|
|
62
|
+
className: String,
|
|
63
|
+
type: String,
|
|
64
|
+
resources: Resources,
|
|
65
|
+
packageName: String,
|
|
66
|
+
): Int {
|
|
67
|
+
var aligned = 0
|
|
68
|
+
try {
|
|
69
|
+
Class.forName(className).fields
|
|
70
|
+
.filter { Modifier.isStatic(it.modifiers) && !Modifier.isFinal(it.modifiers) && it.type == Int::class.javaPrimitiveType }
|
|
71
|
+
.forEach { field ->
|
|
72
|
+
val id = resources.getIdentifier(field.name, type, packageName)
|
|
73
|
+
if (id != 0 && id != field.getInt(null)) {
|
|
74
|
+
field.setInt(null, id)
|
|
75
|
+
aligned++
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
} catch (e: Throwable) {
|
|
79
|
+
AndroidLogger.info("Could not align $className: $e")
|
|
80
|
+
}
|
|
81
|
+
return aligned
|
|
82
|
+
}
|
|
83
|
+
}
|
package/espresso-server/library/src/composeOn/java/io/appium/espressoserver/lib/http/Server.kt
CHANGED
|
@@ -16,12 +16,20 @@
|
|
|
16
16
|
|
|
17
17
|
package io.appium.espressoserver.lib.http
|
|
18
18
|
|
|
19
|
+
import io.appium.espressoserver.lib.compose.ComposeResourceIds
|
|
19
20
|
import io.appium.espressoserver.lib.drivers.DriverContext
|
|
20
21
|
import io.appium.espressoserver.lib.drivers.composeTestRule
|
|
21
22
|
import org.junit.rules.TestRule
|
|
23
|
+
import java.io.IOException
|
|
22
24
|
|
|
23
25
|
class Server : ServerBase(), TestRule by DriverContext.composeTestRule {
|
|
24
26
|
|
|
27
|
+
@Throws(IOException::class)
|
|
28
|
+
override fun start() {
|
|
29
|
+
ComposeResourceIds.alignWithTarget()
|
|
30
|
+
super.start()
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
override fun advanceComposeMainClockIfNeeded() {
|
|
26
34
|
if (DriverContext.currentStrategyType == DriverContext.StrategyType.COMPOSE) {
|
|
27
35
|
DriverContext.composeTestRule.mainClock.advanceTimeByFrame()
|
|
@@ -80,5 +80,7 @@ class Keys : RequestHandler<TextValueParams, Unit> {
|
|
|
80
80
|
UiControllerPerformer(runnable).run()
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
// Without an element the keys go to the focused view, as in Espresso mode
|
|
84
|
+
override fun handleCompose(params: TextValueParams) =
|
|
85
|
+
if (params.elementId == null) handleEspresso(params) else ComposeHandlerBridge.keys(params)
|
|
84
86
|
}
|
package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/handlers/PerformAction.kt
CHANGED
|
@@ -16,7 +16,11 @@
|
|
|
16
16
|
|
|
17
17
|
package io.appium.espressoserver.lib.handlers
|
|
18
18
|
|
|
19
|
+
import android.graphics.Point
|
|
19
20
|
import androidx.test.espresso.UiController
|
|
21
|
+
import io.appium.espressoserver.lib.compose.ComposeHandlerBridge
|
|
22
|
+
import io.appium.espressoserver.lib.drivers.DriverContext
|
|
23
|
+
import io.appium.espressoserver.lib.helpers.ComposeViewCache
|
|
20
24
|
import io.appium.espressoserver.lib.handlers.exceptions.AppiumException
|
|
21
25
|
import io.appium.espressoserver.lib.helpers.w3c.adapter.espresso.EspressoW3CActionAdapter
|
|
22
26
|
import io.appium.espressoserver.lib.helpers.w3c.models.Actions
|
|
@@ -27,10 +31,11 @@ class PerformAction : RequestHandler<Actions, Void?> {
|
|
|
27
31
|
|
|
28
32
|
@Throws(AppiumException::class)
|
|
29
33
|
override fun handleInternal(params: Actions): Void? {
|
|
34
|
+
val elementCenters = resolveComposeElementCenters(params)
|
|
30
35
|
|
|
31
36
|
val runnable = object: UiControllerRunnable<Void?> {
|
|
32
37
|
override fun run(uiController: UiController): Void? {
|
|
33
|
-
val adapter = EspressoW3CActionAdapter(uiController)
|
|
38
|
+
val adapter = EspressoW3CActionAdapter(uiController, elementCenters)
|
|
34
39
|
params.adapter = adapter
|
|
35
40
|
try {
|
|
36
41
|
params.perform(params.sessionId!!)
|
|
@@ -46,4 +51,19 @@ class PerformAction : RequestHandler<Actions, Void?> {
|
|
|
46
51
|
UiControllerPerformer(runnable).run()
|
|
47
52
|
return null
|
|
48
53
|
}
|
|
54
|
+
|
|
55
|
+
// Compose elements cannot be resolved on the main thread, so resolve them up front
|
|
56
|
+
private fun resolveComposeElementCenters(params: Actions): Map<String, Point> {
|
|
57
|
+
if (DriverContext.currentStrategyType != DriverContext.StrategyType.COMPOSE) {
|
|
58
|
+
return emptyMap()
|
|
59
|
+
}
|
|
60
|
+
return params.actions.orEmpty()
|
|
61
|
+
.flatMap { it.actions.orEmpty() }
|
|
62
|
+
.filter { it.isOriginElement }
|
|
63
|
+
.mapNotNull { it.origin.elementId }
|
|
64
|
+
.distinct()
|
|
65
|
+
// Other ids are Espresso views, which the adapter resolves itself
|
|
66
|
+
.filter { ComposeViewCache.get(it) != null }
|
|
67
|
+
.associateWith { ComposeHandlerBridge.getElementCenterPoint(it) }
|
|
68
|
+
}
|
|
49
69
|
}
|
package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/helpers/SizeHelpers.kt
CHANGED
|
@@ -17,9 +17,11 @@
|
|
|
17
17
|
package io.appium.espressoserver.lib.helpers
|
|
18
18
|
|
|
19
19
|
import android.content.Context
|
|
20
|
+
import android.graphics.Point
|
|
20
21
|
import android.graphics.Rect
|
|
21
22
|
import android.os.Build
|
|
22
23
|
import android.util.DisplayMetrics
|
|
24
|
+
import android.view.View
|
|
23
25
|
import android.view.WindowManager
|
|
24
26
|
import androidx.test.core.app.ApplicationProvider
|
|
25
27
|
|
|
@@ -37,3 +39,12 @@ fun getCurrentWindowRect(): Rect {
|
|
|
37
39
|
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
|
38
40
|
return Rect(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels)
|
|
39
41
|
}
|
|
42
|
+
|
|
43
|
+
/** Screen position of the window origin; unlike the view location, it ignores the view offset and translation. */
|
|
44
|
+
fun View.windowOriginOnScreen(): Point {
|
|
45
|
+
val onScreen = IntArray(2)
|
|
46
|
+
val inWindow = IntArray(2)
|
|
47
|
+
getLocationOnScreen(onScreen)
|
|
48
|
+
getLocationInWindow(inWindow)
|
|
49
|
+
return Point(onScreen[0] - inWindow[0], onScreen[1] - inWindow[1])
|
|
50
|
+
}
|
package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/helpers/Version.kt
CHANGED
|
@@ -2,6 +2,6 @@ package io.appium.espressoserver.lib.helpers
|
|
|
2
2
|
|
|
3
3
|
// This value is updated automatically by the NPM versioning script
|
|
4
4
|
// It should be in sync with the NPM module version from package.json
|
|
5
|
-
private const val VERSION = "9.3.
|
|
5
|
+
private const val VERSION = "9.3.13"
|
|
6
6
|
|
|
7
7
|
fun getEspressoServerVersion() = VERSION
|
|
@@ -323,7 +323,9 @@ class AndroidKeyEvent @JvmOverloads constructor(
|
|
|
323
323
|
|
|
324
324
|
// Inject all of the key events, in order
|
|
325
325
|
for (androidKeyEvent in keyEvents) {
|
|
326
|
-
|
|
326
|
+
// Printing keys are not logged since they may be sensitive
|
|
327
|
+
val keyName = if (androidKeyEvent.isPrintingKey) "printing key" else KeyEvent.keyCodeToString(androidKeyEvent.keyCode)
|
|
328
|
+
AndroidLogger.info("Calling key event: action=${androidKeyEvent.action} key=[$keyName]")
|
|
327
329
|
var isSuccess: Boolean
|
|
328
330
|
isSuccess = try {
|
|
329
331
|
uiController.injectKeyEvent(androidKeyEvent)
|
|
@@ -331,7 +333,7 @@ class AndroidKeyEvent @JvmOverloads constructor(
|
|
|
331
333
|
throw AppiumException(e.cause.toString())
|
|
332
334
|
}
|
|
333
335
|
if (!isSuccess) {
|
|
334
|
-
throw AppiumException(
|
|
336
|
+
throw AppiumException("Could not inject key event: key=[$keyName]")
|
|
335
337
|
}
|
|
336
338
|
}
|
|
337
339
|
ImeSettle.mark(false)
|
|
@@ -23,7 +23,14 @@ import androidx.test.core.app.ApplicationProvider.getApplicationContext
|
|
|
23
23
|
import kotlin.math.roundToInt
|
|
24
24
|
import kotlin.math.roundToLong
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* @param elementCenters pre-resolved origin element centers for elements that cannot
|
|
28
|
+
* be looked up on the main thread (Compose)
|
|
29
|
+
*/
|
|
30
|
+
class EspressoW3CActionAdapter @JvmOverloads constructor(
|
|
31
|
+
private val uiController: UiController,
|
|
32
|
+
private val elementCenters: Map<String, Point> = emptyMap(),
|
|
33
|
+
) : BaseW3CActionAdapter() {
|
|
27
34
|
|
|
28
35
|
private val androidKeyEvent: AndroidKeyEvent = AndroidKeyEvent(uiController)
|
|
29
36
|
private val multiTouchState = MultiTouchState()
|
|
@@ -129,6 +136,7 @@ class EspressoW3CActionAdapter(private val uiController: UiController) : BaseW3C
|
|
|
129
136
|
}
|
|
130
137
|
|
|
131
138
|
override fun getElementCenterPoint(elementId: String?): Point {
|
|
139
|
+
elementCenters[elementId]?.let { return it }
|
|
132
140
|
val viewState = EspressoElement.getCachedViewStateById(elementId)
|
|
133
141
|
val coords = GeneralLocation.CENTER.calculateCoordinates(viewState.view)
|
|
134
142
|
val point = Point()
|
|
@@ -8,6 +8,7 @@ import android.widget.TextView
|
|
|
8
8
|
import androidx.test.espresso.UiController
|
|
9
9
|
import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry
|
|
10
10
|
import androidx.test.runner.lifecycle.Stage
|
|
11
|
+
import io.appium.espressoserver.lib.compose.ComposeHandlerBridge
|
|
11
12
|
import io.appium.espressoserver.lib.handlers.exceptions.InvalidArgumentException
|
|
12
13
|
import io.appium.espressoserver.lib.handlers.exceptions.InvalidElementStateException
|
|
13
14
|
import io.appium.espressoserver.lib.helpers.AndroidLogger
|
|
@@ -31,20 +32,27 @@ class NonAsciiTextInserter(private val uiController: UiController) {
|
|
|
31
32
|
"The code point $it is neither a known W3C special key nor a printable character that could be typed")
|
|
32
33
|
}
|
|
33
34
|
uiController.loopMainThreadUntilIdle()
|
|
34
|
-
val
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
val focused = waitForFocusedEditor()
|
|
36
|
+
if (focused is TextView) {
|
|
37
|
+
val editable = focused.text as? Editable
|
|
38
|
+
?: throw InvalidElementStateException("The focused element does not expose editable text")
|
|
39
|
+
val inserted = insertIntoEditable(editable, text)
|
|
40
|
+
AndroidLogger.info("Typed $inserted of ${text.length} chars into the focused element")
|
|
41
|
+
} else if (ComposeHandlerBridge.insertTextIntoFocusedNode(focused, text)) {
|
|
42
|
+
AndroidLogger.info("Typed ${text.length} chars into the focused Compose element")
|
|
43
|
+
} else {
|
|
44
|
+
throw InvalidElementStateException("The focused Compose element rejected the text")
|
|
45
|
+
}
|
|
39
46
|
uiController.loopMainThreadUntilIdle()
|
|
40
47
|
}
|
|
41
48
|
|
|
42
|
-
private fun waitForFocusedEditor():
|
|
49
|
+
private fun waitForFocusedEditor(): View {
|
|
43
50
|
val deadline = SystemClock.uptimeMillis() + FOCUS_TIMEOUT_MS
|
|
44
51
|
var focused: View?
|
|
45
52
|
while (true) {
|
|
46
53
|
focused = findFocusedView()
|
|
47
|
-
if (focused is TextView && focused.onCheckIsTextEditor()
|
|
54
|
+
if (focused is TextView && focused.onCheckIsTextEditor()
|
|
55
|
+
|| focused != null && ComposeHandlerBridge.hasFocusedEditableNode(focused)) {
|
|
48
56
|
return focused
|
|
49
57
|
}
|
|
50
58
|
if (SystemClock.uptimeMillis() >= deadline) {
|
|
@@ -14,8 +14,10 @@ class W3CKeyEvent {
|
|
|
14
14
|
var isRepeat = false
|
|
15
15
|
var isComposing = false
|
|
16
16
|
|
|
17
|
+
// Typed characters may be sensitive, so neither key nor code are logged
|
|
17
18
|
fun logMessage(): String {
|
|
18
|
-
|
|
19
|
+
val keyKind = if (key?.firstOrNull() in '\uE000'..'\uF8FF') "special" else "character"
|
|
20
|
+
return "key=[$keyKind] altKey=[$isAltKey] shiftKey=[$isShiftKey] ctrlKey=[$isCtrlKey] metaKey=[$isMetaKey]"
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
}
|
|
@@ -60,7 +60,7 @@ class KeyInputState : InputState {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
fun logMessage(): String {
|
|
63
|
-
return "alt=[$isAlt] shift=[$isShift] ctrl=[$isCtrl] meta=[$isMeta]
|
|
63
|
+
return "alt=[$isAlt] shift=[$isShift] ctrl=[$isCtrl] meta=[$isMeta] pressedCount=[${pressed.size}]"
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
fun toMetaState(): Int {
|
|
@@ -210,7 +210,12 @@ internal class Router(server: ServerBase) {
|
|
|
210
210
|
try {
|
|
211
211
|
// Parse the parameters
|
|
212
212
|
val appiumParams: AppiumParams = postJson?.let {
|
|
213
|
-
|
|
213
|
+
// Requests carrying text to type may contain sensitive data
|
|
214
|
+
if (paramClass == TextValueParams::class.java || paramClass == Actions::class.java) {
|
|
215
|
+
AndroidLogger.debug("Got raw post data of ${it.length} chars")
|
|
216
|
+
} else {
|
|
217
|
+
AndroidLogger.debug("Got raw post data: ${abbreviate(it, 300)}")
|
|
218
|
+
}
|
|
214
219
|
try {
|
|
215
220
|
paramClass.cast(Gson().fromJson<AppiumParams>(it, paramClass))
|
|
216
221
|
?: return AppiumResponse(InvalidArgumentException("Could not parse JSON: $it"))
|
|
@@ -31,6 +31,7 @@ import org.hamcrest.Matcher
|
|
|
31
31
|
class UiControllerPerformer<T>(private val runnable: UiControllerRunnable<T>) : ViewAction {
|
|
32
32
|
private var appiumException: AppiumException? = null
|
|
33
33
|
private var runResult: T? = null
|
|
34
|
+
private var isPerformed = false
|
|
34
35
|
|
|
35
36
|
override fun getConstraints(): Matcher<View> {
|
|
36
37
|
return ViewMatchers.isRoot()
|
|
@@ -46,6 +47,7 @@ class UiControllerPerformer<T>(private val runnable: UiControllerRunnable<T>) :
|
|
|
46
47
|
} catch (e: AppiumException) {
|
|
47
48
|
appiumException = e
|
|
48
49
|
}
|
|
50
|
+
isPerformed = true
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
@Throws(AppiumException::class)
|
|
@@ -58,6 +60,12 @@ class UiControllerPerformer<T>(private val runnable: UiControllerRunnable<T>) :
|
|
|
58
60
|
viewInteraction.perform(this, ViewActions.closeSoftKeyboard())
|
|
59
61
|
} catch (nme: NoMatchingViewException) {
|
|
60
62
|
// Ignore this. The viewMatcher is a hack to begin with
|
|
63
|
+
} catch (e: RuntimeException) {
|
|
64
|
+
// The exception class is private. The actions may have opened a window that never takes focus
|
|
65
|
+
if (!isPerformed || e.javaClass.simpleName != "RootViewWithoutFocusException") {
|
|
66
|
+
throw e
|
|
67
|
+
}
|
|
68
|
+
AndroidLogger.info("The root view has no focus after the actions were performed")
|
|
61
69
|
}
|
|
62
70
|
if (appiumException != null) {
|
|
63
71
|
throw appiumException!!
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
* you may not use this file except in compliance with the License.
|
|
4
|
+
* See the NOTICE file distributed with this work for additional
|
|
5
|
+
* information regarding copyright ownership.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
package io.appium.espressoserver.test.helpers
|
|
18
|
+
|
|
19
|
+
import android.app.Activity
|
|
20
|
+
import android.view.View
|
|
21
|
+
import android.widget.FrameLayout
|
|
22
|
+
import io.appium.espressoserver.lib.helpers.windowOriginOnScreen
|
|
23
|
+
import org.junit.Test
|
|
24
|
+
import org.junit.runner.RunWith
|
|
25
|
+
import org.robolectric.Robolectric
|
|
26
|
+
import org.robolectric.RobolectricTestRunner
|
|
27
|
+
import kotlin.test.assertEquals
|
|
28
|
+
import kotlin.test.assertNotEquals
|
|
29
|
+
|
|
30
|
+
@RunWith(RobolectricTestRunner::class)
|
|
31
|
+
class `Window Origin Tests` {
|
|
32
|
+
|
|
33
|
+
@Test
|
|
34
|
+
fun `window origin should not depend on the view offset or translation`() {
|
|
35
|
+
val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
|
|
36
|
+
val view = View(activity)
|
|
37
|
+
activity.setContentView(
|
|
38
|
+
FrameLayout(activity).apply { addView(view, FrameLayout.LayoutParams(100, 100)) }
|
|
39
|
+
)
|
|
40
|
+
val originBefore = view.windowOriginOnScreen()
|
|
41
|
+
val locationBefore = IntArray(2).also { view.getLocationOnScreen(it) }
|
|
42
|
+
|
|
43
|
+
view.translationY = 80f
|
|
44
|
+
view.translationX = 30f
|
|
45
|
+
|
|
46
|
+
val locationAfter = IntArray(2).also { view.getLocationOnScreen(it) }
|
|
47
|
+
assertEquals(locationBefore[1] + 80, locationAfter[1])
|
|
48
|
+
assertNotEquals(locationBefore[0], locationAfter[0])
|
|
49
|
+
assertEquals(originBefore, view.windowOriginOnScreen())
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package io.appium.espressoserver.test.helpers.w3c.adapter
|
|
2
2
|
|
|
3
|
+
import android.graphics.Point
|
|
3
4
|
import android.os.SystemClock
|
|
4
5
|
import android.view.KeyEvent
|
|
5
6
|
import android.view.MotionEvent
|
|
@@ -84,6 +85,18 @@ class AndroidKeyEventTest {
|
|
|
84
85
|
Assert.assertEquals(keyEvent.metaState, KeyEvent.META_SHIFT_MASK or KeyEvent.META_ALT_MASK)
|
|
85
86
|
}
|
|
86
87
|
|
|
88
|
+
@Test
|
|
89
|
+
fun failedInjectionDoesNotExposePrintingKey() {
|
|
90
|
+
val mockUiController = object : UiController by MockUiController() {
|
|
91
|
+
override fun injectKeyEvent(event: KeyEvent) = false
|
|
92
|
+
}
|
|
93
|
+
val w3CKeyEvent = getKeyEvent(EspressoW3CActionAdapter(mockUiController), "7")
|
|
94
|
+
val error = Assert.assertThrows(AppiumException::class.java) {
|
|
95
|
+
AndroidKeyEvent(mockUiController).keyDown(w3CKeyEvent)
|
|
96
|
+
}
|
|
97
|
+
Assert.assertEquals("Could not inject key event: key=[printing key]", error.message)
|
|
98
|
+
}
|
|
99
|
+
|
|
87
100
|
@Test
|
|
88
101
|
@Throws(AppiumException::class)
|
|
89
102
|
fun keyDownAndUp() {
|
|
@@ -115,4 +128,12 @@ class AndroidKeyEventTest {
|
|
|
115
128
|
Assert.assertEquals(keyCodeToEvent(ARROW_UP, 0).toLong(), KeyEvent.KEYCODE_DPAD_UP.toLong())
|
|
116
129
|
Assert.assertEquals(keyCodeToEvent(ARROW_DOWN, 0).toLong(), KeyEvent.KEYCODE_DPAD_DOWN.toLong())
|
|
117
130
|
}
|
|
118
|
-
|
|
131
|
+
|
|
132
|
+
@Test
|
|
133
|
+
fun preResolvedElementCenterIsUsed() {
|
|
134
|
+
val adapter = EspressoW3CActionAdapter(MockUiController(), mapOf("compose-node" to Point(12, 34)))
|
|
135
|
+
val center = adapter.getElementCenterPoint("compose-node")
|
|
136
|
+
Assert.assertEquals(12, center.x)
|
|
137
|
+
Assert.assertEquals(34, center.y)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
package io.appium.espressoserver.test.helpers.w3c.adapter
|
|
2
|
+
|
|
3
|
+
import io.appium.espressoserver.lib.helpers.w3c.dispatcher.W3CKeyEvent
|
|
4
|
+
import io.appium.espressoserver.lib.helpers.w3c.state.KeyInputState
|
|
5
|
+
import org.junit.Assert.assertFalse
|
|
6
|
+
import org.junit.Assert.assertTrue
|
|
7
|
+
import org.junit.Test
|
|
8
|
+
|
|
9
|
+
class KeyLogRedactionTest {
|
|
10
|
+
@Test
|
|
11
|
+
fun keyEventLogDoesNotContainTypedCharacters() {
|
|
12
|
+
val event = W3CKeyEvent().apply {
|
|
13
|
+
key = "ж"
|
|
14
|
+
code = "KeyJ"
|
|
15
|
+
}
|
|
16
|
+
val message = event.logMessage()
|
|
17
|
+
assertFalse(message.contains("ж"))
|
|
18
|
+
assertFalse(message.contains("KeyJ"))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Test
|
|
22
|
+
fun keyEventLogKeepsSpecialKeysApart() {
|
|
23
|
+
val event = W3CKeyEvent().apply { key = "" }
|
|
24
|
+
assertTrue(event.logMessage().contains("key=[special]"))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Test
|
|
28
|
+
fun keyInputStateLogDoesNotContainPressedKeys() {
|
|
29
|
+
val state = KeyInputState().apply { addPressed("Q") }
|
|
30
|
+
assertFalse(state.logMessage().contains("Q"))
|
|
31
|
+
assertTrue(state.logMessage().contains("pressedCount=[1]"))
|
|
32
|
+
}
|
|
33
|
+
}
|