// Imports the Flutter Driver API import 'dart:math'; import 'dart:async'; import 'dart:io'; import 'package:flutter_driver/flutter_driver.dart'; import 'package:test/test.dart'; //import 'package:touch_demonstrator/ui/pageTouchPoints/ButtonOrAnimation.dart'; //import 'package:flutter_test/flutter_test.dart'; void main() { group('Test ', () /* /// Test connection to Bluetooth Device. This test is not useful in simulator /// /// This test pushes the connect button and checks if the app connects /// to the demonstrator. */ { // First, define the Finders. We can use these to locate Widgets from the // test suite. Note: the Strings provided to the `byValueKey` method must // be the same as the Strings we used for the Keys in step 1. final connectTextFinder = find.byValueKey('ConnectButton'); final disconnectTextFinder = find.byValueKey('DisconnectButton'); final buttonFinder = find.byValueKey('ConnectionButton'); // final animationFinder = find.byValueKey('Animation'); final logoFinder = find.byValueKey('Logo'); final debugButtonFinder = find.byValueKey('debugButton'); final debugListFinder = find.byValueKey('ListTouchData'); final drawerFinder = find.byValueKey('Drawer'); final drawerHeaderFinder = find.byValueKey('DrawerHeader'); final drawerLastEntryFinder = find.byValueKey('Disclaimer'); FlutterDriver driver; // Connect to the Flutter driver before running any tests setUpAll(() async { new Directory('screenshots').create(); driver = await FlutterDriver.connect(); // new Directory(‘screenshots’).create(); }); // Close the connection to the driver after the tests have completed tearDownAll(() async { if (driver != null) { driver.close(); print('driver closed!'); } }); test('Connect to bluetooth device and then disconnect again', () async { await takeScreenshot(driver, 'screenshots/Not_connected.png'); expect(await driver.getText(connectTextFinder), "Connect"); await driver.tap(buttonFinder); expect(await driver.getText(disconnectTextFinder), "Disconnect"); await takeScreenshot(driver, 'screenshots/Connected.png'); await driver.tap(buttonFinder); expect(await driver.getText(connectTextFinder), "Connect"); }); /* test('Check drawer', () async { final SerializableFinder drawerOpenButton = find.byTooltip('Open navigation menu'); await takeScreenshot(driver, 'screenshots/drawer_open.png'); });*/ test('Find Logo and tap it 3 times to get to debug page', () async { await driver.waitForAbsent(debugButtonFinder); await takeScreenshot(driver, 'screenshots/debug_disabled.png'); for (var i = 0; i < 3; i++) { await driver.tap(logoFinder); } await driver.waitFor(debugButtonFinder); await takeScreenshot(driver, 'screenshots/debug_enabled.png'); for (var i = 0; i < 3; i++) { await driver.tap(logoFinder); } await driver.waitForAbsent(debugButtonFinder); for (var i = 0; i < 3; i++) { await driver.tap(logoFinder); } await driver.tap(debugButtonFinder); await driver.waitFor(debugListFinder); await takeScreenshot(driver, 'screenshots/debug_page.png'); }); }); } takeScreenshot(FlutterDriver driver, String path) async { final List pixels = await driver.screenshot(); final File file = new File(path); await file.writeAsBytes(pixels); print('wrote $file'); print(path); } // run with: // flutter drive --target=test_driver/app.dart