Skip to content

Commit 8f5f0c0

Browse files
committed
fix(provider-webdriver): keep a hinted field's value absent, gate editable on enabled
A hinted field's absent value fell through to the node's value attribute, and a text field read as editable whatever its enabled state. The fallback now applies only to nodes that are not text fields, and editable follows the reported enabled flag on both platforms. The hint-equals-value ambiguity the page source cannot resolve is documented at the helper.
1 parent 8903a75 commit 8f5f0c0

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ test("Android WebDriver facts read a text field's content as its value, not its
5252
);
5353
});
5454

55-
test('Android WebDriver facts read a hinted field as empty and a masked field as a password', () => {
56-
const [hinted, secure] = parseWebDriverSourceFacts(
55+
test('Android WebDriver facts read a hinted field as empty, a masked field as a password, and a disabled field as not editable', () => {
56+
const [hinted, secure, disabled] = parseWebDriverSourceFacts(
5757
'<hierarchy>' +
5858
'<android.widget.EditText text="Your name" hint="Your name" bounds="[0,40][100,80]" />' +
5959
'<android.widget.EditText text="••••••" password="true" bounds="[0,80][100,120]" />' +
60+
'<android.widget.EditText text="locked" enabled="false" bounds="[0,120][100,160]" />' +
6061
'</hierarchy>',
6162
'android',
6263
).nodes;
@@ -66,6 +67,7 @@ test('Android WebDriver facts read a hinted field as empty and a masked field as
6667
[undefined, undefined, 'Your name', true],
6768
);
6869
assert.deepEqual([secure!.password, secure!.editable], [true, true]);
70+
assert.deepEqual([disabled!.value, disabled!.editable], ['locked', false]);
6971
});
7072

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

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function sourceNodeFromAttributes(
174174
? ['content-desc', 'label', 'text', 'name']
175175
: ['content-desc', 'label', 'name'],
176176
),
177-
value: field?.value ?? nonEmptyWebDriverAttribute(attrs.value),
177+
value: field === undefined ? nonEmptyWebDriverAttribute(attrs.value) : field.value,
178178
identifier: firstWebDriverAttribute(attrs, ['resource-id', 'id', 'accessibility-id', 'name']),
179179
rect,
180180
...sourceStateFacts(attrs, rect, platform),
@@ -216,7 +216,12 @@ function textFieldFacts(
216216
: iosTextFieldFacts(type, attrs);
217217
}
218218

219-
/** A field showing its hint reports the hint as its text, so that text is the placeholder, not a value. */
219+
/**
220+
* A field showing its hint reports the hint as its text, so that text is the placeholder, not a
221+
* value. The page source offers no other signal, so a typed value equal to the hint reads as the
222+
* hint showing; the native helper's `hint-showing` fact has no counterpart here. A disabled field
223+
* is not editable, whatever its class.
224+
*/
220225
function androidTextFieldFacts(
221226
type: string,
222227
attrs: Record<string, string>,
@@ -229,7 +234,7 @@ function androidTextFieldFacts(
229234
return {
230235
value: hintShowing ? undefined : text,
231236
facts: {
232-
editable: true,
237+
editable: parseWebDriverBoolean(attrs.enabled, true) === true,
233238
...optionalFact('password', password),
234239
...(placeholder === undefined ? {} : { placeholder, hintShowing }),
235240
},
@@ -244,7 +249,7 @@ function iosTextFieldFacts(
244249
return {
245250
value: nonEmptyWebDriverAttribute(attrs.value),
246251
facts: {
247-
editable: true,
252+
editable: parseWebDriverBoolean(attrs.enabled, true) === true,
248253
...optionalFact('password', type === 'XCUIElementTypeSecureTextField' || undefined),
249254
},
250255
};

0 commit comments

Comments
 (0)