/
android-create-session.test.js
88 lines (75 loc) · 2.73 KB
/
android-create-session.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
const webdriverio = require('webdriverio');
const androidOptions = require('../../helpers/caps').androidOptions;
const app = require('../../helpers/apps').androidApiDemos;
const assert = require('chai').assert;
androidOptions.capabilities.app = app;
/**
* Starts recording a TestFaiy session.
*
* @param client wdio client
* @param appToken TestFairy app token can be found at https://app.testfairy.com/settings
*/
async function begin(client, appToken) {
client.startActivity()
const args = Buffer.from(JSON.stringify(['begin', appToken])).toString('base64');
await client.execute('mobile: startService', {
intent: '--es "args" "' + args + '" com.example.appiumcallstestfairy/.TestFairyService',
});
}
/**
* This helps us simulate a long running operation usually found in tests.
*/
async function wait() {
await new Promise(function(resolve) {
setTimeout(() => {
resolve();
}, 2000);
});
}
/**
* Sends a string event to currently recorded session. It will show up in the session timeline.
* Multiple sessions that has the same event can be searched at https://app.testfairy.com/sessions
*
* @param client wdio client
* @param event Some string value to represent a significant event happening during tests
*/
async function addEvent(client, event) {
const args = Buffer.from(JSON.stringify(['addEvent', event])).toString('base64');
await client.execute('mobile: startService', {
intent: '--es "args" "' + args + '" com.example.appiumcallstestfairy/.TestFairyService',
});
}
/**
* Stops recording a TestFairy session.
*
* @param client wdio client
*/
async function stop(client) {
const args = Buffer.from(JSON.stringify(['stop'])).toString('base64');
await client.execute('mobile: startService', {
intent: '--es "args" "' + args + '" com.example.appiumcallstestfairy/.TestFairyService',
});
}
// Test suite
describe('Create TestFairy session', function () {
let client;
before(async function () {
client = await webdriverio.remote(androidOptions);
});
it('should create and destroy a session', async function () {
const res = await client.status();
assert.isObject(res.build);
const current_package = await client.getCurrentPackage();
assert.equal(current_package, 'com.example.appiumcallstestfairy');
console.log("Starting a TestFairy session");
await begin(client, "SDK-XXXXXXX"); // TestFairy app token can be found at https://app.testfairy.com/settings
await wait();
await addEvent(client, "Waited a few seconds, this will show up in session timeline");
await wait();
await stop(client);
await wait();
console.log("Ending TestFairy session");
const delete_session = await client.deleteSession();
assert.isNull(delete_session);
});
});