Skip to content

Commit 92b8d41

Browse files
committed
fix(provider-webdriver): decide a text entry class by its last name segment
The class match now reads the last segment of the class name, lowercased, as isFillableType does, so a package segment that happens to contain the word does not make a button a field.
1 parent 40df641 commit 92b8d41

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

‎packages/provider-webdriver/src/webdriver-source.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ test("Android WebDriver facts name a node by its text, carry a content descripti
6060
});
6161

6262
test('Android WebDriver facts read a hinted field as empty, a masked field as a password, and a disabled field as not editable', () => {
63-
const [hinted, secure, disabled] = parseWebDriverSourceFacts(
63+
const [hinted, secure, disabled, lookalike] = parseWebDriverSourceFacts(
6464
'<hierarchy>' +
6565
'<android.widget.EditText text="Your name" hint="Your name" bounds="[0,40][100,80]" />' +
6666
'<android.widget.EditText text="••••••" password="true" bounds="[0,80][100,120]" />' +
6767
'<android.widget.EditText text="locked" enabled="false" bounds="[0,120][100,160]" />' +
68+
'<com.edittext.sample.CustomButton text="Go" bounds="[0,160][100,200]" />' +
6869
'</hierarchy>',
6970
'android',
7071
).nodes;
@@ -76,6 +77,11 @@ test('Android WebDriver facts read a hinted field as empty, a masked field as a
7677
);
7778
assert.deepEqual([secure!.password, secure!.editable], [true, true]);
7879
assert.deepEqual([disabled!.value, disabled!.editable], ['locked', false]);
80+
// Only the class name's last segment decides, as `isFillableType` reads it.
81+
assert.deepEqual(
82+
[lookalike!.label, lookalike!.value, 'editable' in lookalike!],
83+
['Go', undefined, false],
84+
);
7985
});
8086

8187
// UiAutomator2 writes `checkable="false" checked="false"` on every node, so `checked` is a fact

‎packages/provider-webdriver/src/webdriver-source.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,18 @@ function sourceNodeFromAttributes(
180180
}
181181

182182
/**
183-
* The Android text entry classes, the same set `isFillableType` in
184-
* `@agent-device/contracts/snapshot-text` admits; that module is not a package subpath, so the
185-
* rule is restated here.
183+
* The Android text entry classes, the same rule `isFillableType` in
184+
* `@agent-device/contracts/snapshot-text` applies to the class name's last segment; that module is
185+
* not a package subpath, so the rule is restated here.
186186
*/
187-
const ANDROID_TEXT_FIELD_CLASS = /(edittext|autocompletetextview)/i;
187+
const ANDROID_TEXT_FIELD_CLASS = /edittext|autocompletetextview/;
188+
189+
/** The class name's last segment, lowercased, as `normalizeType` reads a type. */
190+
function classNameSegment(className: string): string {
191+
return className
192+
.slice(Math.max(className.lastIndexOf('.'), className.lastIndexOf('/')) + 1)
193+
.toLowerCase();
194+
}
188195

189196
/**
190197
* How a node is named. An Android node is labelled by its text and falls back to the content
@@ -239,7 +246,9 @@ function androidTextFieldFacts(
239246
attrs: Record<string, string>,
240247
): TextFieldFacts | undefined {
241248
const password = parseWebDriverBoolean(attrs.password);
242-
if (!ANDROID_TEXT_FIELD_CLASS.test(attrs.class ?? type) && password !== true) return undefined;
249+
if (!ANDROID_TEXT_FIELD_CLASS.test(classNameSegment(attrs.class ?? type)) && password !== true) {
250+
return undefined;
251+
}
243252
const placeholder = nonEmptyWebDriverAttribute(attrs.hint);
244253
const text = nonEmptyWebDriverAttribute(attrs.text);
245254
const hintShowing = placeholder !== undefined && text === placeholder;

0 commit comments

Comments
 (0)