(id: string, initialValue: string)
| 36 | } |
| 37 | |
| 38 | async function installReactTrackedInput(id: string, initialValue: string): Promise<void> { |
| 39 | await browser.execute(({ inputId, value }) => { |
| 40 | let input = document.getElementById(inputId) as HTMLInputElement | null; |
| 41 | if (!input) { |
| 42 | input = document.createElement('input'); |
| 43 | input.id = inputId; |
| 44 | input.style.position = 'fixed'; |
| 45 | input.style.left = '24px'; |
| 46 | input.style.top = '196px'; |
| 47 | document.body.appendChild(input); |
| 48 | } |
| 49 | |
| 50 | const proto = Object.getPrototypeOf(input) as HTMLInputElement; |
| 51 | const descriptor = Object.getOwnPropertyDescriptor(proto, 'value'); |
| 52 | if (!descriptor?.get || !descriptor?.set) { |
| 53 | throw new Error('Missing native value descriptor'); |
| 54 | } |
| 55 | |
| 56 | const tracker = { currentValue: value, syntheticChanges: 0 }; |
| 57 | Object.defineProperty(input, 'value', { |
| 58 | configurable: true, |
| 59 | get() { |
| 60 | return descriptor.get!.call(this); |
| 61 | }, |
| 62 | set(next: string) { |
| 63 | tracker.currentValue = String(next); |
| 64 | descriptor.set!.call(this, next); |
| 65 | }, |
| 66 | }); |
| 67 | |
| 68 | descriptor.set.call(input, value); |
| 69 | input.focus(); |
| 70 | input.setSelectionRange(value.length, value.length); |
| 71 | (window as typeof window & { __wdReactTracker?: typeof tracker }).__wdReactTracker = tracker; |
| 72 | |
| 73 | input.oninput = () => { |
| 74 | const liveValue = descriptor.get!.call(input!); |
| 75 | if (liveValue !== tracker.currentValue) { |
| 76 | tracker.syntheticChanges += 1; |
| 77 | tracker.currentValue = liveValue; |
| 78 | } |
| 79 | }; |
| 80 | }, { inputId: id, value: initialValue }); |
| 81 | } |
| 82 | |
| 83 | describe('L0 Embedded WebDriver Protocol', () => { |
| 84 | it('supports alert lifecycle endpoints', async () => { |
no test coverage detected