-
-
Notifications
You must be signed in to change notification settings - Fork 6k
/
basic-specs.js
352 lines (310 loc) · 11.6 KB
/
basic-specs.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
"use strict";
var env = require('../../../helpers/env')
, setup = require("../../common/setup-base")
, desired = require("./desired")
, try3Times = require('../../../helpers/repeat').try3Times
, initSession = require('../../../helpers/session').initSession
, getTitle = require('../../../helpers/title').getTitle
, path = require('path')
, ADB = require("../../../../lib/devices/android/adb.js")
, chai = require('chai')
, should = chai.should()
, spawn = require('child_process').spawn
, _ = require('underscore')
, ChaiAsserter = require('../../../helpers/asserter.js').ChaiAsserter
, getAppPath = require('../../../helpers/app').getAppPath
, androidReset = require('../../../helpers/reset').androidReset;
describe("apidemo - basic @skip-ci", function () {
afterEach(function (done) {
setTimeout(function () { done(); }, 2000); // cooldown
});
describe('short command timeout', function () {
var driver;
setup(this, desired).then(function (d) { driver = d; });
it('should die with short command timeout', function (done) {
driver
.setCommandTimeout(3000)
.sleep(4000)
.elementByName('Animation')
.should.be.rejectedWith(/status: (13|6)/)
.nodeify(done);
});
});
describe('commands coming in', function () {
var driver;
setup(this, desired).then(function (d) { driver = d; });
it('should not die if commands come in', function (done) {
var start;
var find = function () {
if ((Date.now() - start) < 5000) {
return driver
.elementByName('Animation').should.eventually.exist
.then(find);
}
};
driver
.setCommandTimeout(7000)
.then(function () { start = Date.now(); })
.then(find)
.sleep(10000)
.elementByName('Animation').should.be.rejected
.nodeify(done);
});
});
describe('api', function () {
var driver;
setup(this, desired).then(function (d) { driver = d; });
it('should get device size', function (done) {
driver.getWindowSize()
.then(function (size) {
size.width.should.be.above(0);
size.height.should.be.above(0);
}).nodeify(done);
});
it('should be able to get current activity', function (done) {
driver
.getCurrentActivity()
.should.eventually.include("ApiDemos")
.nodeify(done);
});
it('should be able to get logcat log type', function (done) {
driver
.logTypes()
.should.eventually.include('logcat')
.nodeify(done);
});
it('should be able to get logcat logs', function (done) {
driver.log('logcat').then(function (logs) {
logs.length.should.be.above(0);
logs[0].message.should.not.include("\n");
logs[0].level.should.equal("ALL");
logs[0].timestamp.should.exist;
}).nodeify(done);
});
it('should be able to install/remove app and detect its status', function (done) {
driver
.isAppInstalled('foo')
.should.eventually.equal(false)
.isAppInstalled('io.appium.android.apis')
.should.eventually.equal(true)
.removeApp('io.appium.android.apis')
.isAppInstalled('io.appium.android.apis')
.should.eventually.equal(false)
.installApp(getAppPath('ApiDemos'))
.isAppInstalled('io.appium.android.apis')
.should.eventually.equal(true)
.nodeify(done);
});
it("should background the app", function (done) {
var before = new Date().getTime() / 1000;
driver
.backgroundApp(3)
.then(function () {
((new Date().getTime() / 1000) - before).should.be.least(3);
// should really not be checking this.
//((new Date().getTime() / 1000) - before).should.be.below(5);
})
.getCurrentActivity()
.should.eventually.include("ApiDemos")
.nodeify(done);
});
it("should get app strings", function (done) {
driver
.getAppStrings()
.then(function (strings) {
_.size(strings).should.be.above(1);
strings.activity_sample_code.should.eql("API Demos");
})
.nodeify(done);
});
});
describe('with fastReset', function () {
var driver;
setup(this, desired)
.then(function (d) { driver = d; });
it('should still be able to reset', function (done) {
driver
.sleep(3000)
.resetApp()
.getWindowSize()
.nodeify(done);
});
});
describe('activity style: no period', function () {
this.timeout(env.MOCHA_INIT_TIMEOUT);
var session;
var title = getTitle(this);
after(function () { return session.tearDown(this.currentTest.state === 'passed'); });
it('should still find activity', function (done) {
session = initSession(_.defaults({appActivity: 'ApiDemos'}, desired));
session.setUp(title).nodeify(done);
});
});
describe('activity style: fully qualified', function () {
this.timeout(env.MOCHA_INIT_TIMEOUT);
var session;
var title = getTitle(this);
after(function () { return session.tearDown(this.currentTest.state === 'passed'); });
it('should still find activity', function (done) {
session = initSession(_.defaults({appActivity: 'io.appium.android.apis.ApiDemos'}, desired));
session.setUp(title).nodeify(done);
});
});
describe('error cases', function () {
this.timeout(env.MOCHA_INIT_TIMEOUT);
var opts = {'no-retry': true};
describe('activity style: non-existent', function () {
var session;
var title = getTitle(this);
after(function () { return session.tearDown(this.currentTest.state === 'passed'); });
it('should throw an error', function (done) {
session = initSession(_.defaults({appActivity: '.Blargimarg'}, desired), opts);
try3Times(function () {
return session.setUp(title)
.catch(function (err) { throw err.data; })
.should.be.rejectedWith(/Activity used to start app doesn't exist/);
}).nodeify(done);
});
});
describe('bad app path', function () {
var session;
var title = getTitle(this);
after(function () { return session.tearDown(this.currentTest.state === 'passed'); });
it('should throw an error', function (done) {
var badAppPath = path.resolve(__dirname, "../../../sample-code/apps/ApiDemos/bin/ApiDemos-debugz.apk");
session = initSession(_.defaults({'app': badAppPath}, desired), opts);
try3Times(function () {
return session.setUp(title)
.catch(function (err) { throw err.data; })
.should.eventually.be.rejectedWith(/Error locating the app/);
}).nodeify(done);
});
});
});
describe('pre-existing uiautomator session', function () {
this.timeout(env.MOCHA_INIT_TIMEOUT);
before(function (done) {
var adb = new ADB();
var binPath = path.resolve(__dirname, "..", "..", "..", "..", "build",
"android_bootstrap", "AppiumBootstrap.jar");
var uiArgs = ["shell", "uiautomator", "runtest", "AppiumBootstrap.jar", "-c",
"io.appium.android.bootstrap.Bootstrap"];
adb.push(binPath, "/data/local/tmp/", function (err) {
should.not.exist(err);
spawn("adb", uiArgs);
setTimeout(function () {
adb.getPIDsByName("uiautomator", function (err, pids) {
should.not.exist(err);
pids.length.should.equal(1);
done();
});
}, 5000);
});
});
describe('launching new session', function () {
var driver;
setup(this, desired)
.then(function (d) { driver = d; });
it('should kill pre-existing uiautomator process', function (done) {
driver.getWindowSize().should.eventually.exist
.nodeify(done);
});
});
describe('launching activity with custom intent parameter category', function () {
var driver;
var caps = _.clone(desired);
caps.appActivity = "io.appium.android.apis.app.HelloWorld";
caps.intentCategory = "appium.android.intent.category.SAMPLE_CODE";
setup(this, caps)
.then(function (d) { driver = d; });
it('should launch activity with intent category', function (done) {
driver.getCurrentActivity()
.should.eventually.include("HelloWorld")
.nodeify(done);
});
});
});
describe('appium android', function () {
this.timeout(env.MOCHA_INIT_TIMEOUT);
var session;
var title = getTitle(this);
if (env.FAST_TESTS) {
beforeEach(function (done) {
androidReset('io.appium.android.apis', '.ApiDemos').nodeify(done);
});
}
afterEach(function () { return session.tearDown(this.currentTest.state === 'passed'); });
it('should load an app with using absolute path', function (done) {
var appPath = path.resolve(desired.app);
session = initSession(_.defaults({'app': appPath}, desired));
session.setUp(title + "- abs path").nodeify(done);
});
it('should load an app with using relative path', function (done) {
var appPath = path.relative(process.cwd(), desired.app);
session = initSession(_.defaults({'app': appPath}, desired));
session.setUp(title + "- rel path").nodeify(done);
});
it('should load a zipped app via url', function (done) {
var appUrl = 'http://appium.s3.amazonaws.com/ApiDemos-debug.apk';
session = initSession(_.defaults({'app': appUrl}, desired));
session.setUp(title + "- zip url").nodeify(done);
});
it('should load an app via package', function (done) {
var caps = _.clone(desired);
caps.app = 'io.appium.android.apis';
caps.appActivity = '.ApiDemos';
session = initSession(caps, desired);
session.setUp(title + "- package").nodeify(done);
});
});
describe('appium android', function () {
this.timeout(env.MOCHA_INIT_TIMEOUT);
var session;
var title = getTitle(this);
before(function (done) {
var adb = new ADB({});
adb.uninstallApk("io.appium.android.apis", done);
});
afterEach(function () { return session.tearDown(this.currentTest.state === 'passed'); });
it('should be able to start session without launching app', function (done) {
var appPath = path.resolve(desired.app);
var caps = _.defaults({'app': appPath, 'autoLaunch': false}, desired);
session = initSession(caps, desired);
var driver = session.setUp(title + "- autoLaunch");
var activityToBeBlank = new ChaiAsserter(function (driver) {
return driver
.getCurrentActivity()
.should.eventually.not.include(".ApiDemos");
});
driver
.waitFor(activityToBeBlank, 10000, 700)
.launchApp()
.getCurrentActivity()
.should.eventually.include(".ApiDemos")
.nodeify(done);
});
it('should be able to start session without installing app', function (done) {
var appPath = path.resolve(desired.app);
var appPkg = "io.appium.android.apis";
var caps = _.defaults({
app: appPkg,
autoLaunch: false,
appActivity: ".ApiDemos"
}, desired);
session = initSession(caps, desired);
var driver = session.setUp(title + "- autoLaunch");
var activityToBeBlank = new ChaiAsserter(function (driver) {
return driver
.getCurrentActivity()
.should.eventually.not.include(".ApiDemos");
});
driver
.waitFor(activityToBeBlank, 10000, 700)
.installApp(appPath)
.launchApp()
.getCurrentActivity()
.should.eventually.include(".ApiDemos")
.nodeify(done);
});
});
});