Skip to content

Commit c8d3888

Browse files
test(webdriver): tighten fill replacement review coverage
1 parent 3c24574 commit c8d3888

6 files changed

Lines changed: 38 additions & 15 deletions

File tree

‎packages/contracts/src/interactor-types.ts‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,19 @@ export type TypeTextBackendResult = {
142142
};
143143

144144
/**
145-
* What a cloud `fill` could establish about its target taking text entry focus
146-
* before it sent the keys (#1658). The local Apple runner owns this discipline
147-
* in Swift and reports it as a `textEntryRoute`; a cloud session has no runner,
145+
* Focus evidence reported by a cloud `fill` before clearing or typing (#1658).
146+
* The local Apple runner owns this discipline in Swift and reports it as a
147+
* `textEntryRoute`; a cloud session has no runner,
148148
* only what its provider will tell it, so it names what it observed instead of
149149
* which channel it typed through. Listed strongest evidence first:
150150
*
151151
* - `focused-element`: after the tap, the element holding text-entry focus is the
152152
* one this fill aimed at — positive evidence that THIS field, not merely some
153153
* field, took focus. A field that focusing re-laid out still counts.
154-
* - `keyboard-shown`: no active-element route, but the software keyboard went
155-
* from hidden to shown after our tap. Witnesses that focus arrived somewhere,
156-
* which only means our field when the keyboard was down beforehand.
157-
* Every value describes a fill that sent its keys AND witnessed focus first.
154+
* - `keyboard-shown`: legacy WebDriver evidence that the software keyboard went
155+
* from hidden to shown after the tap. Retained for released provider results;
156+
* current WebDriver fills require a focused element reference and do not emit it.
157+
* Current cloud fills report `focused-element`, including clear-only fills.
158158
* There is deliberately no value for "typed without evidence": nothing renders
159159
* this field, so such a value would reach a caller as an ordinary success and
160160
* recreate the #1658 silent false success it exists to remove. Every
@@ -167,9 +167,8 @@ export type TypeTextBackendResult = {
167167
* wait could establish anything. `press` + `type` remains the deliberate way
168168
* to enter text unwitnessed.
169169
*
170-
* Closed set: the two cloud interactors are its only producers and the boundary
171-
* that narrows it (readFillBackendResult in the touch handler) drops a value it
172-
* cannot name.
170+
* Closed set accepted by readFillBackendResult at the touch boundary. It keeps
171+
* the legacy result readable and drops values it cannot name.
173172
*/
174173
export const CLOUD_TEXT_ENTRY_READINESS = ['focused-element', 'keyboard-shown'] as const;
175174

‎packages/daemon/src/core/fill-backend-result.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ import { test } from 'vitest';
22
import assert from 'node:assert/strict';
33
import { readFillBackendResult } from './fill-backend-result.ts';
44

5+
test('readFillBackendResult preserves released keyboard-shown readiness', () => {
6+
assert.deepEqual(readFillBackendResult({ textEntryReadiness: 'keyboard-shown' }), {
7+
textEntryReadiness: 'keyboard-shown',
8+
});
9+
});
10+
11+
test('readFillBackendResult drops an unknown readiness value', () => {
12+
assert.deepEqual(readFillBackendResult({ textEntryReadiness: 'keyboard-visible' }), {});
13+
});
14+
515
test('readFillBackendResult preserves a complete unconfirmed verification', () => {
616
assert.deepEqual(
717
readFillBackendResult({

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ for (const operation of ['clear', 'replace'] as const) {
419419
operation === 'clear'
420420
? client.clearElement('field')
421421
: client.sendElementKeys('field', 'replacement'),
422+
/provider unavailable/,
422423
);
423424
assert.equal(calls, 1);
424425
});

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ test('fill withholds keys until the tapped point holds text-entry focus', async
1818
world.activeRects = ['none', 'none', CONTAINS_TAP];
1919

2020
const result = await runFill(world);
21-
2221
assert.equal(result?.textEntryReadiness, 'focused-element');
22+
assert.deepEqual(vi.mocked(world.client.clearElement).mock.calls, [['tapped']]);
23+
assert.deepEqual(vi.mocked(world.client.sendElementKeys).mock.calls, [
24+
['tapped', '[email protected]'],
25+
]);
2326
assert.deepEqual(world.transcript, [
2427
'keyboard',
2528
'active',
@@ -440,12 +443,12 @@ function createTextEntryWorld() {
440443
world.tapped = true;
441444
},
442445
releaseActions: async () => {},
443-
clearElement: async () => {
446+
clearElement: vi.fn(async () => {
444447
world.transcript.push('clear');
445-
},
446-
sendElementKeys: async () => {
448+
}),
449+
sendElementKeys: vi.fn(async () => {
447450
world.transcript.push('keys');
448-
},
451+
}),
449452
activeElementReference: (timeoutMs?: number) =>
450453
world.client
451454
.activeElement(timeoutMs)

‎test/integration/provider-scenarios/cloud-webdriver-ios-text-entry.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ test('cloud iOS fill sends no replacement and does not retry a rejected clear',
319319
);
320320

321321
assert.ok(response.json.error);
322+
assert.equal(response.json.error.data?.code, 'COMMAND_FAILED');
323+
assert.equal(response.json.error.data?.details?.status, 503);
324+
assert.match(response.json.error.message ?? '', /clear rejected/);
322325
assert.equal(server.fieldValues.email, 'old-value');
323326
assert.equal(textEntryTranscript(server).filter((step) => step === 'clear').length, 1);
324327
assert.equal(textEntryTranscript(server).includes('keys'), false);

‎test/integration/provider-scenarios/cloud-webdriver-runtime.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,13 @@ function assertWebDriverCalls(calls: readonly CloudWebDriverHttpCall[], leaseId:
489489
]) {
490490
assert.ok(paths.includes(expected), `missing WebDriver transcript call: ${expected}`);
491491
}
492+
const clearIndex = paths.indexOf('POST /wd/hub/session/wd-1/element/focused-field/clear');
493+
const valueIndex = paths.indexOf('POST /wd/hub/session/wd-1/element/focused-field/value');
494+
assert.ok(clearIndex < valueIndex);
495+
assert.deepEqual(calls[valueIndex]?.body, {
496+
text: 'hello cloud',
497+
value: Array.from('hello cloud'),
498+
});
492499
const create = calls.find((call) => call.path === '/wd/hub/session');
493500
assert.deepEqual(create?.body, {
494501
capabilities: {

0 commit comments

Comments
 (0)