Skip to content

Commit

Permalink
clean up webview tests, make them work reliably on Simulator and iPhone
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Oct 13, 2022
1 parent 85f9b97 commit be5e199
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 92 deletions.
49 changes: 7 additions & 42 deletions packages/patrol/example/integration_test/webview_a_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,19 @@ import 'config.dart';

Future<void> main() async {
patrolTest(
'navigates through the app using only native semantics',
'interacts with the LeanCode website in a webview',
config: patrolConfig,
nativeAutomation: true,
($) async {
await $.pumpWidgetAndSettle(ExampleApp());

await $('Open webview screen A').scrollTo();
await $('Open webview screen A').scrollTo().tap();

await $.native.tap(Selector(text: 'Open webview screen A'));

await $.pumpAndSettle();

await $.native.waitAndTap($, Selector(text: 'Accept cookies'));
await $.native.waitAndTap($, Selector(text: 'Select items'));
await $.native.waitAndTap($, Selector(text: 'Developer'));
await $.native.waitAndTap($, Selector(text: '1 item selected'));
await $.native.waitAndEnterTextByIndex(
$,
Selector(text: '1 item selected'),
text: 'test@leancode.pl',
index: 0,
);
await $.native.tap(Selector(text: 'Accept cookies'));
await $.native.tap(Selector(text: 'Select items'));
await $.native.tap(Selector(text: 'Developer'));
await $.native.tap(Selector(text: '1 item selected'));
await $.native.enterTextByIndex('test@leancode.pl', index: 0);
},
);
}

extension PatrolX on NativeAutomator {
Future<void> waitAndTap(PatrolTester $, Selector selector) async {
await tap(selector, appId: resolvedAppId);
//await $.pumpAndSettle();
}

Future<void> waitAndEnterText(
PatrolTester $,
Selector selector, {
required String text,
}) async {
await enterText(selector, text: text, appId: resolvedAppId);
//await $.pumpAndSettle();
}

Future<void> waitAndEnterTextByIndex(
PatrolTester $,
Selector selector, {
required String text,
required int index,
}) async {
await enterTextByIndex(text, index: index, appId: resolvedAppId);
//await $.pumpAndSettle();
}
}
47 changes: 5 additions & 42 deletions packages/patrol/example/integration_test/webview_b_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,17 @@ import 'config.dart';

Future<void> main() async {
patrolTest(
'navigates through the app using only native semantics',
'interacts with the orange website in a webview',
config: patrolConfig,
nativeAutomation: true,
($) async {
await $.pumpWidgetAndSettle(ExampleApp());

await $('Open webview screen B').scrollTo();
await $('Open webview screen B').scrollTo().tap();

await $.native.tap(Selector(text: 'Open webview screen B'));

await $.pumpAndSettle();

await $.native.waitAndTap($, Selector(text: 'login'));
await $.native.waitAndEnterTextByIndex(
$,
text: 'test@leancode.pl',
index: 0,
);
await $.native.waitAndEnterTextByIndex(
$,
text: 'ny4ncat',
index: 1,
);
await $.native.tap(Selector(text: 'login'));
await $.native.enterTextByIndex('test@leancode.pl', index: 0);
await $.native.enterTextByIndex('ny4ncat', index: 1);
},
);
}

extension PatrolX on NativeAutomator {
Future<void> waitAndTap(PatrolTester $, Selector selector) async {
await tap(selector, appId: resolvedAppId);
//await $.pumpAndSettle();
}

Future<void> waitAndEnterText(
PatrolTester $,
Selector selector, {
required String text,
}) async {
await enterText(selector, text: text, appId: resolvedAppId);
//await $.pumpAndSettle();
}

Future<void> waitAndEnterTextByIndex(
PatrolTester $, {
required String text,
required int index,
}) async {
await enterTextByIndex(text, index: index, appId: resolvedAppId);
//await $.pumpAndSettle();
}
}
16 changes: 8 additions & 8 deletions packages/patrol/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,6 @@ class _ExampleHomePageState extends State<ExampleHomePage> {
),
child: const Text('Open overlay screen'),
),
TextButton(
onPressed: () async => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const PermissionsScreen(),
),
),
child: const Text('Open permissions screen'),
),
TextButton(
onPressed: () async => Navigator.of(context).push(
MaterialPageRoute<void>(
Expand All @@ -194,6 +186,14 @@ class _ExampleHomePageState extends State<ExampleHomePage> {
),
child: const Text('Open webview screen B'),
),
TextButton(
onPressed: () async => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const PermissionsScreen(),
),
),
child: const Text('Open permissions screen'),
),
],
),
floatingActionButton: FloatingActionButton(
Expand Down

0 comments on commit be5e199

Please sign in to comment.