appium-uiautomator2-driver 10.3.0 → 10.4.0
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 +6 -0
- package/build/lib/commands/find.js +2 -2
- package/build/lib/commands/find.js.map +1 -1
- package/build/lib/css/class-chain-emitter.d.ts +32 -0
- package/build/lib/css/class-chain-emitter.d.ts.map +1 -0
- package/build/lib/css/class-chain-emitter.js +151 -0
- package/build/lib/css/class-chain-emitter.js.map +1 -0
- package/build/lib/css/constants.d.ts +8 -4
- package/build/lib/css/constants.d.ts.map +1 -1
- package/build/lib/css/constants.js +8 -4
- package/build/lib/css/constants.js.map +1 -1
- package/build/lib/css/index.d.ts +1 -1
- package/build/lib/css/index.d.ts.map +1 -1
- package/build/lib/css/index.js +7 -6
- package/build/lib/css/index.js.map +1 -1
- package/lib/commands/find.ts +2 -2
- package/lib/css/class-chain-emitter.ts +180 -0
- package/lib/css/constants.ts +10 -4
- package/lib/css/index.ts +7 -6
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/crypto.d.ts +3 -3
- package/node_modules/@types/node/package.json +2 -2
- package/node_modules/@types/node/test.d.ts +4 -0
- package/node_modules/@types/node/url.d.ts +2 -0
- package/node_modules/@types/node/util.d.ts +1 -1
- package/node_modules/@types/node/web-globals/encoding.d.ts +5 -2
- package/node_modules/appium-uiautomator2-server/CHANGELOG.md +7 -0
- package/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk +0 -0
- package/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk.idsig +0 -0
- package/node_modules/appium-uiautomator2-server/apks/{appium-uiautomator2-server-v11.6.0.apk → appium-uiautomator2-server-v11.6.1.apk} +0 -0
- package/node_modules/appium-uiautomator2-server/apks/{appium-uiautomator2-server-v11.6.0.apk.idsig → appium-uiautomator2-server-v11.6.1.apk.idsig} +0 -0
- package/node_modules/appium-uiautomator2-server/package.json +2 -2
- package/package.json +2 -2
- package/build/lib/css/ui-automator-emitter.d.ts +0 -16
- package/build/lib/css/ui-automator-emitter.d.ts.map +0 -1
- package/build/lib/css/ui-automator-emitter.js +0 -115
- package/build/lib/css/ui-automator-emitter.js.map +0 -1
- package/lib/css/ui-automator-emitter.ts +0 -141
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [10.4.0](https://github.com/appium/appium-uiautomator2-driver/compare/v10.3.0...v10.4.0) (2026-11-25)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* convert CSS selectors to class chain instead of UiSelector ([#1095](https://github.com/appium/appium-uiautomator2-driver/issues/1095)) ([ae41526](https://github.com/appium/appium-uiautomator2-driver/commit/ae41526d2a32af5f10d2f6acd0ab3a9756f9a8ee))
|
|
6
|
+
|
|
1
7
|
## [10.3.0](https://github.com/appium/appium-uiautomator2-driver/compare/v10.2.0...v10.3.0) (2026-11-24)
|
|
2
8
|
|
|
3
9
|
### Features
|
|
@@ -4,7 +4,7 @@ import { warnIfUiScrollableLocator } from '../utils/deprecation.js';
|
|
|
4
4
|
// looks like /*[@firstVisible="true"]
|
|
5
5
|
const MAGIC_FIRST_VIS_CHILD_SEL = /\/\*\[@firstVisible ?= ?('|")true\1\]/;
|
|
6
6
|
const MAGIC_SCROLLABLE_SEL = /\/\/\*\[@scrollable ?= ?('|")true\1\]/;
|
|
7
|
-
const MAGIC_SCROLLABLE_BY = '
|
|
7
|
+
const MAGIC_SCROLLABLE_BY = 'scrollable == true';
|
|
8
8
|
export async function doFindElementOrEls(params) {
|
|
9
9
|
const uiautomator2 = this.uiautomator2;
|
|
10
10
|
if (params.strategy === 'xpath' && MAGIC_FIRST_VIS_CHILD_SEL.test(params.selector)) {
|
|
@@ -12,7 +12,7 @@ export async function doFindElementOrEls(params) {
|
|
|
12
12
|
return (await uiautomator2.jwproxy.command(`/appium/element/${elementId}/first_visible`, 'GET', {}));
|
|
13
13
|
}
|
|
14
14
|
if (params.strategy === 'xpath' && MAGIC_SCROLLABLE_SEL.test(params.selector)) {
|
|
15
|
-
params.strategy = '-android
|
|
15
|
+
params.strategy = '-android predicate string';
|
|
16
16
|
params.selector = MAGIC_SCROLLABLE_BY;
|
|
17
17
|
}
|
|
18
18
|
if (params.strategy === 'css selector') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find.js","sourceRoot":"","sources":["../../../lib/commands/find.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAC,yBAAyB,EAAC,MAAM,yBAAyB,CAAC;AAElE,4EAA4E;AAC5E,sCAAsC;AACtC,MAAM,yBAAyB,GAAG,uCAAuC,CAAC;AAE1E,MAAM,oBAAoB,GAAG,uCAAuC,CAAC;AACrE,MAAM,mBAAmB,GAAG,
|
|
1
|
+
{"version":3,"file":"find.js","sourceRoot":"","sources":["../../../lib/commands/find.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAC,yBAAyB,EAAC,MAAM,yBAAyB,CAAC;AAElE,4EAA4E;AAC5E,sCAAsC;AACtC,MAAM,yBAAyB,GAAG,uCAAuC,CAAC;AAE1E,MAAM,oBAAoB,GAAG,uCAAuC,CAAC;AACrE,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AAgBjD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAEtC,MAAuB;IAEvB,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;IACvC,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,IAAI,yBAAyB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnF,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC;QACjC,OAAO,CAAC,MAAM,YAAY,CAAC,OAAO,CAAC,OAAO,CACxC,mBAAmB,SAAS,gBAAgB,EAC5C,KAAK,EACL,EAAE,CACH,CAAkB,CAAC;IACtB,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,IAAI,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9E,MAAM,CAAC,QAAQ,GAAG,2BAA2B,CAAC;QAC9C,MAAM,CAAC,QAAQ,GAAG,mBAAmB,CAAC;IACxC,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,KAAK,cAAc,EAAE,CAAC;QACvC,CAAC,EAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAC,GAAG,MAAM,kBAAkB,CAChF,MAAM,CAAC,QAAQ,EACf,IAAI,CAAC,IAAI,CAAC,UAAU,CACrB,CAAC,CAAC;IACL,CAAC;IACD,yBAAyB,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClE,OAAO,CAAC,MAAM,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,CAEhF,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ParsedRule, ParsedSelector, StrategyEmitter } from '@appium/css-locator-to-native';
|
|
2
|
+
export interface ClassChainEmitterContext {
|
|
3
|
+
appPackage?: string | null;
|
|
4
|
+
}
|
|
5
|
+
/** Converts parsed CSS selectors into class chain strings. */
|
|
6
|
+
export declare class ClassChainEmitter implements StrategyEmitter<ClassChainEmitterContext> {
|
|
7
|
+
readonly strategy: string;
|
|
8
|
+
constructor(strategy: string);
|
|
9
|
+
emit(parsed: ParsedSelector, ctx?: ClassChainEmitterContext): string;
|
|
10
|
+
/** Splits a rule into the type of a step, the predicates that restrict it and an optional position. */
|
|
11
|
+
protected buildStep(rule: ParsedRule, ctx?: ClassChainEmitterContext): {
|
|
12
|
+
type: string;
|
|
13
|
+
predicates: string[];
|
|
14
|
+
position?: number;
|
|
15
|
+
};
|
|
16
|
+
private emitRule;
|
|
17
|
+
/** A fully qualified class is the type of a step, a partial one (`TextView`, `.widget.TextView`) is a suffix. */
|
|
18
|
+
private formatClass;
|
|
19
|
+
private formatPredicate;
|
|
20
|
+
private formatStringPredicate;
|
|
21
|
+
private formatIdLocator;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Converts a parsed CSS selector that is a single rule without a position into a predicate string.
|
|
25
|
+
* It is the same as a class chain of a single step with the predicate, but shorter.
|
|
26
|
+
*/
|
|
27
|
+
export declare class PredicateStringEmitter extends ClassChainEmitter {
|
|
28
|
+
emit(parsed: ParsedSelector, ctx?: ClassChainEmitterContext): string;
|
|
29
|
+
}
|
|
30
|
+
/** Whether the selector needs a class chain: it has more than one rule or selects a position. */
|
|
31
|
+
export declare function needsClassChain(parsed: ParsedSelector): boolean;
|
|
32
|
+
//# sourceMappingURL=class-chain-emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-chain-emitter.d.ts","sourceRoot":"","sources":["../../../lib/css/class-chain-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,UAAU,EAAE,cAAc,EAAE,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAiChH,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,8DAA8D;AAC9D,qBAAa,iBAAkB,YAAW,eAAe,CAAC,wBAAwB,CAAC;IACjF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,QAAQ,EAAE,MAAM;IAI5B,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,wBAAwB,GAAG,MAAM;IAIpE,uGAAuG;IACvG,SAAS,CAAC,SAAS,CACjB,IAAI,EAAE,UAAU,EAChB,GAAG,CAAC,EAAE,wBAAwB,GAC7B;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAC;IAmB1D,OAAO,CAAC,QAAQ;IAiBhB,iHAAiH;IACjH,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,qBAAqB;IAkC7B,OAAO,CAAC,eAAe;CAGxB;AAED;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,iBAAiB;IAClD,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,wBAAwB,GAAG,MAAM;CAK9E;AAED,iGAAiG;AACjG,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAG/D"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { errors } from 'appium/driver.js';
|
|
2
|
+
import { util } from 'appium/support.js';
|
|
3
|
+
const BOOLEAN_ATTRS = new Set([
|
|
4
|
+
'checkable',
|
|
5
|
+
'checked',
|
|
6
|
+
'clickable',
|
|
7
|
+
'enabled',
|
|
8
|
+
'focusable',
|
|
9
|
+
'focused',
|
|
10
|
+
'long-clickable',
|
|
11
|
+
'scrollable',
|
|
12
|
+
'selected',
|
|
13
|
+
]);
|
|
14
|
+
/** CSS attribute name -> element attribute used in the predicates. */
|
|
15
|
+
const STRING_ATTRS = {
|
|
16
|
+
description: 'content-desc',
|
|
17
|
+
'resource-id': 'resource-id',
|
|
18
|
+
text: 'text',
|
|
19
|
+
'class-name': 'class',
|
|
20
|
+
'package-name': 'package',
|
|
21
|
+
};
|
|
22
|
+
/** The old UiSelector methods matched these two attributes without respect to the case. */
|
|
23
|
+
const CASE_INSENSITIVE_ATTRS = new Set(['description', 'text']);
|
|
24
|
+
/** CSS whitespace only, unlike `\s` it does not include e.g. the non-breaking space. */
|
|
25
|
+
const CSS_WHITESPACE = /[ \t\r\n\f]/;
|
|
26
|
+
const ID_LOCATOR_PATTERN = /^[a-zA-Z_][a-zA-Z0-9._]*:id\/[\S]+$/;
|
|
27
|
+
/** Converts parsed CSS selectors into class chain strings. */
|
|
28
|
+
export class ClassChainEmitter {
|
|
29
|
+
strategy;
|
|
30
|
+
constructor(strategy) {
|
|
31
|
+
this.strategy = strategy;
|
|
32
|
+
}
|
|
33
|
+
emit(parsed, ctx) {
|
|
34
|
+
return this.emitRule(parsed.rule, ctx);
|
|
35
|
+
}
|
|
36
|
+
/** Splits a rule into the type of a step, the predicates that restrict it and an optional position. */
|
|
37
|
+
buildStep(rule, ctx) {
|
|
38
|
+
const { type, predicates: classPredicates } = this.formatClass(rule);
|
|
39
|
+
const predicates = [...classPredicates];
|
|
40
|
+
let position;
|
|
41
|
+
if (rule.id) {
|
|
42
|
+
predicates.push(`resource-id == ${quote(this.formatIdLocator(rule.id, ctx?.appPackage))}`);
|
|
43
|
+
}
|
|
44
|
+
for (const attr of [...rule.attributes, ...rule.pseudos]) {
|
|
45
|
+
if (attr.name === 'instance') {
|
|
46
|
+
// instance() is zero-based, positions of a class chain start with 1
|
|
47
|
+
position = Number(attr.value) + 1;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
predicates.push(this.formatPredicate(attr, ctx));
|
|
51
|
+
}
|
|
52
|
+
return { type, predicates, position };
|
|
53
|
+
}
|
|
54
|
+
emitRule(rule, ctx) {
|
|
55
|
+
const { type, predicates, position } = this.buildStep(rule, ctx);
|
|
56
|
+
let step = type;
|
|
57
|
+
if (predicates.length) {
|
|
58
|
+
step += `[\`${predicates.join(' AND ').replaceAll('`', '``')}\`]`;
|
|
59
|
+
}
|
|
60
|
+
if (position !== undefined) {
|
|
61
|
+
step += `[${position}]`;
|
|
62
|
+
}
|
|
63
|
+
// The first rule is searched for anywhere, the nested ones relative to the previous one
|
|
64
|
+
const separator = !rule.combinator ? '**/' : rule.combinator === 'child' ? '/' : '/**/';
|
|
65
|
+
const chain = `${separator}${step}`;
|
|
66
|
+
return rule.nested ? `${chain}${this.emitRule(rule.nested, ctx)}` : chain;
|
|
67
|
+
}
|
|
68
|
+
/** A fully qualified class is the type of a step, a partial one (`TextView`, `.widget.TextView`) is a suffix. */
|
|
69
|
+
formatClass(rule) {
|
|
70
|
+
const tagName = rule.tag && rule.tag !== '*' ? rule.tag : '';
|
|
71
|
+
const classNames = [...rule.classes];
|
|
72
|
+
if (tagName && classNames.length) {
|
|
73
|
+
return { type: [tagName, ...classNames].join('.'), predicates: [] };
|
|
74
|
+
}
|
|
75
|
+
const partialName = [tagName, ...classNames].filter(Boolean).join('.');
|
|
76
|
+
if (!partialName) {
|
|
77
|
+
return { type: '*', predicates: [] };
|
|
78
|
+
}
|
|
79
|
+
// The name may also be the whole class name, e.g. an unqualified one, which has no leading dot
|
|
80
|
+
const predicate = `(class == ${quote(partialName)} OR class ENDSWITH ${quote(`.${partialName}`)})`;
|
|
81
|
+
return { type: '*', predicates: [predicate] };
|
|
82
|
+
}
|
|
83
|
+
formatPredicate(attr, ctx) {
|
|
84
|
+
if (BOOLEAN_ATTRS.has(attr.name)) {
|
|
85
|
+
return `${attr.name} == ${attr.value ?? 'true'}`;
|
|
86
|
+
}
|
|
87
|
+
if (attr.name === 'index') {
|
|
88
|
+
return `index == ${attr.value}`;
|
|
89
|
+
}
|
|
90
|
+
return this.formatStringPredicate(attr, ctx);
|
|
91
|
+
}
|
|
92
|
+
formatStringPredicate(attr, ctx) {
|
|
93
|
+
const name = STRING_ATTRS[attr.name];
|
|
94
|
+
if (!name) {
|
|
95
|
+
throw new errors.InvalidSelectorError(`Unsupported attribute '${attr.name}'`);
|
|
96
|
+
}
|
|
97
|
+
if (attr.operator === undefined) {
|
|
98
|
+
// A missing value also satisfies `!= ''`, so it has to be excluded explicitly
|
|
99
|
+
return `${name} != nil AND ${name} != ''`;
|
|
100
|
+
}
|
|
101
|
+
let value = attr.value ?? '';
|
|
102
|
+
// Only an exact id is qualified, substring operators get the fragment as is
|
|
103
|
+
if (attr.name === 'resource-id' && (attr.operator === '=' || attr.operator === undefined)) {
|
|
104
|
+
value = this.formatIdLocator(value, ctx?.appPackage);
|
|
105
|
+
}
|
|
106
|
+
const modifier = CASE_INSENSITIVE_ATTRS.has(attr.name) ? '[c]' : '';
|
|
107
|
+
switch (attr.operator) {
|
|
108
|
+
case '*=':
|
|
109
|
+
return `${name} CONTAINS${modifier} ${quote(value)}`;
|
|
110
|
+
case '^=':
|
|
111
|
+
return `${name} BEGINSWITH${modifier} ${quote(value)}`;
|
|
112
|
+
case '$=':
|
|
113
|
+
return `${name} ENDSWITH ${quote(value)}`;
|
|
114
|
+
case '~=':
|
|
115
|
+
// CSS words are whitespace-delimited, so an empty value or one with whitespace never matches
|
|
116
|
+
if (!value || CSS_WHITESPACE.test(value)) {
|
|
117
|
+
return 'FALSEPREDICATE';
|
|
118
|
+
}
|
|
119
|
+
return `${name} MATCHES ${quote(getWordMatcherRegex(value))}`;
|
|
120
|
+
default:
|
|
121
|
+
return `${name} == ${quote(value)}`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
formatIdLocator(locator, appPackage) {
|
|
125
|
+
return ID_LOCATOR_PATTERN.test(locator) ? locator : `${appPackage || 'android'}:id/${locator}`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Converts a parsed CSS selector that is a single rule without a position into a predicate string.
|
|
130
|
+
* It is the same as a class chain of a single step with the predicate, but shorter.
|
|
131
|
+
*/
|
|
132
|
+
export class PredicateStringEmitter extends ClassChainEmitter {
|
|
133
|
+
emit(parsed, ctx) {
|
|
134
|
+
const { type, predicates } = this.buildStep(parsed.rule, ctx);
|
|
135
|
+
const all = type === '*' ? predicates : [`class == ${quote(type)}`, ...predicates];
|
|
136
|
+
return all.length ? all.join(' AND ') : 'TRUEPREDICATE';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** Whether the selector needs a class chain: it has more than one rule or selects a position. */
|
|
140
|
+
export function needsClassChain(parsed) {
|
|
141
|
+
const { rule } = parsed;
|
|
142
|
+
return Boolean(rule.nested) || [...rule.attributes, ...rule.pseudos].some((attr) => attr.name === 'instance');
|
|
143
|
+
}
|
|
144
|
+
/** Quotes a predicate string literal: the backslash and the quote are the only characters to escape. */
|
|
145
|
+
function quote(value) {
|
|
146
|
+
return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'")}'`;
|
|
147
|
+
}
|
|
148
|
+
function getWordMatcherRegex(word) {
|
|
149
|
+
return `(?s)(.*[ \\t\\r\\n\\f])?${util.escapeRegExp(word)}([ \\t\\r\\n\\f].*)?`;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=class-chain-emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-chain-emitter.js","sourceRoot":"","sources":["../../../lib/css/class-chain-emitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,IAAI,EAAC,MAAM,mBAAmB,CAAC;AAEvC,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,WAAW;IACX,SAAS;IACT,WAAW;IACX,SAAS;IACT,WAAW;IACX,SAAS;IACT,gBAAgB;IAChB,YAAY;IACZ,UAAU;CACX,CAAC,CAAC;AAEH,sEAAsE;AACtE,MAAM,YAAY,GAA2B;IAC3C,WAAW,EAAE,cAAc;IAC3B,aAAa,EAAE,aAAa;IAC5B,IAAI,EAAE,MAAM;IACZ,YAAY,EAAE,OAAO;IACrB,cAAc,EAAE,SAAS;CAC1B,CAAC;AAEF,2FAA2F;AAC3F,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC;AAEhE,wFAAwF;AACxF,MAAM,cAAc,GAAG,aAAa,CAAC;AAErC,MAAM,kBAAkB,GAAG,qCAAqC,CA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
@@ -1,5 +1,9 @@
|
|
|
1
|
-
/** Locator strategy name used for
|
|
2
|
-
export declare const
|
|
3
|
-
/**
|
|
4
|
-
export declare const
|
|
1
|
+
/** Locator strategy name used for class chain queries. */
|
|
2
|
+
export declare const CLASS_CHAIN_STRATEGY = "-android class chain";
|
|
3
|
+
/** Locator strategy name used for predicate string queries. */
|
|
4
|
+
export declare const PREDICATE_STRATEGY = "-android predicate string";
|
|
5
|
+
/** Registry key for the class chain CSS emitter. */
|
|
6
|
+
export declare const CLASS_CHAIN_EMITTER_KEY = "classChain";
|
|
7
|
+
/** Registry key for the predicate string CSS emitter. */
|
|
8
|
+
export declare const PREDICATE_EMITTER_KEY = "predicate";
|
|
5
9
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../lib/css/constants.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../lib/css/constants.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAE3D,+DAA+D;AAC/D,eAAO,MAAM,kBAAkB,8BAA8B,CAAC;AAE9D,oDAAoD;AACpD,eAAO,MAAM,uBAAuB,eAAe,CAAC;AAEpD,yDAAyD;AACzD,eAAO,MAAM,qBAAqB,cAAc,CAAC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
/** Locator strategy name used for
|
|
2
|
-
export const
|
|
3
|
-
/**
|
|
4
|
-
export const
|
|
1
|
+
/** Locator strategy name used for class chain queries. */
|
|
2
|
+
export const CLASS_CHAIN_STRATEGY = '-android class chain';
|
|
3
|
+
/** Locator strategy name used for predicate string queries. */
|
|
4
|
+
export const PREDICATE_STRATEGY = '-android predicate string';
|
|
5
|
+
/** Registry key for the class chain CSS emitter. */
|
|
6
|
+
export const CLASS_CHAIN_EMITTER_KEY = 'classChain';
|
|
7
|
+
/** Registry key for the predicate string CSS emitter. */
|
|
8
|
+
export const PREDICATE_EMITTER_KEY = 'predicate';
|
|
5
9
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../lib/css/constants.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../lib/css/constants.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAE3D,+DAA+D;AAC/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,2BAA2B,CAAC;AAE9D,oDAAoD;AACpD,MAAM,CAAC,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAEpD,yDAAyD;AACzD,MAAM,CAAC,MAAM,qBAAqB,GAAG,WAAW,CAAC"}
|
package/build/lib/css/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NativeLocator } from '@appium/css-locator-to-native';
|
|
2
|
-
export {
|
|
2
|
+
export { CLASS_CHAIN_STRATEGY, PREDICATE_STRATEGY } from './constants.js';
|
|
3
3
|
/**
|
|
4
4
|
* Converts a CSS selector string into a native locator for the resolved strategy.
|
|
5
5
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/css/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,aAAa,EAAc,MAAM,+BAA+B,CAAC;AAQ9F,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/css/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,aAAa,EAAc,MAAM,+BAA+B,CAAC;AAQ9F,OAAO,EAAC,oBAAoB,EAAE,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAkBxE;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,CAOxG"}
|
package/build/lib/css/index.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { errors } from 'appium/driver.js';
|
|
2
2
|
import { util } from 'appium/support.js';
|
|
3
|
-
import {
|
|
3
|
+
import { ClassChainEmitter, needsClassChain, PredicateStringEmitter } from './class-chain-emitter.js';
|
|
4
|
+
import { CLASS_CHAIN_EMITTER_KEY, CLASS_CHAIN_STRATEGY, PREDICATE_EMITTER_KEY, PREDICATE_STRATEGY } from './constants.js';
|
|
4
5
|
import { ATTRIBUTE_SCHEMA } from './schema.js';
|
|
5
|
-
|
|
6
|
-
export { UI_AUTOMATOR_STRATEGY } from './constants.js';
|
|
6
|
+
export { CLASS_CHAIN_STRATEGY, PREDICATE_STRATEGY } from './constants.js';
|
|
7
7
|
const emitters = {
|
|
8
|
-
[
|
|
8
|
+
[CLASS_CHAIN_EMITTER_KEY]: new ClassChainEmitter(CLASS_CHAIN_STRATEGY),
|
|
9
|
+
[PREDICATE_EMITTER_KEY]: new PredicateStringEmitter(PREDICATE_STRATEGY),
|
|
9
10
|
};
|
|
10
11
|
const getTransformCss = util.memoize(async function loadTransformCss() {
|
|
11
12
|
const mod = await import('@appium/css-locator-to-native');
|
|
12
13
|
return mod.createCssTransformer({
|
|
13
14
|
schema: ATTRIBUTE_SCHEMA,
|
|
14
15
|
emitters,
|
|
15
|
-
resolveStrategy() {
|
|
16
|
-
return
|
|
16
|
+
resolveStrategy(parsed) {
|
|
17
|
+
return needsClassChain(parsed) ? CLASS_CHAIN_EMITTER_KEY : PREDICATE_EMITTER_KEY;
|
|
17
18
|
},
|
|
18
19
|
});
|
|
19
20
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/css/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,IAAI,EAAC,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/css/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,IAAI,EAAC,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAC,iBAAiB,EAAE,eAAe,EAAE,sBAAsB,EAAC,MAAM,0BAA0B,CAAC;AACpG,OAAO,EAAC,uBAAuB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AACxH,OAAO,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAC,oBAAoB,EAAE,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAExE,MAAM,QAAQ,GAAG;IACf,CAAC,uBAAuB,CAAC,EAAE,IAAI,iBAAiB,CAAC,oBAAoB,CAAC;IACtE,CAAC,qBAAqB,CAAC,EAAE,IAAI,sBAAsB,CAAC,kBAAkB,CAAC;CACxE,CAAC;AAEF,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,UAAU,gBAAgB;IAClE,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,+BAA+B,CAAC,CAAC;IAC1D,OAAO,GAAG,CAAC,oBAAoB,CAAC;QAC9B,MAAM,EAAE,gBAAgB;QACxB,QAAQ;QACR,eAAe,CAAC,MAAM;YACpB,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,qBAAqB,CAAC;QACnF,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,GAAW,EAAE,UAA0B;IAC9E,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,MAAM,eAAe,EAAE,CAAC;QAC7C,OAAO,YAAY,CAAC,GAAG,EAAE,EAAC,UAAU,EAAC,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,GAAY,EAAE,GAAW;IAC5C,IAAI,cAAc,CAAC,GAAG,EAAE,sBAAsB,CAAC,EAAE,CAAC;QAChD,OAAO,IAAI,MAAM,CAAC,oBAAoB,CAAC,yBAAyB,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;IAC/E,CAAC;IACD,IAAI,cAAc,CAAC,GAAG,EAAE,0BAA0B,CAAC,EAAE,CAAC;QACpD,OAAO,IAAI,MAAM,CAAC,oBAAoB,CAAC,6BAA6B,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;IACnF,CAAC;IACD,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,cAAc,CAAC,GAAY,EAAE,IAAY;IAChD,OAAO,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC;AACnD,CAAC"}
|
package/lib/commands/find.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {warnIfUiScrollableLocator} from '../utils/deprecation.js';
|
|
|
10
10
|
const MAGIC_FIRST_VIS_CHILD_SEL = /\/\*\[@firstVisible ?= ?('|")true\1\]/;
|
|
11
11
|
|
|
12
12
|
const MAGIC_SCROLLABLE_SEL = /\/\/\*\[@scrollable ?= ?('|")true\1\]/;
|
|
13
|
-
const MAGIC_SCROLLABLE_BY = '
|
|
13
|
+
const MAGIC_SCROLLABLE_BY = 'scrollable == true';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Overrides helpers.doFindElementOrEls functionality of appium-android-driver.
|
|
@@ -40,7 +40,7 @@ export async function doFindElementOrEls(
|
|
|
40
40
|
)) as AppiumElement;
|
|
41
41
|
}
|
|
42
42
|
if (params.strategy === 'xpath' && MAGIC_SCROLLABLE_SEL.test(params.selector)) {
|
|
43
|
-
params.strategy = '-android
|
|
43
|
+
params.strategy = '-android predicate string';
|
|
44
44
|
params.selector = MAGIC_SCROLLABLE_BY;
|
|
45
45
|
}
|
|
46
46
|
if (params.strategy === 'css selector') {
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type {ParsedAttribute, ParsedRule, ParsedSelector, StrategyEmitter} from '@appium/css-locator-to-native';
|
|
2
|
+
import {errors} from 'appium/driver.js';
|
|
3
|
+
import {util} from 'appium/support.js';
|
|
4
|
+
|
|
5
|
+
const BOOLEAN_ATTRS = new Set([
|
|
6
|
+
'checkable',
|
|
7
|
+
'checked',
|
|
8
|
+
'clickable',
|
|
9
|
+
'enabled',
|
|
10
|
+
'focusable',
|
|
11
|
+
'focused',
|
|
12
|
+
'long-clickable',
|
|
13
|
+
'scrollable',
|
|
14
|
+
'selected',
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
/** CSS attribute name -> element attribute used in the predicates. */
|
|
18
|
+
const STRING_ATTRS: Record<string, string> = {
|
|
19
|
+
description: 'content-desc',
|
|
20
|
+
'resource-id': 'resource-id',
|
|
21
|
+
text: 'text',
|
|
22
|
+
'class-name': 'class',
|
|
23
|
+
'package-name': 'package',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** The old UiSelector methods matched these two attributes without respect to the case. */
|
|
27
|
+
const CASE_INSENSITIVE_ATTRS = new Set(['description', 'text']);
|
|
28
|
+
|
|
29
|
+
/** CSS whitespace only, unlike `\s` it does not include e.g. the non-breaking space. */
|
|
30
|
+
const CSS_WHITESPACE = /[ \t\r\n\f]/;
|
|
31
|
+
|
|
32
|
+
const ID_LOCATOR_PATTERN = /^[a-zA-Z_][a-zA-Z0-9._]*:id\/[\S]+$/;
|
|
33
|
+
|
|
34
|
+
export interface ClassChainEmitterContext {
|
|
35
|
+
appPackage?: string | null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Converts parsed CSS selectors into class chain strings. */
|
|
39
|
+
export class ClassChainEmitter implements StrategyEmitter<ClassChainEmitterContext> {
|
|
40
|
+
readonly strategy: string;
|
|
41
|
+
|
|
42
|
+
constructor(strategy: string) {
|
|
43
|
+
this.strategy = strategy;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
emit(parsed: ParsedSelector, ctx?: ClassChainEmitterContext): string {
|
|
47
|
+
return this.emitRule(parsed.rule, ctx);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Splits a rule into the type of a step, the predicates that restrict it and an optional position. */
|
|
51
|
+
protected buildStep(
|
|
52
|
+
rule: ParsedRule,
|
|
53
|
+
ctx?: ClassChainEmitterContext,
|
|
54
|
+
): {type: string; predicates: string[]; position?: number} {
|
|
55
|
+
const {type, predicates: classPredicates} = this.formatClass(rule);
|
|
56
|
+
const predicates = [...classPredicates];
|
|
57
|
+
let position: number | undefined;
|
|
58
|
+
|
|
59
|
+
if (rule.id) {
|
|
60
|
+
predicates.push(`resource-id == ${quote(this.formatIdLocator(rule.id, ctx?.appPackage))}`);
|
|
61
|
+
}
|
|
62
|
+
for (const attr of [...rule.attributes, ...rule.pseudos]) {
|
|
63
|
+
if (attr.name === 'instance') {
|
|
64
|
+
// instance() is zero-based, positions of a class chain start with 1
|
|
65
|
+
position = Number(attr.value) + 1;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
predicates.push(this.formatPredicate(attr, ctx));
|
|
69
|
+
}
|
|
70
|
+
return {type, predicates, position};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private emitRule(rule: ParsedRule, ctx?: ClassChainEmitterContext): string {
|
|
74
|
+
const {type, predicates, position} = this.buildStep(rule, ctx);
|
|
75
|
+
|
|
76
|
+
let step = type;
|
|
77
|
+
if (predicates.length) {
|
|
78
|
+
step += `[\`${predicates.join(' AND ').replaceAll('`', '``')}\`]`;
|
|
79
|
+
}
|
|
80
|
+
if (position !== undefined) {
|
|
81
|
+
step += `[${position}]`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// The first rule is searched for anywhere, the nested ones relative to the previous one
|
|
85
|
+
const separator = !rule.combinator ? '**/' : rule.combinator === 'child' ? '/' : '/**/';
|
|
86
|
+
const chain = `${separator}${step}`;
|
|
87
|
+
return rule.nested ? `${chain}${this.emitRule(rule.nested, ctx)}` : chain;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A fully qualified class is the type of a step, a partial one (`TextView`, `.widget.TextView`) is a suffix. */
|
|
91
|
+
private formatClass(rule: ParsedRule): {type: string; predicates: string[]} {
|
|
92
|
+
const tagName = rule.tag && rule.tag !== '*' ? rule.tag : '';
|
|
93
|
+
const classNames = [...rule.classes];
|
|
94
|
+
if (tagName && classNames.length) {
|
|
95
|
+
return {type: [tagName, ...classNames].join('.'), predicates: []};
|
|
96
|
+
}
|
|
97
|
+
const partialName = [tagName, ...classNames].filter(Boolean).join('.');
|
|
98
|
+
if (!partialName) {
|
|
99
|
+
return {type: '*', predicates: []};
|
|
100
|
+
}
|
|
101
|
+
// The name may also be the whole class name, e.g. an unqualified one, which has no leading dot
|
|
102
|
+
const predicate = `(class == ${quote(partialName)} OR class ENDSWITH ${quote(`.${partialName}`)})`;
|
|
103
|
+
return {type: '*', predicates: [predicate]};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private formatPredicate(attr: ParsedAttribute, ctx?: ClassChainEmitterContext): string {
|
|
107
|
+
if (BOOLEAN_ATTRS.has(attr.name)) {
|
|
108
|
+
return `${attr.name} == ${attr.value ?? 'true'}`;
|
|
109
|
+
}
|
|
110
|
+
if (attr.name === 'index') {
|
|
111
|
+
return `index == ${attr.value}`;
|
|
112
|
+
}
|
|
113
|
+
return this.formatStringPredicate(attr, ctx);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private formatStringPredicate(attr: ParsedAttribute, ctx?: ClassChainEmitterContext): string {
|
|
117
|
+
const name = STRING_ATTRS[attr.name];
|
|
118
|
+
if (!name) {
|
|
119
|
+
throw new errors.InvalidSelectorError(`Unsupported attribute '${attr.name}'`);
|
|
120
|
+
}
|
|
121
|
+
if (attr.operator === undefined) {
|
|
122
|
+
// A missing value also satisfies `!= ''`, so it has to be excluded explicitly
|
|
123
|
+
return `${name} != nil AND ${name} != ''`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let value = attr.value ?? '';
|
|
127
|
+
// Only an exact id is qualified, substring operators get the fragment as is
|
|
128
|
+
if (attr.name === 'resource-id' && (attr.operator === '=' || attr.operator === undefined)) {
|
|
129
|
+
value = this.formatIdLocator(value, ctx?.appPackage);
|
|
130
|
+
}
|
|
131
|
+
const modifier = CASE_INSENSITIVE_ATTRS.has(attr.name) ? '[c]' : '';
|
|
132
|
+
switch (attr.operator) {
|
|
133
|
+
case '*=':
|
|
134
|
+
return `${name} CONTAINS${modifier} ${quote(value)}`;
|
|
135
|
+
case '^=':
|
|
136
|
+
return `${name} BEGINSWITH${modifier} ${quote(value)}`;
|
|
137
|
+
case '$=':
|
|
138
|
+
return `${name} ENDSWITH ${quote(value)}`;
|
|
139
|
+
case '~=':
|
|
140
|
+
// CSS words are whitespace-delimited, so an empty value or one with whitespace never matches
|
|
141
|
+
if (!value || CSS_WHITESPACE.test(value)) {
|
|
142
|
+
return 'FALSEPREDICATE';
|
|
143
|
+
}
|
|
144
|
+
return `${name} MATCHES ${quote(getWordMatcherRegex(value))}`;
|
|
145
|
+
default:
|
|
146
|
+
return `${name} == ${quote(value)}`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private formatIdLocator(locator: string, appPackage?: string | null): string {
|
|
151
|
+
return ID_LOCATOR_PATTERN.test(locator) ? locator : `${appPackage || 'android'}:id/${locator}`;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Converts a parsed CSS selector that is a single rule without a position into a predicate string.
|
|
157
|
+
* It is the same as a class chain of a single step with the predicate, but shorter.
|
|
158
|
+
*/
|
|
159
|
+
export class PredicateStringEmitter extends ClassChainEmitter {
|
|
160
|
+
override emit(parsed: ParsedSelector, ctx?: ClassChainEmitterContext): string {
|
|
161
|
+
const {type, predicates} = this.buildStep(parsed.rule, ctx);
|
|
162
|
+
const all = type === '*' ? predicates : [`class == ${quote(type)}`, ...predicates];
|
|
163
|
+
return all.length ? all.join(' AND ') : 'TRUEPREDICATE';
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Whether the selector needs a class chain: it has more than one rule or selects a position. */
|
|
168
|
+
export function needsClassChain(parsed: ParsedSelector): boolean {
|
|
169
|
+
const {rule} = parsed;
|
|
170
|
+
return Boolean(rule.nested) || [...rule.attributes, ...rule.pseudos].some((attr) => attr.name === 'instance');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Quotes a predicate string literal: the backslash and the quote are the only characters to escape. */
|
|
174
|
+
function quote(value: string): string {
|
|
175
|
+
return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'")}'`;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function getWordMatcherRegex(word: string): string {
|
|
179
|
+
return `(?s)(.*[ \\t\\r\\n\\f])?${util.escapeRegExp(word)}([ \\t\\r\\n\\f].*)?`;
|
|
180
|
+
}
|
package/lib/css/constants.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
/** Locator strategy name used for
|
|
2
|
-
export const
|
|
1
|
+
/** Locator strategy name used for class chain queries. */
|
|
2
|
+
export const CLASS_CHAIN_STRATEGY = '-android class chain';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
export const
|
|
4
|
+
/** Locator strategy name used for predicate string queries. */
|
|
5
|
+
export const PREDICATE_STRATEGY = '-android predicate string';
|
|
6
|
+
|
|
7
|
+
/** Registry key for the class chain CSS emitter. */
|
|
8
|
+
export const CLASS_CHAIN_EMITTER_KEY = 'classChain';
|
|
9
|
+
|
|
10
|
+
/** Registry key for the predicate string CSS emitter. */
|
|
11
|
+
export const PREDICATE_EMITTER_KEY = 'predicate';
|
package/lib/css/index.ts
CHANGED
|
@@ -2,14 +2,15 @@ import type {CssTransformer, NativeLocator, StrategyKey} from '@appium/css-locat
|
|
|
2
2
|
import {errors} from 'appium/driver.js';
|
|
3
3
|
import {util} from 'appium/support.js';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {ClassChainEmitter, needsClassChain, PredicateStringEmitter} from './class-chain-emitter.js';
|
|
6
|
+
import {CLASS_CHAIN_EMITTER_KEY, CLASS_CHAIN_STRATEGY, PREDICATE_EMITTER_KEY, PREDICATE_STRATEGY} from './constants.js';
|
|
6
7
|
import {ATTRIBUTE_SCHEMA} from './schema.js';
|
|
7
|
-
import {UiAutomatorEmitter} from './ui-automator-emitter.js';
|
|
8
8
|
|
|
9
|
-
export {
|
|
9
|
+
export {CLASS_CHAIN_STRATEGY, PREDICATE_STRATEGY} from './constants.js';
|
|
10
10
|
|
|
11
11
|
const emitters = {
|
|
12
|
-
[
|
|
12
|
+
[CLASS_CHAIN_EMITTER_KEY]: new ClassChainEmitter(CLASS_CHAIN_STRATEGY),
|
|
13
|
+
[PREDICATE_EMITTER_KEY]: new PredicateStringEmitter(PREDICATE_STRATEGY),
|
|
13
14
|
};
|
|
14
15
|
|
|
15
16
|
const getTransformCss = util.memoize(async function loadTransformCss(): Promise<CssTransformer> {
|
|
@@ -17,8 +18,8 @@ const getTransformCss = util.memoize(async function loadTransformCss(): Promise<
|
|
|
17
18
|
return mod.createCssTransformer({
|
|
18
19
|
schema: ATTRIBUTE_SCHEMA,
|
|
19
20
|
emitters,
|
|
20
|
-
resolveStrategy(): StrategyKey<typeof emitters> {
|
|
21
|
-
return
|
|
21
|
+
resolveStrategy(parsed): StrategyKey<typeof emitters> {
|
|
22
|
+
return needsClassChain(parsed) ? CLASS_CHAIN_EMITTER_KEY : PREDICATE_EMITTER_KEY;
|
|
22
23
|
},
|
|
23
24
|
});
|
|
24
25
|
});
|
|
@@ -8,7 +8,7 @@ This package contains type definitions for node (https://nodejs.org/).
|
|
|
8
8
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node.
|
|
9
9
|
|
|
10
10
|
### Additional Details
|
|
11
|
-
* Last updated: Wed,
|
|
11
|
+
* Last updated: Wed, 25 Nov 2026 07:32:29 GMT
|
|
12
12
|
* Dependencies: [undici-types](https://npmjs.com/package/undici-types)
|
|
13
13
|
|
|
14
14
|
# Credits
|
|
@@ -3797,12 +3797,12 @@ declare module "node:crypto" {
|
|
|
3797
3797
|
generateKey(
|
|
3798
3798
|
algorithm: RsaHashedKeyGenParams | EcKeyGenParams,
|
|
3799
3799
|
extractable: boolean,
|
|
3800
|
-
keyUsages: KeyUsage[],
|
|
3800
|
+
keyUsages: readonly KeyUsage[],
|
|
3801
3801
|
): Promise<CryptoKeyPair>;
|
|
3802
3802
|
generateKey(
|
|
3803
3803
|
algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params | KmacKeyGenParams,
|
|
3804
3804
|
extractable: boolean,
|
|
3805
|
-
keyUsages: KeyUsage[],
|
|
3805
|
+
keyUsages: readonly KeyUsage[],
|
|
3806
3806
|
): Promise<CryptoKey>;
|
|
3807
3807
|
generateKey(
|
|
3808
3808
|
algorithm: AlgorithmIdentifier,
|
|
@@ -3821,7 +3821,7 @@ declare module "node:crypto" {
|
|
|
3821
3821
|
| AesKeyAlgorithm
|
|
3822
3822
|
| KmacImportParams,
|
|
3823
3823
|
extractable: boolean,
|
|
3824
|
-
keyUsages: KeyUsage[],
|
|
3824
|
+
keyUsages: readonly KeyUsage[],
|
|
3825
3825
|
): Promise<CryptoKey>;
|
|
3826
3826
|
importKey(
|
|
3827
3827
|
format: Exclude<KeyFormat, "jwk">,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/node",
|
|
3
|
-
"version": "26.6.
|
|
3
|
+
"version": "26.6.10",
|
|
4
4
|
"description": "TypeScript definitions for node",
|
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
|
|
6
6
|
"license": "MIT",
|
|
@@ -135,6 +135,6 @@
|
|
|
135
135
|
"undici-types": "~8.9.0"
|
|
136
136
|
},
|
|
137
137
|
"peerDependencies": {},
|
|
138
|
-
"typesPublisherContentHash": "
|
|
138
|
+
"typesPublisherContentHash": "2a076da122503d39fe16ca3fa4236b6a47fe9b8829007bb1286ba5d287578531",
|
|
139
139
|
"typeScriptVersion": "5.6"
|
|
140
140
|
}
|
|
@@ -1016,6 +1016,10 @@ declare module "node:test" {
|
|
|
1016
1016
|
* The total number of cancelled tests.
|
|
1017
1017
|
*/
|
|
1018
1018
|
cancelled: number;
|
|
1019
|
+
/**
|
|
1020
|
+
* The total number of failed tests.
|
|
1021
|
+
*/
|
|
1022
|
+
failed: number;
|
|
1019
1023
|
/**
|
|
1020
1024
|
* The total number of passed tests.
|
|
1021
1025
|
*/
|
|
@@ -500,6 +500,7 @@ declare module "node:url" {
|
|
|
500
500
|
readonly searchParams: URLSearchParams;
|
|
501
501
|
username: string;
|
|
502
502
|
toJSON(): string;
|
|
503
|
+
toString(): string;
|
|
503
504
|
}
|
|
504
505
|
var URL: {
|
|
505
506
|
prototype: URL;
|
|
@@ -541,6 +542,7 @@ declare module "node:url" {
|
|
|
541
542
|
entries(): URLSearchParamsIterator<[string, string]>;
|
|
542
543
|
keys(): URLSearchParamsIterator<string>;
|
|
543
544
|
values(): URLSearchParamsIterator<string>;
|
|
545
|
+
toString(): string;
|
|
544
546
|
}
|
|
545
547
|
var URLSearchParams: {
|
|
546
548
|
prototype: URLSearchParams;
|
|
@@ -1204,7 +1204,7 @@ declare module "node:util" {
|
|
|
1204
1204
|
* A stream that will be validated if it can be colored.
|
|
1205
1205
|
* @default process.stdout
|
|
1206
1206
|
*/
|
|
1207
|
-
stream?: NodeJS.WritableStream | undefined;
|
|
1207
|
+
stream?: NodeJS.ReadableStream | NodeJS.WritableStream | undefined;
|
|
1208
1208
|
}
|
|
1209
1209
|
/**
|
|
1210
1210
|
* This function returns a formatted text considering the `format` passed
|
|
@@ -2,10 +2,13 @@ export {};
|
|
|
2
2
|
|
|
3
3
|
import * as util from "node:util";
|
|
4
4
|
|
|
5
|
+
type _TextDecoder = typeof globalThis extends { onmessage: any } ? {} : util.TextDecoder;
|
|
6
|
+
type _TextEncoder = typeof globalThis extends { onmessage: any } ? {} : util.TextEncoder;
|
|
7
|
+
|
|
5
8
|
declare global {
|
|
6
|
-
interface TextDecoder extends
|
|
9
|
+
interface TextDecoder extends _TextDecoder {}
|
|
7
10
|
var TextDecoder: typeof globalThis extends { onmessage: any; TextDecoder: infer T } ? T : typeof util.TextDecoder;
|
|
8
11
|
|
|
9
|
-
interface TextEncoder extends
|
|
12
|
+
interface TextEncoder extends _TextEncoder {}
|
|
10
13
|
var TextEncoder: typeof globalThis extends { onmessage: any; TextEncoder: infer T } ? T : typeof util.TextEncoder;
|
|
11
14
|
}
|
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [11.6.1](https://github.com/appium/appium-android/compare/appium-uiautomator2-server@11.6.0...appium-uiautomator2-server@11.6.1) (2026-11-25)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **uiautomator2-server:** respect currentDisplayId for the active window root ([#180](https://github.com/appium/appium-android/issues/180)) ([af3e654](https://github.com/appium/appium-android/commit/af3e6549988e85cc71eb7d095a70e9cc680c7548))
|
|
11
|
+
|
|
12
|
+
|
|
6
13
|
## [11.6.0](https://github.com/appium/appium-android/compare/appium-uiautomator2-server@11.5.0...appium-uiautomator2-server@11.6.0) (2026-11-24)
|
|
7
14
|
|
|
8
15
|
### Features
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appium-uiautomator2-server",
|
|
3
|
-
"version": "11.6.
|
|
3
|
+
"version": "11.6.1",
|
|
4
4
|
"description": "A netty server with uiautomator2 handlers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"android",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"node": "^22.22.2 || ^24.15.0 || >=26.0.0",
|
|
58
58
|
"npm": ">=10"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "49bd86b16f325a8fbefec46ea601b1fe105be5af"
|
|
61
61
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appium-uiautomator2-driver",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.4.0",
|
|
4
4
|
"description": "UiAutomator2 integration for Appium",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"android",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@appium/css-locator-to-native": "2.0.1",
|
|
43
43
|
"appium-adb": "17.0.4",
|
|
44
44
|
"appium-android-driver": "16.1.3",
|
|
45
|
-
"appium-uiautomator2-server": "11.6.
|
|
45
|
+
"appium-uiautomator2-server": "11.6.1",
|
|
46
46
|
"asyncbox": "7.1.0",
|
|
47
47
|
"axios": "1.21.1",
|
|
48
48
|
"io.appium.settings": "9.2.4",
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ParsedSelector, StrategyEmitter } from '@appium/css-locator-to-native';
|
|
2
|
-
export interface UiAutomatorEmitterContext {
|
|
3
|
-
appPackage?: string | null;
|
|
4
|
-
}
|
|
5
|
-
/** Converts parsed CSS selectors into UiAutomator selector strings. */
|
|
6
|
-
export declare class UiAutomatorEmitter implements StrategyEmitter<UiAutomatorEmitterContext> {
|
|
7
|
-
readonly strategy: string;
|
|
8
|
-
constructor(strategy: string);
|
|
9
|
-
emit(parsed: ParsedSelector, ctx?: UiAutomatorEmitterContext): string;
|
|
10
|
-
private emitRule;
|
|
11
|
-
private formatEntity;
|
|
12
|
-
private formatBoolean;
|
|
13
|
-
private formatStringAttr;
|
|
14
|
-
private formatIdLocator;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=ui-automator-emitter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ui-automator-emitter.d.ts","sourceRoot":"","sources":["../../../lib/css/ui-automator-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA8B,cAAc,EAAE,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAqBhH,MAAM,WAAW,yBAAyB;IACxC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,uEAAuE;AACvE,qBAAa,kBAAmB,YAAW,eAAe,CAAC,yBAAyB,CAAC;IACnF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,QAAQ,EAAE,MAAM;IAI5B,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,yBAAyB,GAAG,MAAM;IAIrE,OAAO,CAAC,QAAQ;IAsChB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,gBAAgB;IAkCxB,OAAO,CAAC,eAAe;CAGxB"}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { util } from 'appium/support.js';
|
|
2
|
-
const BOOLEAN_ATTRS = new Set([
|
|
3
|
-
'checkable',
|
|
4
|
-
'checked',
|
|
5
|
-
'clickable',
|
|
6
|
-
'enabled',
|
|
7
|
-
'focusable',
|
|
8
|
-
'focused',
|
|
9
|
-
'long-clickable',
|
|
10
|
-
'scrollable',
|
|
11
|
-
'selected',
|
|
12
|
-
]);
|
|
13
|
-
const NUMERIC_ATTRS = new Set(['index', 'instance']);
|
|
14
|
-
const STRING_ATTRS = new Set(['description', 'resource-id', 'text', 'class-name', 'package-name']);
|
|
15
|
-
const ID_LOCATOR_PATTERN = /^[a-zA-Z_][a-zA-Z0-9._]*:id\/[\S]+$/;
|
|
16
|
-
/** Converts parsed CSS selectors into UiAutomator selector strings. */
|
|
17
|
-
export class UiAutomatorEmitter {
|
|
18
|
-
strategy;
|
|
19
|
-
constructor(strategy) {
|
|
20
|
-
this.strategy = strategy;
|
|
21
|
-
}
|
|
22
|
-
emit(parsed, ctx) {
|
|
23
|
-
return this.emitRule(parsed.rule, ctx);
|
|
24
|
-
}
|
|
25
|
-
emitRule(rule, ctx) {
|
|
26
|
-
const parts = ['new UiSelector()'];
|
|
27
|
-
const tagName = rule.tag;
|
|
28
|
-
const classNames = [...rule.classes];
|
|
29
|
-
if (tagName && tagName !== '*') {
|
|
30
|
-
if (classNames.length) {
|
|
31
|
-
parts.push(`.className("${[tagName, ...classNames].join('.')}")`);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
parts.push(`.classNameMatches("${tagName}")`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
else if (classNames.length) {
|
|
38
|
-
parts.push(`.classNameMatches("${classNames.join('\\.')}")`);
|
|
39
|
-
}
|
|
40
|
-
if (rule.id) {
|
|
41
|
-
parts.push(`.resourceId("${this.formatIdLocator(rule.id, ctx?.appPackage)}")`);
|
|
42
|
-
}
|
|
43
|
-
for (const attr of rule.attributes) {
|
|
44
|
-
parts.push(this.formatEntity(attr, ctx));
|
|
45
|
-
}
|
|
46
|
-
for (const pseudo of rule.pseudos) {
|
|
47
|
-
const formatted = this.formatEntity(pseudo, ctx);
|
|
48
|
-
if (formatted) {
|
|
49
|
-
parts.push(formatted);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (rule.nested) {
|
|
53
|
-
parts.push(`.childSelector(${this.emitRule(rule.nested, ctx)})`);
|
|
54
|
-
}
|
|
55
|
-
return parts.join('');
|
|
56
|
-
}
|
|
57
|
-
formatEntity(attr, ctx) {
|
|
58
|
-
if (BOOLEAN_ATTRS.has(attr.name)) {
|
|
59
|
-
return this.formatBoolean(attr);
|
|
60
|
-
}
|
|
61
|
-
if (NUMERIC_ATTRS.has(attr.name)) {
|
|
62
|
-
return `.${attr.name}(${attr.value})`;
|
|
63
|
-
}
|
|
64
|
-
if (STRING_ATTRS.has(attr.name)) {
|
|
65
|
-
return this.formatStringAttr(attr, ctx);
|
|
66
|
-
}
|
|
67
|
-
return '';
|
|
68
|
-
}
|
|
69
|
-
formatBoolean(attr) {
|
|
70
|
-
const value = attr.value ?? 'true';
|
|
71
|
-
return `.${toSnakeCase(attr.name)}(${value})`;
|
|
72
|
-
}
|
|
73
|
-
formatStringAttr(attr, ctx) {
|
|
74
|
-
const methodName = toSnakeCase(attr.name);
|
|
75
|
-
let value = attr.value ?? '';
|
|
76
|
-
if (attr.name === 'resource-id') {
|
|
77
|
-
value = this.formatIdLocator(value, ctx?.appPackage);
|
|
78
|
-
}
|
|
79
|
-
if (value === '') {
|
|
80
|
-
return `.${methodName}Matches("")`;
|
|
81
|
-
}
|
|
82
|
-
switch (attr.operator) {
|
|
83
|
-
case '=':
|
|
84
|
-
return `.${methodName}("${value}")`;
|
|
85
|
-
case '*=':
|
|
86
|
-
if (['description', 'text'].includes(attr.name)) {
|
|
87
|
-
return `.${methodName}Contains("${value}")`;
|
|
88
|
-
}
|
|
89
|
-
return `.${methodName}Matches("${util.escapeRegExp(value)}")`;
|
|
90
|
-
case '^=':
|
|
91
|
-
if (['description', 'text'].includes(attr.name)) {
|
|
92
|
-
return `.${methodName}StartsWith("${value}")`;
|
|
93
|
-
}
|
|
94
|
-
return `.${methodName}Matches("^${util.escapeRegExp(value)}")`;
|
|
95
|
-
case '$=':
|
|
96
|
-
return `.${methodName}Matches("${util.escapeRegExp(value)}$")`;
|
|
97
|
-
case '~=':
|
|
98
|
-
return `.${methodName}Matches("${getWordMatcherRegex(value)}")`;
|
|
99
|
-
default:
|
|
100
|
-
return `.${methodName}("${value}")`;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
formatIdLocator(locator, appPackage) {
|
|
104
|
-
return ID_LOCATOR_PATTERN.test(locator) ? locator : `${appPackage || 'android'}:id/${locator}`;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
function toSnakeCase(str) {
|
|
108
|
-
const tokens = str.split('-').map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase());
|
|
109
|
-
const out = tokens.join('');
|
|
110
|
-
return out.charAt(0).toLowerCase() + out.slice(1);
|
|
111
|
-
}
|
|
112
|
-
function getWordMatcherRegex(word) {
|
|
113
|
-
return `\\b(\\w*${util.escapeRegExp(word)}\\w*)\\b`;
|
|
114
|
-
}
|
|
115
|
-
//# sourceMappingURL=ui-automator-emitter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ui-automator-emitter.js","sourceRoot":"","sources":["../../../lib/css/ui-automator-emitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,mBAAmB,CAAC;AAEvC,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,WAAW;IACX,SAAS;IACT,WAAW;IACX,SAAS;IACT,WAAW;IACX,SAAS;IACT,gBAAgB;IAChB,YAAY;IACZ,UAAU;CACX,CAAC,CAAC;AAEH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AAErD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC;AAEnG,MAAM,kBAAk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IAAI,CAAC;YAClE;gBACE,OAAO,IAAI,UAAU,KAAK,KAAK,IAAI,CAAC;QACxC,CAAC;IACH,CAAC;IAEO,eAAe,CAAC,OAAe,EAAE,UAA0B;QACjE,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,UAAU,IAAI,SAAS,OAAO,OAAO,EAAE,CAAC;IACjG,CAAC;CACF;AAED,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IAC3G,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO,WAAW,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;AACtD,CAAC"}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import type {ParsedAttribute, ParsedRule, ParsedSelector, StrategyEmitter} from '@appium/css-locator-to-native';
|
|
2
|
-
import {util} from 'appium/support.js';
|
|
3
|
-
|
|
4
|
-
const BOOLEAN_ATTRS = new Set([
|
|
5
|
-
'checkable',
|
|
6
|
-
'checked',
|
|
7
|
-
'clickable',
|
|
8
|
-
'enabled',
|
|
9
|
-
'focusable',
|
|
10
|
-
'focused',
|
|
11
|
-
'long-clickable',
|
|
12
|
-
'scrollable',
|
|
13
|
-
'selected',
|
|
14
|
-
]);
|
|
15
|
-
|
|
16
|
-
const NUMERIC_ATTRS = new Set(['index', 'instance']);
|
|
17
|
-
|
|
18
|
-
const STRING_ATTRS = new Set(['description', 'resource-id', 'text', 'class-name', 'package-name']);
|
|
19
|
-
|
|
20
|
-
const ID_LOCATOR_PATTERN = /^[a-zA-Z_][a-zA-Z0-9._]*:id\/[\S]+$/;
|
|
21
|
-
|
|
22
|
-
export interface UiAutomatorEmitterContext {
|
|
23
|
-
appPackage?: string | null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Converts parsed CSS selectors into UiAutomator selector strings. */
|
|
27
|
-
export class UiAutomatorEmitter implements StrategyEmitter<UiAutomatorEmitterContext> {
|
|
28
|
-
readonly strategy: string;
|
|
29
|
-
|
|
30
|
-
constructor(strategy: string) {
|
|
31
|
-
this.strategy = strategy;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
emit(parsed: ParsedSelector, ctx?: UiAutomatorEmitterContext): string {
|
|
35
|
-
return this.emitRule(parsed.rule, ctx);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private emitRule(rule: ParsedRule, ctx?: UiAutomatorEmitterContext): string {
|
|
39
|
-
const parts: string[] = ['new UiSelector()'];
|
|
40
|
-
|
|
41
|
-
const tagName = rule.tag;
|
|
42
|
-
const classNames = [...rule.classes];
|
|
43
|
-
|
|
44
|
-
if (tagName && tagName !== '*') {
|
|
45
|
-
if (classNames.length) {
|
|
46
|
-
parts.push(`.className("${[tagName, ...classNames].join('.')}")`);
|
|
47
|
-
} else {
|
|
48
|
-
parts.push(`.classNameMatches("${tagName}")`);
|
|
49
|
-
}
|
|
50
|
-
} else if (classNames.length) {
|
|
51
|
-
parts.push(`.classNameMatches("${classNames.join('\\.')}")`);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (rule.id) {
|
|
55
|
-
parts.push(`.resourceId("${this.formatIdLocator(rule.id, ctx?.appPackage)}")`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
for (const attr of rule.attributes) {
|
|
59
|
-
parts.push(this.formatEntity(attr, ctx));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
for (const pseudo of rule.pseudos) {
|
|
63
|
-
const formatted = this.formatEntity(pseudo, ctx);
|
|
64
|
-
if (formatted) {
|
|
65
|
-
parts.push(formatted);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (rule.nested) {
|
|
70
|
-
parts.push(`.childSelector(${this.emitRule(rule.nested, ctx)})`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return parts.join('');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private formatEntity(attr: ParsedAttribute, ctx?: UiAutomatorEmitterContext): string {
|
|
77
|
-
if (BOOLEAN_ATTRS.has(attr.name)) {
|
|
78
|
-
return this.formatBoolean(attr);
|
|
79
|
-
}
|
|
80
|
-
if (NUMERIC_ATTRS.has(attr.name)) {
|
|
81
|
-
return `.${attr.name}(${attr.value})`;
|
|
82
|
-
}
|
|
83
|
-
if (STRING_ATTRS.has(attr.name)) {
|
|
84
|
-
return this.formatStringAttr(attr, ctx);
|
|
85
|
-
}
|
|
86
|
-
return '';
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private formatBoolean(attr: ParsedAttribute): string {
|
|
90
|
-
const value = attr.value ?? 'true';
|
|
91
|
-
return `.${toSnakeCase(attr.name)}(${value})`;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
private formatStringAttr(attr: ParsedAttribute, ctx?: UiAutomatorEmitterContext): string {
|
|
95
|
-
const methodName = toSnakeCase(attr.name);
|
|
96
|
-
let value = attr.value ?? '';
|
|
97
|
-
|
|
98
|
-
if (attr.name === 'resource-id') {
|
|
99
|
-
value = this.formatIdLocator(value, ctx?.appPackage);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (value === '') {
|
|
103
|
-
return `.${methodName}Matches("")`;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
switch (attr.operator) {
|
|
107
|
-
case '=':
|
|
108
|
-
return `.${methodName}("${value}")`;
|
|
109
|
-
case '*=':
|
|
110
|
-
if (['description', 'text'].includes(attr.name)) {
|
|
111
|
-
return `.${methodName}Contains("${value}")`;
|
|
112
|
-
}
|
|
113
|
-
return `.${methodName}Matches("${util.escapeRegExp(value)}")`;
|
|
114
|
-
case '^=':
|
|
115
|
-
if (['description', 'text'].includes(attr.name)) {
|
|
116
|
-
return `.${methodName}StartsWith("${value}")`;
|
|
117
|
-
}
|
|
118
|
-
return `.${methodName}Matches("^${util.escapeRegExp(value)}")`;
|
|
119
|
-
case '$=':
|
|
120
|
-
return `.${methodName}Matches("${util.escapeRegExp(value)}$")`;
|
|
121
|
-
case '~=':
|
|
122
|
-
return `.${methodName}Matches("${getWordMatcherRegex(value)}")`;
|
|
123
|
-
default:
|
|
124
|
-
return `.${methodName}("${value}")`;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
private formatIdLocator(locator: string, appPackage?: string | null): string {
|
|
129
|
-
return ID_LOCATOR_PATTERN.test(locator) ? locator : `${appPackage || 'android'}:id/${locator}`;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function toSnakeCase(str: string): string {
|
|
134
|
-
const tokens = str.split('-').map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase());
|
|
135
|
-
const out = tokens.join('');
|
|
136
|
-
return out.charAt(0).toLowerCase() + out.slice(1);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function getWordMatcherRegex(word: string): string {
|
|
140
|
-
return `\\b(\\w*${util.escapeRegExp(word)}\\w*)\\b`;
|
|
141
|
-
}
|