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

Function proceedSeeInField

lib/helper/Puppeteer.js:3319–3376  ·  view source on GitHub ↗
(assertType, field, value, context)

Source from the content-addressed store, hash-verified

3317}
3318
3319async function proceedSeeInField(assertType, field, value, context) {
3320 const els = await findVisibleFields.call(this, field, context)
3321 assertElementExists(els, field, 'Field')
3322 const el = els[0]
3323 const tag = await el.getProperty('tagName').then(el => el.jsonValue())
3324 const fieldType = await el.getProperty('type').then(el => el.jsonValue())
3325
3326 const proceedMultiple = async elements => {
3327 const fields = Array.isArray(elements) ? elements : [elements]
3328
3329 const elementValues = []
3330 for (const element of fields) {
3331 elementValues.push(await element.getProperty('value').then(el => el.jsonValue()))
3332 }
3333
3334 if (typeof value === 'boolean') {
3335 equals(`no. of items matching > 0: ${field}`)[assertType](value, !!elementValues.length)
3336 } else {
3337 if (assertType === 'assert') {
3338 equals(`select option by ${field}`)[assertType](true, elementValues.length > 0)
3339 }
3340 elementValues.forEach(val => stringIncludes(`fields by ${field}`)[assertType](value, val))
3341 }
3342 }
3343
3344 if (tag === 'SELECT') {
3345 const selectedOptions = await el.$$('option:checked')
3346 // locate option by values and check them
3347 if (value === '') {
3348 return proceedMultiple(selectedOptions)
3349 }
3350
3351 const options = await filterFieldsByValue(selectedOptions, value, true)
3352 return proceedMultiple(options)
3353 }
3354
3355 if (tag === 'INPUT') {
3356 if (fieldType === 'checkbox' || fieldType === 'radio') {
3357 if (typeof value === 'boolean') {
3358 // Filter by values
3359 const options = await filterFieldsBySelectionState(els, true)
3360 return proceedMultiple(options)
3361 }
3362
3363 const options = await filterFieldsByValue(els, value, true)
3364 return proceedMultiple(options)
3365 }
3366 return proceedMultiple(els[0])
3367 }
3368
3369 let fieldVal = await el.getProperty('value').then(el => el.jsonValue())
3370
3371 if (fieldVal === undefined || fieldVal === null) {
3372 fieldVal = await el.evaluate(el => el.textContent || el.innerText)
3373 }
3374
3375 return stringIncludes(`fields by ${field}`)[assertType](value, fieldVal)
3376}

Callers

nothing calls this directly

Calls 7

getPropertyMethod · 0.80
$$Method · 0.80
evaluateMethod · 0.80
assertElementExistsFunction · 0.70
proceedMultipleFunction · 0.70
filterFieldsByValueFunction · 0.70

Tested by

no test coverage detected