appium-uiautomator2-driver 6.6.1 → 6.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +14 -9
- package/build/lib/commands/screenshot.d.ts +17 -14
- package/build/lib/commands/screenshot.d.ts.map +1 -1
- package/build/lib/commands/screenshot.js +50 -36
- package/build/lib/commands/screenshot.js.map +1 -1
- package/build/lib/constraints.d.ts +3 -0
- package/build/lib/constraints.d.ts.map +1 -1
- package/build/test/unit/commands/general-specs.d.ts +2 -0
- package/build/test/unit/commands/general-specs.d.ts.map +1 -0
- package/build/test/unit/commands/general-specs.js +80 -0
- package/build/test/unit/commands/general-specs.js.map +1 -0
- package/build/test/unit/commands/screenshot-specs.d.ts +2 -0
- package/build/test/unit/commands/screenshot-specs.d.ts.map +1 -0
- package/build/test/unit/commands/screenshot-specs.js +124 -0
- package/build/test/unit/commands/screenshot-specs.js.map +1 -0
- package/build/test/unit/css-converter-specs.d.ts +2 -0
- package/build/test/unit/css-converter-specs.d.ts.map +1 -0
- package/build/test/unit/css-converter-specs.js +68 -0
- package/build/test/unit/css-converter-specs.js.map +1 -0
- package/build/test/unit/driver-specs.d.ts +2 -0
- package/build/test/unit/driver-specs.d.ts.map +1 -0
- package/build/test/unit/driver-specs.js +328 -0
- package/build/test/unit/driver-specs.js.map +1 -0
- package/build/test/unit/uiautomator2-specs.d.ts +2 -0
- package/build/test/unit/uiautomator2-specs.d.ts.map +1 -0
- package/build/test/unit/uiautomator2-specs.js +320 -0
- package/build/test/unit/uiautomator2-specs.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/commands/screenshot.ts +146 -0
- package/npm-shrinkwrap.json +252 -387
- package/package.json +2 -3
- package/lib/commands/screenshot.js +0 -116
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"automated testing",
|
|
8
8
|
"android"
|
|
9
9
|
],
|
|
10
|
-
"version": "6.6.
|
|
10
|
+
"version": "6.6.3",
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/appium/appium-uiautomator2-driver/issues"
|
|
13
13
|
},
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"rebuild": "npm run clean; npm run build",
|
|
49
49
|
"format": "prettier -w ./lib",
|
|
50
50
|
"reset": "node ./scripts/reset.js",
|
|
51
|
-
"test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.
|
|
51
|
+
"test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.ts\""
|
|
52
52
|
},
|
|
53
53
|
"prettier": {
|
|
54
54
|
"bracketSpacing": false,
|
|
@@ -73,7 +73,6 @@
|
|
|
73
73
|
"@appium/docutils": "^2.0.0-rc.1",
|
|
74
74
|
"@appium/eslint-config-appium-ts": "^2.0.0-rc.1",
|
|
75
75
|
"@appium/support": "^7.0.0-rc.1",
|
|
76
|
-
"@appium/test-support": "^4.0.0-rc.1",
|
|
77
76
|
"@appium/tsconfig": "^1.0.0-rc.1",
|
|
78
77
|
"@appium/types": "^1.0.0-rc.1",
|
|
79
78
|
"@semantic-release/changelog": "^6.0.1",
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import B from 'bluebird';
|
|
3
|
-
import {imageUtil} from 'appium/support';
|
|
4
|
-
|
|
5
|
-
// Display 4619827259835644672 (HWC display 0): port=0 pnpId=GGL displayName="EMU_display_0"
|
|
6
|
-
const DISPLAY_PATTERN = /^Display\s+(\d+)\s+\(.+display\s+(\d+)\).+displayName="([^"]*)/gm;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @this {AndroidUiautomator2Driver}
|
|
10
|
-
* @returns {Promise<string>}
|
|
11
|
-
*/
|
|
12
|
-
export async function mobileViewportScreenshot() {
|
|
13
|
-
return await this.getViewportScreenshot();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @this {AndroidUiautomator2Driver}
|
|
18
|
-
* @returns {Promise<string>}
|
|
19
|
-
*/
|
|
20
|
-
export async function getViewportScreenshot() {
|
|
21
|
-
const screenshot = await this.getScreenshot();
|
|
22
|
-
const rect = await this.getViewPortRect();
|
|
23
|
-
return await imageUtil.cropBase64Image(screenshot, rect);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @this {AndroidUiautomator2Driver}
|
|
28
|
-
* @returns {Promise<string>}
|
|
29
|
-
*/
|
|
30
|
-
export async function getScreenshot() {
|
|
31
|
-
if (this.mjpegStream) {
|
|
32
|
-
const data = await this.mjpegStream.lastChunkPNGBase64();
|
|
33
|
-
if (data) {
|
|
34
|
-
return data;
|
|
35
|
-
}
|
|
36
|
-
this.log.warn(
|
|
37
|
-
'Tried to get screenshot from active MJPEG stream, but there ' +
|
|
38
|
-
'was no data yet. Falling back to regular screenshot methods.'
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
return String(
|
|
42
|
-
await /** @type {import('../uiautomator2').UiAutomator2Server} */ (
|
|
43
|
-
this.uiautomator2
|
|
44
|
-
).jwproxy.command('/screenshot', 'GET')
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Retrieves screenshots of each display available to Android.
|
|
50
|
-
* This functionality is only supported since Android 10.
|
|
51
|
-
* @this {AndroidUiautomator2Driver}
|
|
52
|
-
* @param {number | string} [displayId] Android display identifier to take a screenshot for.
|
|
53
|
-
* If not provided then screenshots of all displays are going to be returned.
|
|
54
|
-
* If no matches were found then an error is thrown.
|
|
55
|
-
* @returns {Promise<import('@appium/types').StringRecord<import('./types').Screenshot>>}
|
|
56
|
-
*/
|
|
57
|
-
export async function mobileScreenshots(displayId) {
|
|
58
|
-
const displaysInfo = await /** @type {import('appium-adb').ADB} */ (this.adb).shell([
|
|
59
|
-
'dumpsys',
|
|
60
|
-
'SurfaceFlinger',
|
|
61
|
-
'--display-id',
|
|
62
|
-
]);
|
|
63
|
-
/** @type {import('@appium/types').StringRecord<import('./types').Screenshot>} */
|
|
64
|
-
const infos = {};
|
|
65
|
-
let match;
|
|
66
|
-
while ((match = DISPLAY_PATTERN.exec(displaysInfo))) {
|
|
67
|
-
infos[match[1]] = /** @type {any} */ ({
|
|
68
|
-
id: match[1],
|
|
69
|
-
isDefault: match[2] === '0',
|
|
70
|
-
name: match[3],
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
if (_.isEmpty(infos)) {
|
|
74
|
-
this.log.debug(displaysInfo);
|
|
75
|
-
throw new Error('Cannot determine the information about connected Android displays');
|
|
76
|
-
}
|
|
77
|
-
this.log.info(`Parsed Android display infos: ${JSON.stringify(infos)}`);
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @param {string} dispId
|
|
81
|
-
*/
|
|
82
|
-
const toB64Screenshot = async (dispId) =>
|
|
83
|
-
(await /** @type {import('appium-adb').ADB} */ (this.adb).takeScreenshot(dispId)).toString(
|
|
84
|
-
'base64'
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
// @ts-ignore isNaN works properly here
|
|
88
|
-
const displayIdStr = isNaN(displayId) ? null : `${displayId}`;
|
|
89
|
-
if (displayIdStr) {
|
|
90
|
-
if (!infos[displayIdStr]) {
|
|
91
|
-
throw new Error(
|
|
92
|
-
`The provided display identifier '${displayId}' is not known. ` +
|
|
93
|
-
`Only the following displays have been detected: ${JSON.stringify(infos)}`
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
[displayIdStr]: {
|
|
98
|
-
...infos[displayIdStr],
|
|
99
|
-
payload: await toB64Screenshot(displayIdStr),
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const allInfos = _.values(infos);
|
|
105
|
-
const screenshots = await B.all(allInfos.map(({id}) => toB64Screenshot(id)));
|
|
106
|
-
for (const [info, payload] of /** @type {[import('./types').Screenshot, string][]} */ (
|
|
107
|
-
_.zip(allInfos, screenshots)
|
|
108
|
-
)) {
|
|
109
|
-
info.payload = payload;
|
|
110
|
-
}
|
|
111
|
-
return infos;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
|
|
116
|
-
*/
|