Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated parameters from patrolTest #1892

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/patrol/example/integration_test/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ final _nativeAutomatorConfig = NativeAutomatorConfig(
findTimeout: Duration(seconds: 20), // 10 seconds is too short for some CIs
);

Future<void> createApp(PatrolTester $) async {
Future<void> createApp(PatrolIntegrationTester $) async {
await app_main.main();
}

void patrol(
String description,
Future<void> Function(PatrolTester) callback, {
Future<void> Function(PatrolIntegrationTester) callback, {
bool? skip,
NativeAutomatorConfig? nativeAutomatorConfig,
LiveTestWidgetsFlutterBindingFramePolicy framePolicy =
Expand All @@ -26,7 +26,6 @@ void patrol(
description,
config: _patrolTesterConfig,
nativeAutomatorConfig: nativeAutomatorConfig ?? _nativeAutomatorConfig,
nativeAutomation: true,
framePolicy: framePolicy,
skip: skip,
callback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void main() {
});
}

Future<void> _testBody(PatrolTester $) async {
Future<void> _testBody(PatrolIntegrationTester $) async {
await createApp($);

final testName = global_state.currentTestFullName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import '../common.dart';
const _timeout = Duration(seconds: 5); // to avoid timeouts on CI

// Firebase Test Lab pops out another dialog we need to handle
Future<void> tapOkIfGoogleDialogAppears(PatrolTester $) async {
Future<void> tapOkIfGoogleDialogAppears(PatrolIntegrationTester $) async {
var listWithOkText = <NativeView>[];
final inactivityTimer = Timer(Duration(seconds: 10), () {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() {
});
}

Future<void> _requestAndGrantCameraPermission(PatrolTester $) async {
Future<void> _requestAndGrantCameraPermission(PatrolIntegrationTester $) async {
if (!await Permission.camera.isGranted) {
expect($(#camera).$(#statusText).text, 'Not granted');
await $('Request camera permission').tap();
Expand All @@ -29,7 +29,9 @@ Future<void> _requestAndGrantCameraPermission(PatrolTester $) async {
expect($(#camera).$(#statusText).text, 'Granted');
}

Future<void> _requestAndGrantMicrophonePermission(PatrolTester $) async {
Future<void> _requestAndGrantMicrophonePermission(
PatrolIntegrationTester $,
) async {
if (!await Permission.microphone.isGranted) {
expect($(#microphone).$(#statusText).text, 'Not granted');
await $('Request microphone permission').tap();
Expand All @@ -42,7 +44,9 @@ Future<void> _requestAndGrantMicrophonePermission(PatrolTester $) async {
expect($(#microphone).$(#statusText).text, 'Granted');
}

Future<void> _requestAndDenyContactsPermission(PatrolTester $) async {
Future<void> _requestAndDenyContactsPermission(
PatrolIntegrationTester $,
) async {
if (!await Permission.contacts.isGranted) {
expect($(#contacts).$(#statusText).text, 'Not granted');
await $('Request contacts permission').tap();
Expand Down
24 changes: 5 additions & 19 deletions packages/patrol/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,16 @@ void patrolTest(
dynamic tags,
finders.PatrolTesterConfig config = const finders.PatrolTesterConfig(),
NativeAutomatorConfig nativeAutomatorConfig = const NativeAutomatorConfig(),
bool nativeAutomation = false,
LiveTestWidgetsFlutterBindingFramePolicy framePolicy =
LiveTestWidgetsFlutterBindingFramePolicy.fadePointers,
}) {
NativeAutomator? automator;
NativeAutomator automator;

PatrolBinding? patrolBinding;

if (!nativeAutomation) {
debugPrint('''
╔════════════════════════════════════════════════════════════════════════════════════╗
║ In next major release, patrolTest method will be intended for UI tests only ║
║ If you want to use Patrol in your widget tests, use patrol_finders package. ║
║ ║
║ For more information, see https://patrol.leancode.co/patrol-finders-release ║
╚════════════════════════════════════════════════════════════════════════════════════╝
''');
}

if (nativeAutomation) {
automator = NativeAutomator(config: nativeAutomatorConfig);
patrolBinding = PatrolBinding.ensureInitialized(nativeAutomatorConfig)
..framePolicy = framePolicy;
}
automator = NativeAutomator(config: nativeAutomatorConfig);
patrolBinding = PatrolBinding.ensureInitialized(nativeAutomatorConfig)
..framePolicy = framePolicy;

testWidgets(
description,
Expand Down Expand Up @@ -113,7 +99,7 @@ void patrolTest(
// See https://github.com/leancodepl/patrol/issues/1474
};
}
await automator?.configure();
await automator.configure();

final patrolTester = PatrolIntegrationTester(
tester: widgetTester,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import 'package:patrol/src/native/native_automator.dart';
import 'package:patrol_finders/patrol_finders.dart' as finders;

/// This typedef help us to avoid breaking changes.
@Deprecated(
'''
PatrolTester will be accessible only in patrol_finders package.
Use PatrolIntegrationTester in patrolTest callback
''',
)
typedef PatrolTester = PatrolIntegrationTester;

/// PatrolIntegrationTester extends the capabilities of [finders.PatrolTester]
/// with the ability to interact with native platform features via [native].
class PatrolIntegrationTester extends finders.PatrolTester {
Expand All @@ -23,18 +14,8 @@ class PatrolIntegrationTester extends finders.PatrolTester {
/// Native automator that allows for interaction with OS the app is running
/// on.
///
/// TODO This field will not be nullable or will be removed
final NativeAutomator? nativeAutomator;
final NativeAutomator nativeAutomator;

/// Shorthand for [nativeAutomator]. Throws if [nativeAutomator] is null,
/// which is the case if it wasn't initialized.
NativeAutomator get native {
assert(
nativeAutomator != null,
'NativeAutomator is not initialized. Make sure you passed '
"`nativeAutomation: true` to patrolTest(), and that you're *not* "
'initializing any bindings in your test.',
);
return nativeAutomator!;
}
/// Shorthand for [nativeAutomator].
NativeAutomator get native => nativeAutomator;
}
43 changes: 10 additions & 33 deletions packages/patrol_finders/lib/src/custom_finders/patrol_finder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,21 @@ class PatrolFinder extends MatchFinder {
/// ```
///
/// This method automatically calls [WidgetTester.pumpAndSettle] after
/// tapping. If you want to disable this behavior, set [andSettle] to false.
/// tapping. If you want to disable this behavior, set [settlePolicy] to
/// [SettlePolicy.noSettle].
///
/// See also:
/// - [PatrolFinder.waitUntilVisible], which is used to wait for the widget
/// to appear
/// - [WidgetController.tap]
Future<void> tap({
@Deprecated('Use settlePolicy argument instead') bool? andSettle,
SettlePolicy? settlePolicy,
Duration? visibleTimeout,
Duration? settleTimeout,
}) async {
await tester.tap(
this,
settlePolicy: chooseSettlePolicy(
andSettle: andSettle,
settlePolicy: settlePolicy,
),
settlePolicy: settlePolicy,
visibleTimeout: visibleTimeout,
settleTimeout: settleTimeout,
);
Expand Down Expand Up @@ -241,17 +238,13 @@ class PatrolFinder extends MatchFinder {
/// to appear
/// - [WidgetController.longPress]
Future<void> longPress({
@Deprecated('Use settlePolicy argument instead') bool? andSettle,
SettlePolicy? settlePolicy,
Duration? visibleTimeout,
Duration? settleTimeout,
}) async {
await tester.longPress(
this,
settlePolicy: chooseSettlePolicy(
andSettle: andSettle,
settlePolicy: settlePolicy,
),
settlePolicy: settlePolicy,
visibleTimeout: visibleTimeout,
settleTimeout: settleTimeout,
);
Expand All @@ -275,27 +268,23 @@ class PatrolFinder extends MatchFinder {
/// ```
///
/// This method automatically calls [WidgetTester.pumpAndSettle] after
/// entering text. If you want to disable this behavior, set [andSettle] to
/// false.
/// entering text. If you want to disable this behavior, set [settlePolicy] to
/// [SettlePolicy.noSettle].
///
/// See also:
/// - [PatrolFinder.waitUntilVisible], which is used to wait for the widget
/// to appear
/// - [WidgetTester.enterText]
Future<void> enterText(
String text, {
@Deprecated('Use settlePolicy instead') bool? andSettle,
SettlePolicy? settlePolicy,
Duration? visibleTimeout,
Duration? settleTimeout,
}) async {
await tester.enterText(
this,
text,
settlePolicy: chooseSettlePolicy(
andSettle: andSettle,
settlePolicy: settlePolicy,
),
settlePolicy: settlePolicy,
visibleTimeout: visibleTimeout,
settleTimeout: settleTimeout,
);
Expand All @@ -318,7 +307,6 @@ class PatrolFinder extends MatchFinder {
int maxScrolls = defaultScrollMaxIteration,
Duration? settleBetweenScrollsTimeout,
Duration? dragDuration,
@Deprecated('Use settlePolicy argument instead') bool? andSettle,
SettlePolicy? settlePolicy,
}) {
return tester.scrollUntilVisible(
Expand All @@ -328,10 +316,7 @@ class PatrolFinder extends MatchFinder {
scrollDirection: scrollDirection,
maxScrolls: maxScrolls,
settleBetweenScrollsTimeout: settleBetweenScrollsTimeout,
settlePolicy: chooseSettlePolicy(
andSettle: andSettle,
settlePolicy: settlePolicy,
),
settlePolicy: settlePolicy,
dragDuration: dragDuration,
);
}
Expand Down Expand Up @@ -528,16 +513,12 @@ extension ActionCombiner on Future<PatrolFinder> {
/// Same as [PatrolFinder.tap], but on a [PatrolFinder] which is not yet
/// visible.
Future<void> tap({
@Deprecated('Use settlePolicy argument instead') bool? andSettle,
SettlePolicy? settlePolicy,
Duration? visibleTimeout,
Duration? settleTimoeut,
}) async {
await (await this).tap(
settlePolicy: chooseSettlePolicy(
andSettle: andSettle,
settlePolicy: settlePolicy,
),
settlePolicy: settlePolicy,
visibleTimeout: visibleTimeout,
settleTimeout: settleTimoeut,
);
Expand All @@ -547,17 +528,13 @@ extension ActionCombiner on Future<PatrolFinder> {
/// visible.
Future<void> enterText(
String text, {
@Deprecated('Use settlePolicy argument instead') bool? andSettle,
SettlePolicy? settlePolicy,
Duration? visibleTimeout,
Duration? settleTimoeut,
}) async {
await (await this).enterText(
text,
settlePolicy: chooseSettlePolicy(
andSettle: andSettle,
settlePolicy: settlePolicy,
),
settlePolicy: settlePolicy,
visibleTimeout: visibleTimeout,
settleTimeout: settleTimoeut,
);
Expand Down
Loading
Loading