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

Method fillField

lib/helper/Puppeteer.js:1587–1612  ·  view source on GitHub ↗

* {{> fillField }}

(field, value, context = null)

Source from the content-addressed store, hash-verified

1585 * {{> fillField }}
1586 */
1587 async fillField(field, value, context = null) {
1588 let els = await findVisibleFields.call(this, field, context)
1589 if (!els.length) {
1590 els = await findFields.call(this, field, context)
1591 }
1592 assertElementExists(els, field, 'Field')
1593 const el = selectElement(els, field, this)
1594
1595 if (await fillRichEditor(this, el, value)) {
1596 highlightActiveElement.call(this, el, await this._getContext())
1597 return this._waitForAction()
1598 }
1599
1600 const tag = await el.getProperty('tagName').then(el => el.jsonValue())
1601 const editable = await el.getProperty('contenteditable').then(el => el.jsonValue())
1602 if (tag === 'INPUT' || tag === 'TEXTAREA') {
1603 await this._evaluateHandeInContext(el => (el.value = ''), el)
1604 } else if (editable) {
1605 await this._evaluateHandeInContext(el => (el.innerHTML = ''), el)
1606 }
1607
1608 highlightActiveElement.call(this, el, await this._getContext())
1609 await el.type(value.toString(), { delay: this.options.pressKeyDelay })
1610
1611 return this._waitForAction()
1612 }
1613
1614 /**
1615 * {{> clearField }}

Callers 1

clearFieldMethod · 0.95

Calls 9

_getContextMethod · 0.95
_waitForActionMethod · 0.95
selectElementFunction · 0.90
fillRichEditorFunction · 0.90
getPropertyMethod · 0.80
assertElementExistsFunction · 0.70
typeMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected