-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
index.js
169 lines (142 loc) · 5.39 KB
/
index.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// import * as wdio from 'webdriverio';
// import * as assert from 'assert';
const wdio = require('webdriverio');
const assert = require('assert');
const find = require('appium-flutter-finder');
const osSpecificOps =
process.env.APPIUM_OS === 'android'
? {
platformName: 'Android',
deviceName: 'Pixel 2',
// @todo support non-unix style path
app: __dirname + '/../../apps/android-real-debug.apk' // download local to run faster and save bandwith
// app: 'https://github.com/truongsinh/appium-flutter-driver/releases/download/v0.0.4/android-real-debug.apk',
}
: process.env.APPIUM_OS === 'ios'
? {
platformName: 'iOS',
platformVersion: '12.2',
deviceName: 'iPhone X',
noReset: true,
app: __dirname + '/../../apps/ios-sim-debug.zip' // download local to run faster and save bandwith
// app: 'https://github.com/truongsinh/appium-flutter-driver/releases/download/v0.0.4/ios-sim-debug.zip',
}
: {};
const opts = {
port: 4723,
capabilities: {
...osSpecificOps,
automationName: 'Flutter'
}
};
(async () => {
const counterTextFinder = find.byValueKey('counter');
const buttonFinder = find.byValueKey('increment');
const driver = await wdio.remote(opts);
await validateElementPosition(driver, buttonFinder);
assert.strictEqual(await driver.execute('flutter:checkHealth'), 'ok');
await driver.execute('flutter:clearTimeline');
await driver.execute('flutter:forceGC');
const renderObjectDiagnostics = await driver.execute(
'flutter:getRenderObjectDiagnostics',
counterTextFinder,
{ includeProperties: true, subtreeDepth: 2 }
);
assert.strictEqual(renderObjectDiagnostics.type, 'DiagnosticableTreeNode');
assert.strictEqual(renderObjectDiagnostics.children.length, 1);
const semanticsId = await driver.execute(
'flutter:getSemanticsId',
counterTextFinder
);
assert.strictEqual(semanticsId, 4);
const treeString = await driver.execute('flutter: getRenderTree');
assert.strictEqual(treeString.substr(0, 11), 'RenderView#');
await driver.switchContext('NATIVE_APP');
await driver.saveScreenshot('./native-screenshot.png');
await driver.switchContext('FLUTTER');
await driver.saveScreenshot('./flutter-screenshot.png');
/* new example
if (process.env.APPIUM_OS === 'android') {
await driver.switchContext('NATIVE_APP');
await (await driver.$('~fab')).click();
await driver.switchContext('FLUTTER');
} else {
console.log(
'Switching context to `NATIVE_APP` is currently only applicable to Android demo app.'
);
}
*/
assert.strictEqual(await driver.getElementText(counterTextFinder), '0');
await driver.elementClick(buttonFinder);
await driver.touchAction({
action: 'tap',
element: { elementId: buttonFinder }
});
assert.strictEqual(await driver.getElementText(counterTextFinder), '2');
await driver.elementClick(find.byTooltip('Increment'));
assert.strictEqual(
await driver.getElementText(
find.descendant({
of: find.byTooltip('counter_tooltip'),
matching: find.byValueKey('counter')
})
),
'3'
);
await driver.elementClick(find.byType('FlatButton'));
await driver.execute(
'flutter:waitForAbsent',
buttonFinder
);
assert.strictEqual(
await driver.getElementText(find.byText('This is 2nd route')),
'This is 2nd route'
);
await driver.execute('flutter:scrollUntilVisible', find.byType('ListView'), {item:find.byType('TextField'), dxScroll: 90, dyScroll: -400});
await driver.execute('flutter:scroll', find.byType('ListView'), {dx: 50, dy: 100, durationMilliseconds: 200, frequency: 30});
await driver.execute('flutter:scrollIntoView', find.byType('TextField'), {alignment: 0.1});
await driver.elementClick(find.byType('TextField')); // acquire focus
await driver.execute('flutter:enterText', 'I can enter text'); // enter text
await driver.execute('flutter:waitFor', find.byText('I can enter text')); // verify text appears on UI
await driver.elementClick(find.pageBack());
await driver.execute(
'flutter:waitFor',
buttonFinder
);
assert.strictEqual(
await driver.getElementText(
find.descendant({
of: find.ancestor({
of: find.bySemanticsLabel(RegExp('counter_semantic')),
matching: find.byType('Tooltip')
}),
matching: find.byType('Text')
})
),
'3'
);
driver.deleteSession();
})();
const validateElementPosition = async (driver, buttonFinder) => {
const bottomLeft = await driver.execute(
'flutter:getBottomLeft',
buttonFinder
);
assert.strictEqual(typeof bottomLeft.dx, 'number');
assert.strictEqual(typeof bottomLeft.dy, 'number');
const bottomRight = await driver.execute(
'flutter:getBottomRight',
buttonFinder
);
assert.strictEqual(typeof bottomRight.dx, 'number');
assert.strictEqual(typeof bottomRight.dy, 'number');
const center = await driver.execute('flutter:getCenter', buttonFinder);
assert.strictEqual(typeof center.dx, 'number');
assert.strictEqual(typeof center.dy, 'number');
const topLeft = await driver.execute('flutter:getTopLeft', buttonFinder);
assert.strictEqual(typeof topLeft.dx, 'number');
assert.strictEqual(typeof topLeft.dy, 'number');
const topRight = await driver.execute('flutter:getTopRight', buttonFinder);
assert.strictEqual(typeof topRight.dx, 'number');
assert.strictEqual(typeof topRight.dy, 'number');
};