-
Notifications
You must be signed in to change notification settings - Fork 0
/
manual_upload.js
91 lines (83 loc) · 2.58 KB
/
manual_upload.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
const fs = require('fs/promises');
const path = require('path');
const percyScreenshot = require('@percy/appium-app');
function mockDriver({
deviceName, // same as how SDK would get it
os, // iOS / Android
osVersion,
deviceScreenSize, // width x height. eg 1080x1920
statusBarHeight, // in px
navigationBarHeight, // in px
orientation, // portrait / landscape
screenshotPath,
}) {
const sessionCaps = {
platformName: os,
osVersion,
};
if (os === 'Android') {
sessionCaps.deviceScreenSize = deviceScreenSize;
sessionCaps.desired = {
deviceName,
};
} else if (os === 'iOS') {
sessionCaps.deviceName = deviceName;
}
sessionCaps.viewportRect = {
left: 0,
top: statusBarHeight,
width: parseInt(deviceScreenSize.split('x')[0]),
height:
parseInt(deviceScreenSize.split('x')[1]) -
statusBarHeight -
navigationBarHeight,
};
sessionCaps.pixelRatio = 1.0;
sessionCaps.statBarHeight = statusBarHeight;
return {
// we need to have this unique per device/combination so making a string
sessionID: `${deviceName}${osVersion}${os}${deviceScreenSize}${statusBarHeight}${orientation}`,
configUrl: {
hostname: 'localhost', // do not change
},
sessionCapabilities: () => sessionCaps,
takeScreenshot: async () =>
await fs.readFile(screenshotPath, {encoding: 'base64'}),
getOrientation: () => orientation,
};
}
async function uploadAll(folderPath) {
folderPath = path.resolve(folderPath);
const deviceFolders = await fs.readdir(folderPath);
await Promise.all(
deviceFolders.map(async deviceFolder => {
if (deviceFolder === '.DS_Store') {
return;
}
const fullDeviceFolderPath = path.join(folderPath, deviceFolder);
const device = require(path.join(fullDeviceFolderPath, 'device.json'));
const screenshots = await fs.readdir(fullDeviceFolderPath);
await Promise.all(
screenshots.map(async screenshotName => {
if (screenshotName === 'device.json') {
return;
}
console.log(
`Processing ${device.deviceName}:${device.osVersion} - ${screenshotName}`,
);
const fullScreenshotPath = path.join(
fullDeviceFolderPath,
screenshotName,
);
const driver = mockDriver(
Object.assign({}, device, {
screenshotPath: fullScreenshotPath.toString(),
}),
);
await percyScreenshot(driver, screenshotName.replace('.png', ''));
}),
);
}),
);
}
uploadAll('./resources').then('done');