Quellcode durchsuchen

Migrate espresso suite to detox cont.

Guy Carmeli vor 6 Jahren
Ursprung
Commit
b189893ffd
5 geänderte Dateien mit 158 neuen und 17 gelöschten Zeilen
  1. 23
    0
      e2e/AndroidUtils.js
  2. 117
    0
      e2e/ApplicationLifecycleTest.test.js
  3. 17
    1
      e2e/ScreenStack.test.js
  4. 0
    13
      e2e/TopLevelApi.test.js
  5. 1
    3
      e2e/Utils.js

+ 23
- 0
e2e/AndroidUtils.js Datei anzeigen

@@ -0,0 +1,23 @@
1
+const exec = require('shell-utils').exec;
2
+
3
+module.exports = {
4
+  pressBack: () => {
5
+    exec.execSync('adb shell input keyevent 4');
6
+  },
7
+  pressMenu: () => {
8
+    exec.execSync('adb shell input keyevent 82');
9
+  },
10
+  pressKeyCode: (keyCode) => {
11
+    exec.execSync(`adb shell input keyevent ${keyCode}`);
12
+  },
13
+  grantPermission: () => {
14
+    exec.execSync('adb shell pm grant com.reactnativenavigation.playground android.permission.READ_PHONE_STATE');
15
+  },
16
+  revokePermission: () => {
17
+    exec.execSync('adb shell pm revoke com.reactnativenavigation.playground android.permission.READ_PHONE_STATE');
18
+  },
19
+  openActivity: () => {
20
+    exec.execSync('adb shell am start -n com.reactnativenavigation.playground/.MainActivity');
21
+  },
22
+  executeShellCommand: (command) => exec.execSync(`adb shell ${command}`)
23
+}

+ 117
- 0
e2e/ApplicationLifecycleTest.test.js Datei anzeigen

@@ -0,0 +1,117 @@
1
+const Utils = require('./Utils');
2
+const Android = require('./AndroidUtils');
3
+const testIDs = require('../playground/src/testIDs');
4
+const exec = require('shell-utils').exec;
5
+const _ = require('lodash');
6
+
7
+const { elementByLabel, elementById, sleep } = Utils;
8
+const IS_RELEASE = _.includes(process.argv, '--release');
9
+const KEY_CODE_R = 46;
10
+
11
+describe('application lifecycle test', () => {
12
+  beforeEach(async () => {
13
+    await device.relaunchApp();
14
+  });
15
+
16
+  it('push a screen to ensure its not there after reload', async () => {
17
+    await elementById(testIDs.PUSH_BUTTON).tap();
18
+    await expect(elementByLabel('Pushed Screen')).toBeVisible();
19
+    await device.reloadReactNative();
20
+    await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
21
+  });
22
+
23
+  it(':android: relaunch from background', async () => {
24
+    await elementById(testIDs.PUSH_BUTTON).tap();
25
+    await expect(elementByLabel('Pushed Screen')).toBeVisible();
26
+
27
+    await device.sendToHome();
28
+    await device.launchApp();
29
+
30
+    await expect(elementByLabel('Pushed Screen')).toBeVisible();
31
+  });
32
+
33
+  it(':android: relaunch after close with back button', async () => {
34
+    await elementById(testIDs.PUSH_BUTTON).tap();
35
+    await expect(elementByLabel('Pushed Screen')).toBeVisible();
36
+
37
+    Android.pressBack();
38
+
39
+    await device.launchApp();
40
+    await expect(elementByLabel('Pushed Screen')).toBeNotVisible();
41
+  });
42
+
43
+  it(':android: device orientation does not destroy activity', async () => {
44
+    await elementById(testIDs.PUSH_BUTTON).tap();
45
+    await expect(elementByLabel('Pushed Screen')).toBeVisible();
46
+    
47
+    await device.setOrientation('landscape');
48
+
49
+    await expect(elementByLabel('Pushed Screen')).toBeVisible();
50
+  });
51
+
52
+  it(':android: relaunch after activity killed by system', async () => {
53
+    await elementById(testIDs.PUSH_BUTTON).tap();
54
+    await expect(elementByLabel('Pushed Screen')).toBeVisible();
55
+    await device.sendToHome();
56
+
57
+    await togglePhonePermission();
58
+    await device.launchApp();
59
+
60
+    await expect(elementByLabel('Pushed Screen')).toBeNotVisible();
61
+    await expect(elementByLabel('React Native Navigation!')).toBeVisible();
62
+  });
63
+  
64
+  xit(':android: pressing menu opens dev menu', async () => {
65
+    if (!IS_RELEASE) {
66
+      Android.pressMenu();
67
+      await sleep(1000);
68
+      await expect(elementByLabel('Reload')).toBeVisible();
69
+    }
70
+  });
71
+
72
+  xit(':android: pressing r twice in succession reloads React Native', async () => {
73
+    if (!IS_RELEASE) {
74
+      await elementById(testIDs.PUSH_BUTTON).tap();
75
+      await expect(elementByLabel('Pushed Screen')).toBeVisible();
76
+
77
+      Android.pressKeyCode(KEY_CODE_R);
78
+      Android.pressKeyCode(KEY_CODE_R);
79
+
80
+      await sleep(300);
81
+      await expect(elementByLabel('React Native Navigation!')).toBeVisible();
82
+    }
83
+  });
84
+
85
+  it(':android: pressing r twice with delay does nothing', async () => {
86
+    if (!IS_RELEASE) {
87
+      await elementById(testIDs.PUSH_BUTTON).tap();
88
+      await expect(elementByLabel('Pushed Screen')).toBeVisible();
89
+
90
+      Android.pressKeyCode(KEY_CODE_R);
91
+      await sleep(1000);
92
+      Android.pressKeyCode(KEY_CODE_R);
93
+
94
+      await expect(elementByLabel('Pushed Screen')).toBeVisible();
95
+    }
96
+  });
97
+
98
+  xit(':android: sending reload broadcast reloads react native', async () => {
99
+    if (!IS_RELEASE) {
100
+      await elementById(testIDs.PUSH_BUTTON).tap();
101
+      await expect(elementByLabel('Pushed Screen')).toBeVisible();
102
+
103
+      Android.executeShellCommand('am broadcast -a com.reactnativenavigation.broadcast.RELOAD');
104
+      
105
+      await sleep(1000);
106
+      await expect(elementByLabel('React Native Navigation!')).toBeVisible();
107
+    }
108
+  });
109
+  
110
+  async function togglePhonePermission() {
111
+    await sleep(700);
112
+    Android.revokePermission();
113
+    await sleep(700);
114
+    Android.grantPermission();
115
+    await sleep(1000);
116
+  }
117
+});

+ 17
- 1
e2e/ScreenStack.test.js Datei anzeigen

@@ -1,7 +1,8 @@
1 1
 const Utils = require('./Utils');
2 2
 const testIDs = require('../playground/src/testIDs');
3
+const Android = require('./AndroidUtils');
3 4
 
4
-const { elementByLabel, elementById } = Utils;
5
+const { elementByLabel, elementById, sleep } = Utils;
5 6
 
6 7
 describe('screen stack', () => {
7 8
   beforeEach(async () => {
@@ -73,4 +74,19 @@ describe('screen stack', () => {
73 74
     await expect(elementById('TestLabel')).toBeVisible();
74 75
     await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
75 76
   });
77
+
78
+  it.only(':android: override hardware back button', async () => {
79
+    await elementByLabel('BACK HANDLER').tap();
80
+    await expect(elementByLabel('Back Handler Screen')).toBeVisible();
81
+
82
+    await elementByLabel('ADD BACK HANDLER').tap();
83
+    Android.pressBack();
84
+    await sleep(100);
85
+    await expect(elementByLabel('Back Handler Screen')).toBeVisible();
86
+
87
+    await elementByLabel('REMOVE BACK HANDLER').tap();
88
+    Android.pressBack();
89
+    await sleep(100);
90
+    await expect(elementByLabel('React Native Navigation!')).toBeVisible();
91
+  });
76 92
 });

+ 0
- 13
e2e/TopLevelApi.test.js Datei anzeigen

@@ -40,16 +40,3 @@ describe('top level api', () => {
40 40
     await expect(elementByLabel('didDisappear')).toBeVisible();
41 41
   });
42 42
 });
43
-
44
-describe('reload app', async () => {
45
-  beforeEach(async () => {
46
-    await device.relaunchApp();
47
-  });
48
-
49
-  it('push a screen to ensure its not there after reload', async () => {
50
-    await elementById(testIDs.PUSH_BUTTON).tap();
51
-    await expect(elementByLabel('Pushed Screen')).toBeVisible();
52
-    await device.reloadReactNative();
53
-    await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
54
-  });
55
-});

+ 1
- 3
e2e/Utils.js Datei anzeigen

@@ -14,7 +14,5 @@ module.exports = {
14 14
       return element(by.type('_UIModernBarButton').and(by.label('Back'))).tap();
15 15
     }
16 16
   },
17
-  tapDeviceBackAndroid: () => {
18
-    exec.execSync('adb shell input keyevent 4');
19
-  }
17
+  sleep: ms => new Promise(res => setTimeout(res, ms))
20 18
 };