Masterarbeit Richard Stern. Flutter App, sich mit einem Bluetooth-Gerät verbindet und Berührungen auf einem Sensor visualisiert.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app_test.dart 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Imports the Flutter Driver API
  2. import 'dart:math';
  3. import 'dart:async';
  4. import 'dart:io';
  5. import 'package:flutter_driver/flutter_driver.dart';
  6. import 'package:test/test.dart';
  7. //import 'package:touch_demonstrator/ui/pageTouchPoints/ButtonOrAnimation.dart';
  8. //import 'package:flutter_test/flutter_test.dart';
  9. void main() {
  10. group('Test ', ()
  11. /* /// Test connection to Bluetooth Device. This test is not useful in simulator
  12. ///
  13. /// This test pushes the connect button and checks if the app connects
  14. /// to the demonstrator.
  15. */
  16. {
  17. // First, define the Finders. We can use these to locate Widgets from the
  18. // test suite. Note: the Strings provided to the `byValueKey` method must
  19. // be the same as the Strings we used for the Keys in step 1.
  20. final connectTextFinder = find.byValueKey('ConnectButton');
  21. final disconnectTextFinder = find.byValueKey('DisconnectButton');
  22. final buttonFinder = find.byValueKey('ConnectionButton');
  23. // final animationFinder = find.byValueKey('Animation');
  24. final logoFinder = find.byValueKey('Logo');
  25. final debugButtonFinder = find.byValueKey('debugButton');
  26. final debugListFinder = find.byValueKey('ListTouchData');
  27. final drawerFinder = find.byValueKey('Drawer');
  28. final drawerHeaderFinder = find.byValueKey('DrawerHeader');
  29. final drawerLastEntryFinder = find.byValueKey('Disclaimer');
  30. FlutterDriver driver;
  31. // Connect to the Flutter driver before running any tests
  32. setUpAll(() async {
  33. new Directory('screenshots').create();
  34. driver = await FlutterDriver.connect();
  35. // new Directory(‘screenshots’).create();
  36. });
  37. // Close the connection to the driver after the tests have completed
  38. tearDownAll(() async {
  39. if (driver != null) {
  40. driver.close();
  41. print('driver closed!');
  42. }
  43. });
  44. test('Connect to bluetooth device and then disconnect again', () async {
  45. await takeScreenshot(driver, 'screenshots/Not_connected.png');
  46. expect(await driver.getText(connectTextFinder), "Connect");
  47. await driver.tap(buttonFinder);
  48. expect(await driver.getText(disconnectTextFinder), "Disconnect");
  49. await takeScreenshot(driver, 'screenshots/Connected.png');
  50. await driver.tap(buttonFinder);
  51. expect(await driver.getText(connectTextFinder), "Connect");
  52. });
  53. /* test('Check drawer', () async {
  54. final SerializableFinder drawerOpenButton = find.byTooltip('Open navigation menu');
  55. await takeScreenshot(driver, 'screenshots/drawer_open.png');
  56. });*/
  57. test('Find Logo and tap it 3 times to get to debug page', () async {
  58. await driver.waitForAbsent(debugButtonFinder);
  59. await takeScreenshot(driver, 'screenshots/debug_disabled.png');
  60. for (var i = 0; i < 3; i++) {
  61. await driver.tap(logoFinder);
  62. }
  63. await driver.waitFor(debugButtonFinder);
  64. await takeScreenshot(driver, 'screenshots/debug_enabled.png');
  65. for (var i = 0; i < 3; i++) {
  66. await driver.tap(logoFinder);
  67. }
  68. await driver.waitForAbsent(debugButtonFinder);
  69. for (var i = 0; i < 3; i++) {
  70. await driver.tap(logoFinder);
  71. }
  72. await driver.tap(debugButtonFinder);
  73. await driver.waitFor(debugListFinder);
  74. await takeScreenshot(driver, 'screenshots/debug_page.png');
  75. });
  76. });
  77. }
  78. takeScreenshot(FlutterDriver driver, String path) async {
  79. final List<int> pixels = await driver.screenshot();
  80. final File file = new File(path);
  81. await file.writeAsBytes(pixels);
  82. print('wrote $file');
  83. print(path);
  84. }
  85. // run with:
  86. // flutter drive --target=test_driver/app.dart