(helper, el, value)
| 137 | } |
| 138 | |
| 139 | export async function fillRichEditor(helper, el, value) { |
| 140 | const source = el instanceof WebElement ? el : new WebElement(el, helper) |
| 141 | const kind = await source.evaluate(detectAndMark, { marker: MARKER, kinds: EDITOR }) |
| 142 | if (kind === EDITOR.STANDARD) return false |
| 143 | if (kind === EDITOR.UNREACHABLE) { |
| 144 | throw new Error('fillField: cannot fill a display:none form control. Locator must point at the visible editor surface (a wrapper, iframe, or contenteditable).') |
| 145 | } |
| 146 | |
| 147 | const target = await findMarked(helper) |
| 148 | const delay = helper.options.pressKeyDelay |
| 149 | |
| 150 | if (kind === EDITOR.IFRAME) { |
| 151 | await target.inIframe(async body => { |
| 152 | const innerKind = await evaluateInFrame(helper, body, detectInsideFrame) |
| 153 | if (innerKind === EDITOR.HIDDEN_TEXTAREA) { |
| 154 | const focused = await evaluateInFrame(helper, body, focusMarkedInFrameScript) |
| 155 | if (!focused) throw new Error('fillField: rich editor target inside iframe did not accept focus.') |
| 156 | await body.selectAllAndDelete() |
| 157 | await body.typeText(value, { delay }) |
| 158 | } else { |
| 159 | const focused = await evaluateInFrame(helper, body, selectAllInFrameScript) |
| 160 | if (!focused) throw new Error('fillField: rich editor target inside iframe did not accept focus.') |
| 161 | await body.typeText(value, { delay }) |
| 162 | } |
| 163 | }) |
| 164 | } else if (kind === EDITOR.HIDDEN_TEXTAREA) { |
| 165 | await target.focus() |
| 166 | await assertFocused(target) |
| 167 | await target.selectAllAndDelete() |
| 168 | await target.typeText(value, { delay }) |
| 169 | } else if (kind === EDITOR.CONTENTEDITABLE) { |
| 170 | await target.click() |
| 171 | await target.evaluate(selectAllInEditable) |
| 172 | await assertFocused(target) |
| 173 | await target.typeText(value, { delay }) |
| 174 | } |
| 175 | |
| 176 | await clearMarker(helper) |
| 177 | return true |
| 178 | } |
no test coverage detected