Skip to content

Commit

Permalink
add smoke integration test to verify that failed commands don't crash…
Browse files Browse the repository at this point in the history
… the automation server
  • Loading branch information
bartekpacia committed Mar 4, 2023
1 parent 0b9b20e commit 874df90
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/patrol/example/integration_test/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export 'package:example/main.dart';
export 'package:flutter_test/flutter_test.dart';
export 'package:patrol/patrol.dart';

final _patrolTesterConfig = PatrolTesterConfig();
final _nativeAutomatorConfig = NativeAutomatorConfig();
final globalPatrolTesterConfig = PatrolTesterConfig();
final globalNativeAutomatorConfig = NativeAutomatorConfig();

Future<void> createApp(PatrolTester $) async {
await setUpTimezone();
Expand All @@ -17,12 +17,14 @@ Future<void> createApp(PatrolTester $) async {
void patrol(
String description,
Future<void> Function(PatrolTester) callback, {
PatrolTesterConfig? patrolTesterConfig,
NativeAutomatorConfig? nativeAutomatorConfig,
bool? skip,
}) {
patrolTest(
description,
config: _patrolTesterConfig,
nativeAutomatorConfig: _nativeAutomatorConfig,
config: patrolTesterConfig ?? globalPatrolTesterConfig,
nativeAutomatorConfig: nativeAutomatorConfig ?? globalNativeAutomatorConfig,
nativeAutomation: true,
skip: skip,
callback,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import '../common.dart';

final _nativeAutomatorConfig = globalNativeAutomatorConfig.copyWith(
findTimeout: Duration(seconds: 3), // shorter timeout for this test
);

void main() {
patrol(
'native tap() fails gracefully',
nativeAutomatorConfig: _nativeAutomatorConfig,
($) async {
await createApp($);

await expectLater(
() => $.native.tap(Selector(text: 'This does not exist, boom!')),
throwsA(
isA<PatrolActionException>().having(
(err) => err.message,
'message',
contains('This does not exist, boom!'),
),
),
);
},
);

patrol(
'native enterText() fails gracefully',
nativeAutomatorConfig: _nativeAutomatorConfig,
($) async {
await createApp($);

await expectLater(
() => $.native.enterText(
Selector(text: 'This does not exist, boom!'),
text: 'some text',
),
throwsA(
isA<PatrolActionException>().having(
(err) => err.message,
'message',
contains('This does not exist, boom!'),
),
),
);
},
);

patrol(
'native enterTextByIndex() fails gracefully',
nativeAutomatorConfig: _nativeAutomatorConfig,
($) async {
await createApp($);

await expectLater(
() => $.native.enterTextByIndex('some text', index: 100),
throwsA(isA<PatrolActionException>()),
);
},
);
}

0 comments on commit 874df90

Please sign in to comment.