Skip to content

Instantly share code, notes, and snippets.

@themobilecoder
Last active May 19, 2020 11:35
Show Gist options
  • Save themobilecoder/51c824ef638171f6eb9a620ba3392a9c to your computer and use it in GitHub Desktop.
Save themobilecoder/51c824ef638171f6eb9a620ba3392a9c to your computer and use it in GitHub Desktop.
Flutter Integration Test code snippets
import 'package:flutter_driver/driver_extension.dart';
import 'package:flutter_integration_test/main.dart' as production_app;
void main() {
enableFlutterDriverExtension();
production_app.main();
}
import 'package:test/test.dart';
void main() {
group('Test happy case', () {
test('First test', () {});
});
}
dev_dependencies:
flutter_driver:
sdk: flutter
test: any
test('take a screenshot', () async {
final header = find.text('Contacts');
await driver.waitFor(header);
await Directory('screenshots').create();
final screenshot = await driver.screenshot();
final fileDescriptor = File('screenshots/contact_list.png');
fileDescriptor.writeAsBytes(screenshot);
});
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';
void main() {
group(
'Test happy case',
() {
FlutterDriver driver;
setUpAll(() async {
driver = await FlutterDriver.connect();
});
tearDownAll(() async {
driver?.close();
});
test('Verify health of Flutter driver', () async {
final health = await driver.checkHealth();
expect(health.status, equals(HealthStatus.ok));
});
},
);
}
test('Verify contact detail', () async {
final header = find.text('Contacts');
await driver.waitFor(header);
});
test('Verify contact detail', () async {
final header = find.text('Contacts');
await driver.waitFor(header);
final contactList = find.byType('CustomScrollView');
final ava = find.text('Ava Moreau');
await driver.scrollUntilVisible(
contactList,
ava,
dyScroll: -200.0,
);
await driver.tap(ava);
});
test('Verify contact detail', () async {
final header = find.text('Contacts');
final ava = find.text('Ava Moreau');
final contactList = find.byType('CustomScrollView');
await driver.waitFor(header);
await driver.waitFor(contactList);
await _scrollToWidget(contactList, ava);
await driver.tap(ava);
final mobile = find.text('078 637 62 26');
final email = find.text('[email protected]');
final streetLabel = find.text('Street');
final street = find.text('9733 Rue Louis-Garrand');
final cityLabel = find.text('City');
final city = find.text('Rudolfstetten-Friedlisberg');
final stateLabel = find.text('State');
final state = find.text('Graubünden');
final postCodeLabel = find.text('Post code');
final postCode = find.text('4551');
final backButton = find.pageBack();
await driver.waitFor(ava);
await driver.waitFor(mobile);
await driver.waitFor(email);
await driver.waitFor(streetLabel);
await driver.waitFor(street);
await driver.waitFor(cityLabel);
await driver.waitFor(city);
await driver.waitFor(stateLabel);
await driver.waitFor(state);
await driver.waitFor(postCodeLabel);
await driver.waitFor(postCode);
await driver.tap(backButton);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment