-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
22.launch-args.test.js
112 lines (92 loc) · 3.58 KB
/
22.launch-args.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const _ = require('lodash');
// Note: Android-only as, according to Leo, on iOS there's no added value here compared to
// existing tests that check deep-link URLs. Combined with the fact that we do not yet
// support complex args on iOS -- no point in testing it out.
describe(':android: Launch arguments', () => {
beforeAll(async () => {
await device.selectApp('exampleWithArgs');
await device.launchApp();
});
async function assertLaunchArg(key, expectedValue) {
await expect(element(by.id(`launchArg-${key}.name`))).toBeVisible();
await expect(element(by.id(`launchArg-${key}.value`))).toHaveText(expectedValue);
}
async function assertNoLaunchArg(launchArgKey) {
await expect(element(by.id(`launchArg-${launchArgKey}.name`))).not.toBeVisible();
}
function assertPreconfiguredValue(expectedInitArgs) {
const initArgs = device.appLaunchArgs.get();
if (!_.isEqual(initArgs, expectedInitArgs)) {
throw new Error(`Precondition failure: Preconfigured launch arguments (in detox.config.js) do not match the expected value.\nExpected: ${JSON.stringify(expectedInitArgs)}\nReceived: ${JSON.stringify(initArgs)}`);
}
}
it('should handle primitive args when used on-site', async () => {
const launchArgs = {
hello: 'world',
seekthe: true,
heisthe: 1,
};
await device.launchApp({newInstance: true, launchArgs});
await element(by.text('Launch Args')).tap();
await assertLaunchArg('hello', 'world');
await assertLaunchArg('seekthe', 'true');
await assertLaunchArg('heisthe', '1');
});
it('should handle complex args when used on-site', async () => {
const launchArgs = {
complex: {
bull: ['s', 'h', 1, 't'],
and: {
then: 'so, me',
}
},
complexlist: ['arguments', 'https://haxorhost:1337'],
};
await device.launchApp({newInstance: true, launchArgs});
await element(by.text('Launch Args')).tap();
await assertLaunchArg('complex', JSON.stringify(launchArgs.complex));
await assertLaunchArg('complexlist', JSON.stringify(launchArgs.complexlist));
});
it('should allow for arguments modification', async () => {
const expectedInitArgs = { app: 'le', goo: 'gle?', micro: 'soft' };
assertPreconfiguredValue(expectedInitArgs);
device.appLaunchArgs.modify({
app: undefined, // delete
goo: 'gle!', // modify
ama: 'zon', // add
});
await device.launchApp({ newInstance: true });
await element(by.text('Launch Args')).tap();
await assertLaunchArg('goo', 'gle!');
await assertLaunchArg('ama', 'zon');
await assertLaunchArg('micro', 'soft');
await assertNoLaunchArg('app');
});
it('should allow for on-site arguments to take precedence', async () => {
const launchArgs = {
anArg: 'aValue!',
};
device.appLaunchArgs.reset();
device.appLaunchArgs.modify({
anArg: 'aValue?',
});
await device.launchApp({ newInstance: true, launchArgs });
await element(by.text('Launch Args')).tap();
await assertLaunchArg('anArg', 'aValue!');
});
// Ref: https://developer.android.com/studio/test/command-line#AMOptionsSyntax
it('should not pass android instrumentation args through', async () => {
const launchArgs = {
hello: 'world',
debug: false,
log: false,
size: 'large',
};
await device.launchApp({newInstance: true, launchArgs});
await element(by.text('Launch Args')).tap();
await assertLaunchArg('hello', 'world');
await assertNoLaunchArg('debug');
await assertNoLaunchArg('log');
await assertNoLaunchArg('size');
});
});