MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / waitForValue

Method waitForValue

lib/helper/Playwright.js:3216–3240  ·  view source on GitHub ↗

* {{> waitForValue }}

(field, value, sec)

Source from the content-addressed store, hash-verified

3214 * {{> waitForValue }}
3215 */
3216 async waitForValue(field, value, sec) {
3217 const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout
3218 const locator = new Locator(field, 'css')
3219 const matcher = await this.context
3220 let waiter
3221 const context = await this._getContext()
3222 if (!locator.isXPath()) {
3223 const valueFn = function ([locator, value]) {
3224 return Array.from(document.querySelectorAll(locator)).filter(el => (el.value || '').indexOf(value) !== -1).length > 0
3225 }
3226 waiter = context.waitForFunction(valueFn, [locator.value, value], { timeout: waitTimeout })
3227 } else {
3228 const valueFn = function ([locator, $XPath, value]) {
3229 eval($XPath)
3230 return $XPath(null, locator).filter(el => (el.value || '').indexOf(value) !== -1).length > 0
3231 }
3232 waiter = context.waitForFunction(valueFn, [locator.value, $XPath.toString(), value], {
3233 timeout: waitTimeout,
3234 })
3235 }
3236 return waiter.catch(err => {
3237 const loc = locator.toString()
3238 throw new Error(`element (${loc}) is not in DOM or there is no element(${loc}) with value "${value}" after ${waitTimeout / 1000} sec\n${err.message}`)
3239 })
3240 }
3241
3242 /**
3243 * {{> waitNumberOfVisibleElements }}

Callers

nothing calls this directly

Calls 5

_getContextMethod · 0.95
isXPathMethod · 0.95
toStringMethod · 0.95
waitForFunctionMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected