-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.local.js
127 lines (107 loc) · 3.71 KB
/
test.local.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
const exec = require('child_process').exec;
const path = require('path');
const puppeteer = require('puppeteer-core');
const { promisify } = require('util');
const sleep = promisify(setTimeout);
const should = require('chai').should();
const IsWinOS = process.platform === 'win32';
const ConfigUrl = path.join(process.cwd(), 'app_sample.json');
const RemoteDebuggingPort = 12565;
const TimeoutMs = 60000;
async function withTimeout(op) {
const start = Date.now();
let result;
while (!result && Date.now() - start < TimeoutMs) {
try {
result = await op();
} catch (err) { }
if (!result)
await sleep(500);
}
return result;
}
async function findPage(title, browser) {
return await withTimeout(async function () {
const pages = await browser.pages();
for (const page of pages) {
const pageTitle = await page.title();
if (pageTitle === title)
return page;
}
});
}
function launch() {
exec(IsWinOS ?
`${process.env.LOCALAPPDATA}\\OpenFin\\OpenFinRVM.exe --config=${ConfigUrl} --runtime-arguments="--remote-debugging-port=${RemoteDebuggingPort}"` :
`runtimeArgs="--remote-debugging-port=${RemoteDebuggingPort}" openfin -l -c ${ConfigUrl}`);
}
async function connect() {
return await withTimeout(async function () {
return await puppeteer.connect({ browserURL: `http://localhost:${RemoteDebuggingPort}` });
});
}
before(async function () {
// Launch OpenFin first if running local
launch();
// Try to connect until OpenFin is up
global.browser = await connect();
});
describe('Hello OpenFin App testing with Puppeteer', function () {
var notificationButton, cpuInfoButton, cpuInfoExitButton;
/**
* Check if OpenFin Javascript API fin.desktop.System.getVersion exists
*
**/
async function waitForFinDesktop() {
return await withTimeout(async function () {
return await page.evaluate(function () {
return fin && fin.desktop && fin.desktop.System && fin.desktop.System.getVersion;
});
});
}
it('Find the Hello OpenFin Main window', async () => {
global.page = await findPage('Hello OpenFin', browser);
await page.screenshot({ path: 'Main.png' });
});
it('Wait for OpenFin API ready', async () => {
await waitForFinDesktop();
});
it("Find notification button", async () => {
const result = await page.$("#desktop-notification");
should.exist(result);
notificationButton = result;
});
it("Click notification button", async () => {
should.exist(notificationButton);
await notificationButton.click();
});
it("Find CPU Info button", async () => {
const result = await page.$("#cpu-info");
should.exist(result);
cpuInfoButton = result;
});
it("Click CPU Info button", async () => {
should.exist(cpuInfoButton);
await cpuInfoButton.click();
await sleep(3000); // pause just for demo purpose so we can see the window
});
it('Switch to CPU Info window', async () => {
global.page = await findPage('Hello OpenFin CPU Info', browser);
await page.screenshot({ path: 'CPU.png' });
});
it("Find Exit button for CPU Info window", async () => {
const result = await page.$("#close-app");
should.exist(result);
cpuInfoExitButton = result;
});
it("Click CPU Info Exit button", async () => {
should.exist(cpuInfoExitButton);
await cpuInfoExitButton.click();
});
});
after(async () => {
await page.evaluate(function () {
fin.desktop.System.exit();
});
await sleep(1000);
});