MCPcopy
hub / github.com/codeceptjs/CodeceptJS / fillRichEditor

Function fillRichEditor

lib/helper/extras/richTextEditor.js:139–178  ·  view source on GitHub ↗
(helper, el, value)

Source from the content-addressed store, hash-verified

137}
138
139export 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}

Callers 3

fillFieldMethod · 0.90
fillFieldMethod · 0.90
fillFieldMethod · 0.90

Calls 10

findMarkedFunction · 0.85
evaluateInFrameFunction · 0.85
assertFocusedFunction · 0.85
clearMarkerFunction · 0.85
evaluateMethod · 0.80
inIframeMethod · 0.80
selectAllAndDeleteMethod · 0.80
typeTextMethod · 0.80
focusMethod · 0.45
clickMethod · 0.45

Tested by

no test coverage detected