Last active
June 5, 2023 13:20
-
-
Save bartekpacia/40aba128bcbfac15018e2a39c5b097c0 to your computer and use it in GitHub Desktop.
Fluttercon snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testWidgets('signs up', (WidgetTester tester) async { | |
await tester.pumpWidget(ExampleApp()); | |
await tester.pumpAndSettle(); | |
await tester.enterText( | |
find.byKey(Key('emailTextField')), | |
'charlie@root.me', | |
); | |
await tester.pumpAndSettle(); | |
await tester.enterText( | |
find.byKey(Key('nameTextField')), | |
'Charlie', | |
); | |
await tester.pumpAndSettle(); | |
await tester.enterText( | |
find.byKey(Key('passwordTextField')), | |
'ny4ncat', | |
); | |
await tester.pumpAndSettle(); | |
await tester.tap(find.byKey(Key('termsCheckbox'))); | |
await tester.pumpAndSettle(); | |
await tester.tap(find.byKey(Key('signUpButton'))); | |
await tester.pumpAndSettle(); | |
expect(find.text('Welcome, Charlie!'), findsOneWidget); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await tester.tap( | |
find.ancestor( | |
of: find.text('Activated'), | |
matching: find.descendant( | |
of: find.byType(ListTile), | |
matching: find.byKey(Key('learnMore')), | |
), | |
).first, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'alpha_test.dart' as alpha_test; | |
import 'bravo_test.dart' as bravo_test; | |
import 'delta_test.dart' as delta_test; | |
import 'zulu_test.dart' as zulu_test; | |
void main(){ | |
group('bundled tests', () { | |
alpha_test.main(); | |
bravo_test.main(); | |
delta_test.main(); | |
zulu_test.main(); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patrolTest('demo', nativeAutomation: true, (PatrolTester $) async { | |
await $.pumpWidgetAndSettle(ExampleApp()); | |
// prepare network conditions | |
await $.native.enableCellular(); | |
await $.native.disableWifi(); | |
// toggle system theme | |
await $.native.enableDarkMode(); | |
// handle permission request dialog about location | |
await $.native.selectFineLocation(); | |
await $.native.grantPermissionWhenInUse(); | |
// open drawer and tap on the first notification | |
await $.native.openNotifications(); | |
await $.native.tapOnNotificationByIndex(0) ; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patrolTest( | |
'grants various permissions', | |
nativeAutomation: true, | |
(PatrolTester $) async { | |
await $.pumpWidgetAndSettle(ExampleApp()); | |
await $('Open permissions screen').scrollTo().tap(); | |
await $('Request camera permission').tap(); | |
await $.native.grantPermissionWhenInUse(); | |
await $('Request microphone permission').tap(); | |
await $.native.grantPermissionWhenInUse(); | |
await $('Request contacts permission').tap(); | |
await $.native.denyPermission(); | |
}, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patrolTest( | |
'taps on notification', | |
nativeAutomation: true, | |
(PatrolTester $) async { | |
await $.pumpWidgetAndSettle(ExampleApp()); | |
await $('Open notifications screen').tap(); | |
await $.native.grantPermissionWhenInUse(); | |
await $('Show in a few seconds').tap(); | |
await $.native.pressHome(); | |
await $.native.openNotifications(); | |
await $.native.tapOnNotificationBySelector( | |
Selector(textContains: 'Someone liked'), | |
); | |
await $(RegExp('ID: 1')).waitUntilVisible(); | |
}, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patrolTest( | |
'accepts location permission', | |
nativeAutomation: true, | |
(PatrolTester $) async { | |
await $.pumpWidgetAndSettle(ExampleApp()); | |
await $('Open location screen').scrollTo().tap(); | |
await $('Grant permission').tap() ; | |
await $.native.selectCoarseLocation(); | |
await $.native.selectFineLocation(); | |
await $.native.selectCoarseLocation(); | |
await $.native.selectFineLocation(); | |
await $.native.grantPermission0nlyThisTime(); | |
await $(RegExp('lat')).waitUntilVisible(); | |
await $(RegExp('Ing')).waitUntilVisible(); | |
}, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await $('Sign in').tap(); | |
await $('Email').enterText('charlie@root.me'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(ListView) // -> find.byType(ListView) | |
$('Subscribe') // -> find.text('Subscribe') | |
$(#signInButton) // -> find.byKey(Key('signInButton')) | |
$(Icons.add) // -> find.byIcon(Icons.add) | |
$(RegExp(r'\d+ USD')) // -> find.textContaining(RegExp(r'\d+ USD')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testWidgets('signs up', (WidgetTester tester) async { | |
await tester.pumpWidget(ExampleApp()); | |
await tester.pumpAndSettle(); | |
await tester.enterText( | |
find.byKey(Key('emailTextField')), | |
'charlie@root.me', | |
); | |
await tester.pumpAndSettle(); | |
await tester.enterText( | |
find.byKey(Key('nameTextField')), | |
'Charlie', | |
); | |
await tester.pumpAndSettle(); | |
await tester.enterText( | |
find.byKey(Key('passwordTextField')), | |
'ny4ncat', | |
); | |
await tester.pumpAndSettle(); | |
await tester.tap(find.byKey(Key('termsCheckbox'))); | |
await tester.pumpAndSettle(); | |
await tester.tap(find.byKey(Key('signUpButton'))); | |
await tester.pumpAndSettle(); | |
expect(find.text('Welcome, Charlie!'), findsOneWidget); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patrolTest('signs up', (PatrolTester $) async { | |
await $.pumpWidgetAndSettle(ExampleApp()); | |
await $(#emailTextField).enterText('charlie@root.me'); | |
await $(#nameTextField).enterText('Charlie'); | |
await $(#passwordTextField).enterText('ny4ncat'); | |
await $(#termsCheckbox).tap(); | |
await $(#signUpButton).tap(); | |
await $('Welcome, Charlie!').waitUntilVisible(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: Wait until below is visible | |
await tester.tap( | |
find.descendant( | |
of: find.byType(ListView), | |
matching: find.text('Subscribe'), | |
).first, | |
); | |
await tester.pumpAndSettle(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await $(ListView).$('Subscribe').tap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: Wait until below is visible | |
await tester.tap( | |
find.ancestor( | |
of: find.text('Activated'), | |
matching: find.descendant( | |
of: find.byType(ListTile), | |
matching: find.byKey(Key('learnMore')), | |
), | |
).first, | |
); | |
await tester.pumpAndSettle(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await $(ListTile).containing('Activated').$(#learnMore).tap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patrolTest('adds comment', (PatrolTester $) async { | |
final WidgetTester tester = $.tester; | |
await tester.enterText( | |
find.byKey(Key('commentTextField')), | |
'Everything is a widget (not really)', | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment