I'm using google flutter integration driver to automate the flutter mobile app.
I want to write multiple widgetTests in a single main_test.dart
file.
First test is running successfully, but when second test starts i see Test starting...
(attached screenshot below) screen in emulator, but actually not moving forward to launch the app screen.
And finally, getting below error saying that Bad state: No element
as screen is not loaded.!
Failure Details:
Failure in method: check value increments
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞═════════════════
The following StateError was thrown running a test:
Bad state: No element
When the exception was thrown, this was the stack:
#0 Iterable.single (dart:core/iterable.dart:654:25)
#1 WidgetController.element (package:flutter_test/src/controller.dart:114:30)
#2 WidgetController.ensureVisible (package:flutter_test/src/controller.dart:1210:73)
#3 main.<anonymous closure>.<anonymous closure> (file:///Users/tummalacharlajagadeesh/Desktop/Sparrow/synapse-cards-mobile/synapse-cards-mobile/integration_test/sanity_test.dart:87:20)
<asynchronous suspension>
Here is my integration test file main_test.dart
:
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:get_it/get_it.dart';
import 'package:integration_test/integration_test.dart';
import 'package:sparrowmobile/flavor/uat.dart' as app;
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
group('sanity test suite', () {
//runs before each test
setUp(() async {
app.main();
});
//runs after each test
tearDown(() async {
final getIt = GetIt.instance;
await getIt.reset();
});
testWidgets('sample test', (tester) async {
await tester.pumpAndSettle(const Duration(seconds: 5));
// ensure title is visible
await tester.ensureVisible(find.byKey(const ValueKey('startButton')));
await tester.tap(find.byKey(const ValueKey('startButton')));
await tester.pumpAndSettle();
expect(find.text('Home Screen'), findsOneWidget);
expect(find.text('Transactions'), findsOneWidget);
});
testWidgets('check value increments', (tester) async {
await tester.pumpAndSettle(const Duration(seconds: 10));
//ensure title is visible
await tester.ensureVisible(find.byKey(const ValueKey('startButton')));
await tester.tap(find.byKey(const ValueKey('startButton')));
await tester.pumpAndSettle();
});
});
}
Can anybody help here me to run multiple widgetTests in a single file?