appium-uiautomator2-driver 10.3.0 → 10.4.1

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/lib/commands/find.js +2 -2
  3. package/build/lib/commands/find.js.map +1 -1
  4. package/build/lib/css/class-chain-emitter.d.ts +32 -0
  5. package/build/lib/css/class-chain-emitter.d.ts.map +1 -0
  6. package/build/lib/css/class-chain-emitter.js +151 -0
  7. package/build/lib/css/class-chain-emitter.js.map +1 -0
  8. package/build/lib/css/constants.d.ts +8 -4
  9. package/build/lib/css/constants.d.ts.map +1 -1
  10. package/build/lib/css/constants.js +8 -4
  11. package/build/lib/css/constants.js.map +1 -1
  12. package/build/lib/css/index.d.ts +1 -1
  13. package/build/lib/css/index.d.ts.map +1 -1
  14. package/build/lib/css/index.js +7 -6
  15. package/build/lib/css/index.js.map +1 -1
  16. package/lib/commands/find.ts +2 -2
  17. package/lib/css/class-chain-emitter.ts +180 -0
  18. package/lib/css/constants.ts +10 -4
  19. package/lib/css/index.ts +7 -6
  20. package/node_modules/@appium/base-driver/package.json +4 -4
  21. package/node_modules/@appium/support/package.json +3 -3
  22. package/node_modules/@appium/types/build/lib/command-maps.d.ts +129 -101
  23. package/node_modules/@appium/types/build/lib/command-maps.d.ts.map +1 -1
  24. package/node_modules/@appium/types/build/lib/driver.d.ts +1 -0
  25. package/node_modules/@appium/types/build/lib/driver.d.ts.map +1 -1
  26. package/node_modules/@appium/types/build/lib/plugin.d.ts +1 -1
  27. package/node_modules/@appium/types/lib/command-maps.ts +316 -112
  28. package/node_modules/@appium/types/lib/driver.ts +1 -0
  29. package/node_modules/@appium/types/lib/plugin.ts +1 -1
  30. package/node_modules/@appium/types/package.json +5 -5
  31. package/node_modules/@types/body-parser/README.md +1 -1
  32. package/node_modules/@types/body-parser/index.d.ts +35 -3
  33. package/node_modules/@types/body-parser/package.json +3 -3
  34. package/node_modules/@types/node/README.md +1 -1
  35. package/node_modules/@types/node/assert/strict.d.ts +1 -1
  36. package/node_modules/@types/node/assert.d.ts +13 -13
  37. package/node_modules/@types/node/crypto.d.ts +3 -3
  38. package/node_modules/@types/node/package.json +2 -2
  39. package/node_modules/@types/node/test.d.ts +4 -0
  40. package/node_modules/@types/node/url.d.ts +2 -0
  41. package/node_modules/@types/node/util.d.ts +1 -1
  42. package/node_modules/@types/node/web-globals/encoding.d.ts +5 -2
  43. package/node_modules/appium-android-driver/CHANGELOG.md +8 -0
  44. package/node_modules/appium-android-driver/package.json +3 -3
  45. package/node_modules/appium-chromedriver/CHANGELOG.md +7 -0
  46. package/node_modules/appium-chromedriver/config/edge-checksums.json +13 -0
  47. package/node_modules/appium-chromedriver/package.json +2 -2
  48. package/node_modules/appium-uiautomator2-server/CHANGELOG.md +7 -0
  49. package/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk +0 -0
  50. package/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk.idsig +0 -0
  51. package/node_modules/appium-uiautomator2-server/apks/{appium-uiautomator2-server-v11.6.0.apk → appium-uiautomator2-server-v11.6.1.apk} +0 -0
  52. 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
  53. package/node_modules/appium-uiautomator2-server/package.json +2 -2
  54. package/node_modules/string_decoder/package.json +4 -5
  55. package/package.json +3 -3
  56. package/build/lib/css/ui-automator-emitter.d.ts +0 -16
  57. package/build/lib/css/ui-automator-emitter.d.ts.map +0 -1
  58. package/build/lib/css/ui-automator-emitter.js +0 -115
  59. package/build/lib/css/ui-automator-emitter.js.map +0 -1
  60. package/lib/css/ui-automator-emitter.ts +0 -141
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [10.4.1](https://github.com/appium/appium-uiautomator2-driver/compare/v10.4.0...v10.4.1) (2026-11-27)
2
+
3
+ ### Miscellaneous Chores
4
+
5
+ * bump @appium/types to v3 ([#1097](https://github.com/appium/appium-uiautomator2-driver/issues/1097)) ([5eabba0](https://github.com/appium/appium-uiautomator2-driver/commit/5eabba036f4a02de429087cb7393d124f5e3fa67))
6
+
7
+ ## [10.4.0](https://github.com/appium/appium-uiautomator2-driver/compare/v10.3.0...v10.4.0) (2026-11-25)
8
+
9
+ ### Features
10
+
11
+ * 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))
12
+
1
13
  ## [10.3.0](https://github.com/appium/appium-uiautomator2-driver/compare/v10.2.0...v10.3.0) (2026-11-24)
2
14
 
3
15
  ### 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 = 'new UiSelector().scrollable(true)';
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 uiautomator';
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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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,CAAC;AAMjE,8DAA8D;AAC9D,MAAM,OAAO,iBAAiB;IACnB,QAAQ,CAAS;IAE1B,YAAY,QAAgB;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,IAAI,CAAC,MAAsB,EAAE,GAA8B;QACzD,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACzC,CAAC;IAED,uGAAuG;IAC7F,SAAS,CACjB,IAAgB,EAChB,GAA8B;QAE9B,MAAM,EAAC,IAAI,EAAE,UAAU,EAAE,eAAe,EAAC,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC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AK,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,UAAU,CAAC,CAAC;QACnF,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC;IAC1D,CAAC;CACF;AAED,iGAAiG;AACjG,MAAM,UAAU,eAAe,CAAC,MAAsB;IACpD,MAAM,EAAC,IAAI,EAAC,GAAG,MAAM,CAAC;IACtB,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;AAChH,CAAC;AAED,wGAAwG;AACxG,SAAS,KAAK,CAAC,KAAa;IAC1B,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC;AACtE,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO,2BAA2B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,sBAAsB,CAAC;AAClF,CAAC"}
@@ -1,5 +1,9 @@
1
- /** Locator strategy name used for UiAutomator queries. */
2
- export declare const UI_AUTOMATOR_STRATEGY = "-android uiautomator";
3
- /** Registry key for the UiAutomator CSS emitter. */
4
- export declare const UI_AUTOMATOR_EMITTER_KEY = "uiautomator";
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,qBAAqB,yBAAyB,CAAC;AAE5D,oDAAoD;AACpD,eAAO,MAAM,wBAAwB,gBAAgB,CAAC"}
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 UiAutomator queries. */
2
- export const UI_AUTOMATOR_STRATEGY = '-android uiautomator';
3
- /** Registry key for the UiAutomator CSS emitter. */
4
- export const UI_AUTOMATOR_EMITTER_KEY = 'uiautomator';
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,qBAAqB,GAAG,sBAAsB,CAAC;AAE5D,oDAAoD;AACpD,MAAM,CAAC,MAAM,wBAAwB,GAAG,aAAa,CAAC"}
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"}
@@ -1,5 +1,5 @@
1
1
  import type { NativeLocator } from '@appium/css-locator-to-native';
2
- export { UI_AUTOMATOR_STRATEGY } from './constants.js';
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,qBAAqB,EAAC,MAAM,gBAAgB,CAAC;AAiBrD;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,CAOxG"}
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"}
@@ -1,19 +1,20 @@
1
1
  import { errors } from 'appium/driver.js';
2
2
  import { util } from 'appium/support.js';
3
- import { UI_AUTOMATOR_EMITTER_KEY, UI_AUTOMATOR_STRATEGY } from './constants.js';
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
- import { UiAutomatorEmitter } from './ui-automator-emitter.js';
6
- export { UI_AUTOMATOR_STRATEGY } from './constants.js';
6
+ export { CLASS_CHAIN_STRATEGY, PREDICATE_STRATEGY } from './constants.js';
7
7
  const emitters = {
8
- [UI_AUTOMATOR_EMITTER_KEY]: new UiAutomatorEmitter(UI_AUTOMATOR_STRATEGY),
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 UI_AUTOMATOR_EMITTER_KEY;
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,wBAAwB,EAAE,qBAAqB,EAAC,MAAM,gBAAgB,CA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_SCROLLABLE_SEL = /\/\/\*\[@scrollable ?= ?('|")true\1\]/;
13
- const MAGIC_SCROLLABLE_BY = 'new UiSelector().scrollable(true)';
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 uiautomator';
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
+ }
@@ -1,5 +1,11 @@
1
- /** Locator strategy name used for UiAutomator queries. */
2
- export const UI_AUTOMATOR_STRATEGY = '-android uiautomator';
1
+ /** Locator strategy name used for class chain queries. */
2
+ export const CLASS_CHAIN_STRATEGY = '-android class chain';
3
3
 
4
- /** Registry key for the UiAutomator CSS emitter. */
5
- export const UI_AUTOMATOR_EMITTER_KEY = 'uiautomator';
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 {UI_AUTOMATOR_EMITTER_KEY, UI_AUTOMATOR_STRATEGY} from './constants.js';
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 {UI_AUTOMATOR_STRATEGY} from './constants.js';
9
+ export {CLASS_CHAIN_STRATEGY, PREDICATE_STRATEGY} from './constants.js';
10
10
 
11
11
  const emitters = {
12
- [UI_AUTOMATOR_EMITTER_KEY]: new UiAutomatorEmitter(UI_AUTOMATOR_STRATEGY),
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 UI_AUTOMATOR_EMITTER_KEY;
21
+ resolveStrategy(parsed): StrategyKey<typeof emitters> {
22
+ return needsClassChain(parsed) ? CLASS_CHAIN_EMITTER_KEY : PREDICATE_EMITTER_KEY;
22
23
  },
23
24
  });
24
25
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@appium/base-driver",
3
- "version": "11.0.1",
4
- "gitHead": "e72b4765eb4c400989728a02059075604dadceef",
3
+ "version": "11.0.2",
4
+ "gitHead": "19b5d082d57bad563511d5120ef7fd8da63788b3",
5
5
  "description": "Base driver class for Appium drivers",
6
6
  "keywords": [
7
7
  "android",
@@ -53,8 +53,8 @@
53
53
  "test:types": "tsd"
54
54
  },
55
55
  "dependencies": {
56
- "@appium/support": "^8.0.1",
57
- "@appium/types": "~2.0.0",
56
+ "@appium/support": "^8.0.2",
57
+ "@appium/types": "^3.0.0",
58
58
  "asyncbox": "^7.0.0",
59
59
  "axios": "^1.20.0",
60
60
  "lru-cache": "^11.5.2",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@appium/support",
3
- "version": "8.0.1",
4
- "gitHead": "e72b4765eb4c400989728a02059075604dadceef",
3
+ "version": "8.0.2",
4
+ "gitHead": "19b5d082d57bad563511d5120ef7fd8da63788b3",
5
5
  "description": "Support libs used across Appium packages",
6
6
  "keywords": [
7
7
  "android",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@appium/logger": "~3.0.0",
56
- "@appium/types": "~2.0.0",
56
+ "@appium/types": "^3.0.0",
57
57
  "archiver": "^8.0.0",
58
58
  "asyncbox": "^7.0.0",
59
59
  "axios": "^1.20.0",