diff --git a/dev/e2e_app/integration_test/external_link_test.dart b/dev/e2e_app/integration_test/external_link_test.dart index d91c3b37f..a6dafb433 100644 --- a/dev/e2e_app/integration_test/external_link_test.dart +++ b/dev/e2e_app/integration_test/external_link_test.dart @@ -1,44 +1,56 @@ -import 'dart:io'; - import 'common.dart'; void main() { patrol('Open external url', ($) async { await createApp($); - await $.native.openUrl('https://leancode.co'); + await $.native2.openUrl('https://leancode.co'); - try { - await $.native.tap(Selector(text: 'Use without an account')); - } on PatrolActionException catch (_) { - // ignore - } + await $.pump(Duration(seconds: 5)); try { - await $.native.tap(Selector(text: 'Contact us')); + await $.native2.tap( + NativeSelector( + android: AndroidSelector(text: 'Use without an account'), + ), + ); } on PatrolActionException catch (_) { // ignore } try { - await $.native.tap(Selector(text: 'No thanks')); + await $.native2.tap( + NativeSelector( + android: AndroidSelector(text: 'No thanks'), + ios: IOSSelector(label: 'No thanks'), + ), + appId: 'com.apple.mobilesafari', + ); } on PatrolActionException catch (_) { // ignore } try { - await $.native.tap(Selector(text: 'ACCEPT ALL COOKIES')); + await $.native2.tap( + NativeSelector( + android: AndroidSelector( + text: 'ACCEPT ALL COOKIES', + applicationPackage: 'com.android.chrome', + ), + ios: IOSSelector(label: 'ACCEPT ALL COOKIES'), + ), + appId: 'com.apple.mobilesafari', + ); } on PatrolActionException catch (_) { // ignore } - if (Platform.isIOS) { - await $.native.waitUntilVisible( - Selector(text: 'Subscribe'), - appId: 'com.apple.mobilesafari', - ); - } else { - await $.native.waitUntilVisible(Selector(text: 'Subscribe')); - } + await $.native2.waitUntilVisible( + NativeSelector( + android: AndroidSelector(text: 'Contact us'), + ios: IOSSelector(label: 'Contact us'), + ), + appId: 'com.apple.mobilesafari', + ); }); } diff --git a/dev/e2e_app/integration_test/webview_hackernews_test.dart b/dev/e2e_app/integration_test/webview_hackernews_test.dart index 6af4216a8..0b9895058 100644 --- a/dev/e2e_app/integration_test/webview_hackernews_test.dart +++ b/dev/e2e_app/integration_test/webview_hackernews_test.dart @@ -6,7 +6,7 @@ void main() { await $('Open webview (Hacker News)').scrollTo().tap(); - await Future.delayed(const Duration(seconds: 3)); + await $.pump(Duration(seconds: 3)); await $.native.tap(Selector(text: 'login')); await $.native.enterTextByIndex( @@ -26,7 +26,7 @@ void main() { await $('Open webview (Hacker News)').scrollTo().tap(); - await Future.delayed(const Duration(seconds: 3)); + await $.pump(Duration(seconds: 3)); await $.native2.tap( NativeSelector( @@ -34,14 +34,23 @@ void main() { ios: IOSSelector(label: 'login'), ), ); - await $.native2.enterTextByIndex( - 'test@leancode.pl', - index: 0, + await $.native2.enterText( + NativeSelector( + android: AndroidSelector( + className: 'android.widget.EditText', + instance: 0, + ), + ios: IOSSelector(elementType: IOSElementType.textField), + ), + text: 'test@leancode.pl', keyboardBehavior: KeyboardBehavior.showAndDismiss, ); await $.native2.enterText( NativeSelector( - android: AndroidSelector(className: 'android.widget.EditText'), + android: AndroidSelector( + className: 'android.widget.EditText', + instance: 1, + ), ios: IOSSelector(elementType: IOSElementType.secureTextField), ), text: 'ny4ncat', diff --git a/dev/e2e_app/integration_test/webview_leancode_test.dart b/dev/e2e_app/integration_test/webview_leancode_test.dart index 1d8d1abba..1a4806fcf 100644 --- a/dev/e2e_app/integration_test/webview_leancode_test.dart +++ b/dev/e2e_app/integration_test/webview_leancode_test.dart @@ -1,5 +1,3 @@ -import 'dart:io' as io; - import 'common.dart'; void main() { @@ -22,32 +20,28 @@ void main() { } await $.pumpAndSettle(); - if (io.Platform.isIOS) { - await $.native2.scrollTo( - NativeSelector( - ios: IOSSelector(placeholderValue: 'Type your email'), - ), - maxScrolls: 20, - ); - } + final emailInputSelector = NativeSelector( + android: AndroidSelector(className: 'android.widget.EditText'), + ios: IOSSelector(placeholderValue: 'Type your email'), + ); - await $.pump(Duration(seconds: 5)); + await $.native2.scrollTo(emailInputSelector, maxScrolls: 20); + + await $.pump(Duration(seconds: 2)); await $.native2.enterText( - NativeSelector( - android: AndroidSelector(className: 'android.widget.EditText'), - ios: IOSSelector(placeholderValue: 'Type your email'), - ), + emailInputSelector, text: 'test@leancode.pl', - keyboardBehavior: KeyboardBehavior.showAndDismiss, + keyboardBehavior: KeyboardBehavior.alternative, tapLocation: Offset(0.5, 0.5), ); - await $.native2.tap( - NativeSelector( - android: AndroidSelector(text: 'Subscribe'), - ios: IOSSelector(label: 'Subscribe'), - ), + final subscribeButtonSelector = NativeSelector( + android: AndroidSelector(text: 'Subscribe'), + ios: IOSSelector(label: 'Subscribe'), ); + + await $.native2.scrollTo(subscribeButtonSelector); + await $.native2.tap(subscribeButtonSelector); }); } diff --git a/dev/e2e_app/integration_test/webview_stackoverflow_test.dart b/dev/e2e_app/integration_test/webview_stackoverflow_test.dart index d31a2f7ac..252eb78e6 100644 --- a/dev/e2e_app/integration_test/webview_stackoverflow_test.dart +++ b/dev/e2e_app/integration_test/webview_stackoverflow_test.dart @@ -8,6 +8,8 @@ void main() { await $('Open webview (StackOverflow)').scrollTo().tap(); + await $.pump(Duration(seconds: 2)); + try { await $.native.tap(Selector(text: 'Accept all cookies')); } on PatrolActionException catch (_) { @@ -18,14 +20,22 @@ void main() { await $.pump(Duration(seconds: 2)); // bug: using `Email` and `Password` selectors doesn't work (#1554) - await $.native.enterTextByIndex('test@leancode.pl', index: 0); + await $.native.enterTextByIndex( + 'test@leancode.pl', + index: 0, + keyboardBehavior: KeyboardBehavior.alternative, + ); await $.native.swipe( from: Offset(0.5, 0.5), to: Offset(0.5, 0.1), ); - await $.native.enterTextByIndex('ny4ncat', index: 1); + await $.native.enterTextByIndex( + 'ny4ncat', + index: 1, + keyboardBehavior: KeyboardBehavior.alternative, + ); await $.native.tap(Selector(text: 'Log in')); }, ); @@ -37,6 +47,8 @@ void main() { await $('Open webview (StackOverflow)').scrollTo().tap(); + await $.pump(Duration(seconds: 2)); + try { await $.native2.tap( NativeSelector( @@ -57,14 +69,22 @@ void main() { await $.pump(Duration(seconds: 2)); // bug: using `Email` and `Password` selectors doesn't work (#1554) - await $.native2.enterTextByIndex('test@leancode.pl', index: 0); + await $.native2.enterTextByIndex( + 'test@leancode.pl', + index: 0, + keyboardBehavior: KeyboardBehavior.alternative, + ); await $.native.swipe( from: Offset(0.5, 0.5), to: Offset(0.5, 0.1), ); - await $.native2.enterTextByIndex('ny4ncat', index: 1); + await $.native2.enterTextByIndex( + 'ny4ncat', + index: 1, + keyboardBehavior: KeyboardBehavior.alternative, + ); await $.native2.tap( NativeSelector( android: AndroidSelector(text: 'Log in'), diff --git a/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/ContractsExtensions.kt b/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/ContractsExtensions.kt index 2ee234d2a..72a29501a 100644 --- a/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/ContractsExtensions.kt +++ b/packages/patrol/android/src/main/kotlin/pl/leancode/patrol/ContractsExtensions.kt @@ -252,10 +252,6 @@ fun AndroidSelector.toUiSelector(): UiSelector { } fun AndroidSelector.toBySelector(): BySelector { - if (hasInstance()) { - throw IllegalArgumentException("instance() argument is not supported for BySelector") - } - var selector: BySelector? = null if (hasClassName()) { diff --git a/packages/patrol/darwin/Classes/AutomatorServer/Automator/Automator.swift b/packages/patrol/darwin/Classes/AutomatorServer/Automator/Automator.swift index 398b84948..c0a804e1c 100644 --- a/packages/patrol/darwin/Classes/AutomatorServer/Automator/Automator.swift +++ b/packages/patrol/darwin/Classes/AutomatorServer/Automator/Automator.swift @@ -216,8 +216,8 @@ extension Selector { inApp bundleId: String, dismissKeyboard: Bool, withTimeout timeout: TimeInterval?, - dx: CGFloat, - dy: CGFloat + dx: Double?, + dy: Double? ) throws func enterText( _ data: String, @@ -225,8 +225,8 @@ extension Selector { inApp bundleId: String, dismissKeyboard: Bool, withTimeout timeout: TimeInterval?, - dx: CGFloat, - dy: CGFloat + dx: Double?, + dy: Double? ) throws func enterText( _ data: String, @@ -234,8 +234,8 @@ extension Selector { inApp bundleId: String, dismissKeyboard: Bool, withTimeout timeout: TimeInterval?, - dx: CGFloat, - dy: CGFloat + dx: Double?, + dy: Double? ) throws func swipe(from start: CGVector, to end: CGVector, inApp bundleId: String) throws func scrollTo( diff --git a/packages/patrol/darwin/Classes/AutomatorServer/Automator/IOSAutomator.swift b/packages/patrol/darwin/Classes/AutomatorServer/Automator/IOSAutomator.swift index 7e1fdc0d7..caa210944 100644 --- a/packages/patrol/darwin/Classes/AutomatorServer/Automator/IOSAutomator.swift +++ b/packages/patrol/darwin/Classes/AutomatorServer/Automator/IOSAutomator.swift @@ -183,8 +183,8 @@ inApp bundleId: String, dismissKeyboard: Bool, withTimeout timeout: TimeInterval?, - dx: CGFloat, - dy: CGFloat + dx: Double?, + dy: Double? ) throws { var data = data if dismissKeyboard { @@ -238,8 +238,8 @@ inApp bundleId: String, dismissKeyboard: Bool, withTimeout timeout: TimeInterval?, - dx: CGFloat, - dy: CGFloat + dx: Double?, + dy: Double? ) throws { var data = data if dismissKeyboard { @@ -276,8 +276,8 @@ inApp bundleId: String, dismissKeyboard: Bool, withTimeout timeout: TimeInterval?, - dx: CGFloat, - dy: CGFloat + dx: Double?, + dy: Double? ) throws { var data = data if dismissKeyboard { @@ -924,7 +924,7 @@ } // MARK: Private stuff - private func clearAndEnterText(data: String, element: XCUIElement, dx: CGFloat?, dy: CGFloat?) { + private func clearAndEnterText(data: String, element: XCUIElement, dx: Double?, dy: Double?) { let currentValue = element.value as? String var delete: String = "" if let value = currentValue { @@ -949,8 +949,8 @@ } let app = try self.getApp(withBundleId: bundleId) - let startCoordinate = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.9)) - let endCoordinate = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.1)) + let startCoordinate = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.7)) + let endCoordinate = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.3)) startCoordinate.press(forDuration: 0.1, thenDragTo: endCoordinate) attempts += 1 // Increment the scroll count after each scroll diff --git a/packages/patrol/darwin/Classes/AutomatorServer/AutomatorServer.swift b/packages/patrol/darwin/Classes/AutomatorServer/AutomatorServer.swift index 092a48a5c..ff4cbd5f9 100644 --- a/packages/patrol/darwin/Classes/AutomatorServer/AutomatorServer.swift +++ b/packages/patrol/darwin/Classes/AutomatorServer/AutomatorServer.swift @@ -175,8 +175,8 @@ inApp: request.appId, dismissKeyboard: request.keyboardBehavior == .showAndDismiss, withTimeout: request.timeoutMillis.map { TimeInterval($0 / 1000) }, - dx: request.dx ?? 0.9, - dy: request.dy ?? 0.9 + dx: request.dx, + dy: request.dy ) } else { throw PatrolError.internal("enterText(): neither index nor selector are set")