[Ermine] Improved e2e test for status
- Updated screenshot logic to be device generic
- Screenshot test is overall more robust
TESTED=`fx run-e2e-tests experiences_ermine_session_shell_e2e_test`
Change-Id: Ie1cdc615f25be058e8f32a600b4e5595805bf8f6
diff --git a/tests/e2e/test/ermine_session_shell_status_test.dart b/tests/e2e/test/ermine_session_shell_status_test.dart
index d915a26..965da1f 100644
--- a/tests/e2e/test/ermine_session_shell_status_test.dart
+++ b/tests/e2e/test/ermine_session_shell_status_test.dart
@@ -14,12 +14,14 @@
int ermineBlack;
int ermineGray;
int ermineWhite;
+ int ermineLightGray;
setUp(() async {
sl4fDriver = Sl4f.fromEnvironment();
ermineBlack = Color.fromRgb(0, 0, 0);
ermineGray = Color.fromRgb(48, 48, 48);
ermineWhite = Color.fromRgb(255, 255, 255);
+ ermineLightGray = Color.fromRgb(158, 158, 158);
await sl4fDriver.startServer();
});
@@ -53,12 +55,20 @@
// allow time for ask to dismiss
await Future.delayed(Duration(seconds: 1));
- // Confirm screen is grey/blank before launching status menu.
+ // Get state of screen before launching status menu
+ // through histrogram of (color => number of pixels)
Image image = await Scenic(sl4fDriver).takeScreenshot();
- expect(image.getPixel(image.width - 20, 20), ermineGray);
- expect(image.getPixel(image.width - 250, 20), ermineGray);
- expect(image.getPixel(image.width - 40, 40), ermineGray);
- expect(image.getPixel(image.width - 400, 40), ermineGray);
+ final Map<int, int> histogram = {};
+ for (int i = 0; i < image.length; i += 4) {
+ final color = image[i];
+ histogram[color] = (histogram[color] ?? 0) + 1;
+ }
+
+ // Store initial distribution of central colors for test
+ final initialErmineWhitePixels = histogram[ermineWhite] ?? 0;
+ final initialErmineBlackPixels = histogram[ermineBlack] ?? 0;
+ final initialErmineGrayPixels = histogram[ermineGray] ?? 0;
+ final initialErmineLightGrayPixels = histogram[ermineLightGray] ?? 0;
// Inject 'F5' to trigger launching status.
await sl4fDriver.ssh.run('input keyevent 62');
@@ -66,13 +76,27 @@
// allow time for status startup
await Future.delayed(Duration(seconds: 1));
- // Confirm status menu has launched via checking if pixel in same
- // location has turned black
+ // Get state of screen after launching status menu
+ // through histogram of (color => number of pixels)
image = await Scenic(sl4fDriver).takeScreenshot();
- expect(image.getPixel(image.width - 20, 20), ermineBlack);
- expect(image.getPixel(image.width - 250, 20), ermineBlack);
- expect(image.getPixel(image.width - 40, 40), ermineWhite);
- expect(image.getPixel(image.width - 400, 40), ermineWhite);
+ histogram.clear();
+ for (int i = 0; i < image.length; i += 4) {
+ final color = image[i];
+ histogram[color] = (histogram[color] ?? 0) + 1;
+ }
+
+ // Store updated distribution of central colors for test
+ final finalErmineWhitePixels = histogram[ermineWhite] ?? 0;
+ final finalErmineBlackPixels = histogram[ermineBlack] ?? 0;
+ final finalErmineGrayPixels = histogram[ermineGray] ?? 0;
+ final finalErmineLightGrayPixels = histogram[ermineLightGray] ?? 0;
+
+ // Test to see if color distribution of pixels changed,
+ // which confirms status menu launch was successful
+ expect(initialErmineWhitePixels, lessThan(finalErmineWhitePixels));
+ expect(initialErmineBlackPixels, lessThan(finalErmineBlackPixels));
+ expect(initialErmineGrayPixels, greaterThan(finalErmineGrayPixels));
+ expect(initialErmineLightGrayPixels, lessThan(finalErmineLightGrayPixels));
// Logout for next test
await sl4fDriver.ssh.run('input keyevent 63');