Last active
May 19, 2020 11:35
-
-
Save themobilecoder/51c824ef638171f6eb9a620ba3392a9c to your computer and use it in GitHub Desktop.
Flutter Integration Test code 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
import 'package:flutter_driver/driver_extension.dart'; | |
import 'package:flutter_integration_test/main.dart' as production_app; | |
void main() { | |
enableFlutterDriverExtension(); | |
production_app.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
import 'package:test/test.dart'; | |
void main() { | |
group('Test happy case', () { | |
test('First test', () {}); | |
}); | |
} |
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
dev_dependencies: | |
flutter_driver: | |
sdk: flutter | |
test: any |
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
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); | |
}); |
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 '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)); | |
}); | |
}, | |
); | |
} |
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
test('Verify contact detail', () async { | |
final header = find.text('Contacts'); | |
await driver.waitFor(header); | |
}); |
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
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); | |
}); |
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
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