Browse Source

New detox test command to run test cases when device is locked, one f… (#5159)

new detox test command to run test cases when device is locked, one failing test case for Android when app is running by tapping on a notification and device is locked and the app is not running in the background.
Varun Gupta 5 years ago
parent
commit
8c8a3c1f13
4 changed files with 73 additions and 1 deletions
  1. 12
    0
      e2e/AndroidUtils.js
  2. 34
    0
      e2e/DeviceLocked.test.js
  3. 14
    1
      package.json
  4. 13
    0
      scripts/test-e2e-android-locked.js

+ 12
- 0
e2e/AndroidUtils.js View File

7
   pressMenu: () => {
7
   pressMenu: () => {
8
     exec.execSync('adb shell input keyevent 82');
8
     exec.execSync('adb shell input keyevent 82');
9
   },
9
   },
10
+  pressEnter: (keyCode) => {
11
+    exec.execSync(`adb shell input keyevent 66`);
12
+  },
13
+  pressLockButton: () => {
14
+    exec.execSync(`adb shell input keyevent 26`);
15
+  },
10
   pressKeyCode: (keyCode) => {
16
   pressKeyCode: (keyCode) => {
11
     exec.execSync(`adb shell input keyevent ${keyCode}`);
17
     exec.execSync(`adb shell input keyevent ${keyCode}`);
12
   },
18
   },
21
   },
27
   },
22
   executeShellCommand: (command) => {
28
   executeShellCommand: (command) => {
23
     exec.execSync(`adb shell ${command}`);
29
     exec.execSync(`adb shell ${command}`);
30
+  },
31
+  enterText: (text) => {
32
+    exec.execSync(`adb shell input text ${text}`);
33
+  },
34
+  swipeUp: () => {
35
+    exec.execSync('adb shell input touchscreen swipe 300 1200 500 0 100');
24
   }
36
   }
25
 };
37
 };

+ 34
- 0
e2e/DeviceLocked.test.js View File

1
+const Utils = require('./Utils');
2
+const Android = require('./AndroidUtils');
3
+
4
+const { elementByLabel } = Utils;
5
+
6
+xdescribe(':android: Android phone locked tests', () => {
7
+  beforeEach(async () => {
8
+    await device.relaunchApp();
9
+  });
10
+
11
+  test('launch from locked screen', async () => {
12
+    await device.terminateApp();
13
+    await Android.pressLockButton();
14
+    await Android.pressLockButton();
15
+    await device.launchApp();
16
+    await Android.swipeUp();
17
+    // The device should be locked using PIN 1234
18
+    await Android.enterText('1234');
19
+    await Android.pressEnter();
20
+    await expect(elementByLabel('React Native Navigation!')).toBeVisible();
21
+  });
22
+
23
+  test('launch app from unlocked screen', async () => {
24
+    await device.terminateApp();
25
+    await Android.pressLockButton();
26
+    await Android.pressLockButton();
27
+    await Android.swipeUp();
28
+    // The device should be locked using PIN 1234
29
+    await Android.enterText('1234');
30
+    await Android.pressEnter();
31
+    await device.launchApp();
32
+    await expect(elementByLabel('React Native Navigation!')).toBeVisible();
33
+  });
34
+});

+ 14
- 1
package.json View File

32
     "test-unit-android": "node ./scripts/test-unit --android",
32
     "test-unit-android": "node ./scripts/test-unit --android",
33
     "pretest-e2e-android": "npm run build",
33
     "pretest-e2e-android": "npm run build",
34
     "test-e2e-android": "node ./scripts/test-e2e --android",
34
     "test-e2e-android": "node ./scripts/test-e2e --android",
35
+    "test-e2e-android-locked": "node ./scripts/test-e2e-android-locked",
35
     "pretest-e2e-ios": "npm run build",
36
     "pretest-e2e-ios": "npm run build",
36
     "test-e2e-ios": "node ./scripts/test-e2e --ios",
37
     "test-e2e-ios": "node ./scripts/test-e2e --ios",
37
     "test-e2e-ios-multi": "npm run test-e2e-ios -- --multi",
38
     "test-e2e-ios-multi": "npm run test-e2e-ios -- --multi",
149
         "build": "cd playground/android && ./gradlew app:assembleRelease app:assembleAndroidTest -DtestBuildType=release",
150
         "build": "cd playground/android && ./gradlew app:assembleRelease app:assembleAndroidTest -DtestBuildType=release",
150
         "type": "android.emulator",
151
         "type": "android.emulator",
151
         "name": "Pixel_2_API_26"
152
         "name": "Pixel_2_API_26"
153
+      },
154
+      "android.emu.debug.locked": {
155
+        "binaryPath": "playground/android/app/build/outputs/apk/debug/app-debug.apk",
156
+        "build": "cd playground/android && ./gradlew app:assembleDebug app:assembleAndroidTest -DtestBuildType=debug",
157
+        "type": "android.emulator",
158
+        "name": "Nexus_5_API_25"
159
+      },
160
+      "android.emu.release.locked": {
161
+        "binaryPath": "playground/android/app/build/outputs/apk/release/app-release.apk",
162
+        "build": "cd playground/android && ./gradlew app:assembleRelease app:assembleAndroidTest -DtestBuildType=release",
163
+        "type": "android.emulator",
164
+        "name": "Nexus_5_API_25"
152
       }
165
       }
153
     }
166
     }
154
   }
167
   }
155
-}
168
+}

+ 13
- 0
scripts/test-e2e-android-locked.js View File

1
+const _ = require('lodash');
2
+const exec = require('shell-utils').exec;
3
+
4
+const release = _.includes(process.argv, '--release');
5
+
6
+run();
7
+
8
+function run() {
9
+    const suffix = release ? `release` : `debug`;
10
+    const configuration = `android.emu.${suffix}.locked`;
11
+
12
+    exec.execSync(`detox test --configuration ${configuration} -f "DeviceLocked.test.js"`)
13
+}