diff --git a/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/Automator.kt b/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/Automator.kt index 91154593d..11c2306cc 100644 --- a/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/Automator.kt +++ b/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/Automator.kt @@ -174,7 +174,7 @@ class Automator private constructor() { delay() } - fun enterText(text: String, index: Int, keyboardBehavior: KeyboardBehavior) { + fun enterText(text: String, index: Int, keyboardBehavior: Contracts.KeyboardBehavior) { Logger.d("enterText(text: $text, index: $index)") val selector = By.clazz(EditText::class.java) @@ -187,13 +187,13 @@ class Automator private constructor() { val uiSelector = UiSelector().className(EditText::class.java).instance(index) val uiObject = uiDevice.findObject(uiSelector) - if (keyboardBehavior == KeyboardBehavior.SHOW_AND_DISMISS) { + if (keyboardBehavior == Contracts.KeyboardBehavior.showAndDismiss) { uiObject.click() } uiObject.text = text - if (keyboardBehavior == KeyboardBehavior.SHOW_AND_DISMISS) { + if (keyboardBehavior == Contracts.KeyboardBehavior.showAndDismiss) { pressBack() // Hide keyboard. } } @@ -203,7 +203,7 @@ class Automator private constructor() { uiSelector: UiSelector, bySelector: BySelector, index: Int, - keyboardBehavior: KeyboardBehavior + keyboardBehavior: Contracts.KeyboardBehavior ) { Logger.d("enterText($text): $uiSelector, $bySelector") @@ -213,13 +213,13 @@ class Automator private constructor() { val uiObject = uiDevice.findObject(uiSelector).getFromParent(UiSelector().className(EditText::class.java)) - if (keyboardBehavior == KeyboardBehavior.SHOW_AND_DISMISS) { + if (keyboardBehavior == Contracts.KeyboardBehavior.showAndDismiss) { uiObject.click() } uiObject.text = text - if (keyboardBehavior == KeyboardBehavior.SHOW_AND_DISMISS) { + if (keyboardBehavior == Contracts.KeyboardBehavior.showAndDismiss) { pressBack() // Hide keyboard. } } diff --git a/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/AutomatorServer.kt b/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/AutomatorServer.kt index fb407c922..aaeaa51cc 100644 --- a/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/AutomatorServer.kt +++ b/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/AutomatorServer.kt @@ -121,7 +121,7 @@ class AutomatorServer(private val automation: Automator) : NativeAutomatorServer if (request.index != null) { automation.enterText( text = request.data, - index = request.index!!.toInt(), + index = request.index.toInt(), keyboardBehavior = request.keyboardBehavior ) } else if (request.selector != null) { diff --git a/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/contracts/Contracts.kt b/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/contracts/Contracts.kt index 90e8e3110..674a47101 100644 --- a/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/contracts/Contracts.kt +++ b/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/contracts/Contracts.kt @@ -15,6 +15,12 @@ class Contracts { failure, } + @Serializable + enum class KeyboardBehavior { + showAndDismiss, + alternative, + } + @Serializable enum class HandlePermissionRequestCode { whileUsing, @@ -183,7 +189,7 @@ class Contracts { val appId: String, val index: Long? = null, val selector: Selector? = null, - val showKeyboard: Boolean + val keyboardBehavior: KeyboardBehavior ){ fun hasIndex(): Boolean { return index != null diff --git a/packages/patrol/ios/Classes/AutomatorServer/Contracts.swift b/packages/patrol/ios/Classes/AutomatorServer/Contracts.swift index 6d8d61108..7a3bf355a 100644 --- a/packages/patrol/ios/Classes/AutomatorServer/Contracts.swift +++ b/packages/patrol/ios/Classes/AutomatorServer/Contracts.swift @@ -9,6 +9,11 @@ enum RunDartTestResponseResult: String, Codable { case failure } +enum KeyboardBehavior: String, Codable { + case showAndDismiss + case alternative +} + enum HandlePermissionRequestCode: String, Codable { case whileUsing case onlyThisTime @@ -101,7 +106,7 @@ struct EnterTextRequest: Codable { var appId: String var index: Int? var selector: Selector? - var showKeyboard: Bool + var keyboardBehavior: KeyboardBehavior } struct SwipeRequest: Codable { diff --git a/packages/patrol/lib/src/native/contracts/contracts.dart b/packages/patrol/lib/src/native/contracts/contracts.dart index 48e062632..2255f43ff 100644 --- a/packages/patrol/lib/src/native/contracts/contracts.dart +++ b/packages/patrol/lib/src/native/contracts/contracts.dart @@ -17,6 +17,13 @@ enum RunDartTestResponseResult { failure } +enum KeyboardBehavior { + @JsonValue('showAndDismiss') + showAndDismiss, + @JsonValue('alternative') + alternative +} + enum HandlePermissionRequestCode { @JsonValue('whileUsing') whileUsing, @@ -266,7 +273,7 @@ class EnterTextRequest { required this.appId, this.index, this.selector, - required this.showKeyboard, + required this.keyboardBehavior, }); factory EnterTextRequest.fromJson(Map json) => @@ -276,7 +283,7 @@ class EnterTextRequest { final String appId; final int? index; final Selector? selector; - final bool showKeyboard; + final KeyboardBehavior keyboardBehavior; Map toJson() => _$EnterTextRequestToJson(this); } diff --git a/packages/patrol/lib/src/native/contracts/contracts.g.dart b/packages/patrol/lib/src/native/contracts/contracts.g.dart index 28ca15712..08eaa6a31 100644 --- a/packages/patrol/lib/src/native/contracts/contracts.g.dart +++ b/packages/patrol/lib/src/native/contracts/contracts.g.dart @@ -207,7 +207,8 @@ EnterTextRequest _$EnterTextRequestFromJson(Map json) => selector: json['selector'] == null ? null : Selector.fromJson(json['selector'] as Map), - showKeyboard: json['showKeyboard'] as bool, + keyboardBehavior: + $enumDecode(_$KeyboardBehaviorEnumMap, json['keyboardBehavior']), ); Map _$EnterTextRequestToJson(EnterTextRequest instance) => @@ -216,9 +217,14 @@ Map _$EnterTextRequestToJson(EnterTextRequest instance) => 'appId': instance.appId, 'index': instance.index, 'selector': instance.selector, - 'showKeyboard': instance.showKeyboard, + 'keyboardBehavior': _$KeyboardBehaviorEnumMap[instance.keyboardBehavior]!, }; +const _$KeyboardBehaviorEnumMap = { + KeyboardBehavior.showAndDismiss: 'showAndDismiss', + KeyboardBehavior.alternative: 'alternative', +}; + SwipeRequest _$SwipeRequestFromJson(Map json) => SwipeRequest( startX: (json['startX'] as num).toDouble(), startY: (json['startY'] as num).toDouble(), diff --git a/packages/patrol/lib/src/native/native_automator.dart b/packages/patrol/lib/src/native/native_automator.dart index 5d563e408..e4d014564 100644 --- a/packages/patrol/lib/src/native/native_automator.dart +++ b/packages/patrol/lib/src/native/native_automator.dart @@ -6,6 +6,7 @@ import 'package:integration_test/integration_test.dart'; import 'package:meta/meta.dart'; import 'package:patrol/src/binding.dart'; import 'package:patrol/src/native/contracts/contracts.dart'; +import 'package:patrol/src/native/contracts/contracts.dart' as contracts; import 'package:patrol/src/native/contracts/native_automator_client.dart'; /// Thrown when a native action fails. @@ -51,12 +52,12 @@ enum KeyboardBehavior { } extension on KeyboardBehavior { - EnterTextRequest_KeyboardBehavior get toProtoEnum { + contracts.KeyboardBehavior get toContractsEnum { switch (this) { case KeyboardBehavior.showAndDismiss: - return EnterTextRequest_KeyboardBehavior.SHOW_AND_DISMISS; + return contracts.KeyboardBehavior.showAndDismiss; case KeyboardBehavior.alternative: - return EnterTextRequest_KeyboardBehavior.ALTERNATIVE; + return contracts.KeyboardBehavior.alternative; } } } @@ -547,7 +548,7 @@ class NativeAutomator { appId: appId ?? resolvedAppId, selector: selector, keyboardBehavior: - (keyboardBehavior ?? _config.keyboardBehavior).toProtoEnum, + (keyboardBehavior ?? _config.keyboardBehavior).toContractsEnum, ), ), ); @@ -581,7 +582,7 @@ class NativeAutomator { appId: appId ?? resolvedAppId, index: index, keyboardBehavior: - (keyboardBehavior ?? _config.keyboardBehavior).toProtoEnum, + (keyboardBehavior ?? _config.keyboardBehavior).toContractsEnum, ), ), ); diff --git a/schema.dart b/schema.dart index 95955ea9e..d44f437c7 100644 --- a/schema.dart +++ b/schema.dart @@ -83,12 +83,17 @@ class TapRequest { late String appId; } +enum KeyboardBehavior { + showAndDismiss, + alternative, +} + class EnterTextRequest { late String data; late String appId; int? index; Selector? selector; - late bool showKeyboard; + late KeyboardBehavior keyboardBehavior; } class SwipeRequest {