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

Method seeAttributesOnElements

lib/helper/Playwright.js:2842–2867  ·  view source on GitHub ↗

* {{> seeAttributesOnElements }} *

(locator, attributes)

Source from the content-addressed store, hash-verified

2840 *
2841 */
2842 async seeAttributesOnElements(locator, attributes) {
2843 const res = await this._locate(locator)
2844 assertElementExists(res, locator)
2845
2846 const elemAmount = res.length
2847 const commands = []
2848 res.forEach(el => {
2849 Object.keys(attributes).forEach(prop => {
2850 commands.push(el.evaluate((el, attr) => el[attr] || el.getAttribute(attr), prop))
2851 })
2852 })
2853 let attrs = await Promise.all(commands)
2854 const values = Object.keys(attributes).map(key => attributes[key])
2855 if (!Array.isArray(attrs)) attrs = [attrs]
2856 let chunked = chunkArray(attrs, values.length)
2857 chunked = chunked.filter(val => {
2858 for (let i = 0; i < val.length; ++i) {
2859 // the attribute could be a boolean
2860 if (typeof val[i] === 'boolean') return val[i] === values[i]
2861 // if the attribute doesn't exist, returns false as well
2862 if (!val[i] || !val[i].includes(values[i])) return false
2863 }
2864 return true
2865 })
2866 return equals(`all elements (${new Locator(locator)}) to have attributes ${JSON.stringify(attributes)}`).assert(chunked.length, elemAmount)
2867 }
2868
2869 /**
2870 * {{> dragSlider }}

Callers

nothing calls this directly

Calls 10

_locateMethod · 0.95
chunkArrayFunction · 0.90
equalsFunction · 0.90
pushMethod · 0.80
evaluateMethod · 0.80
getAttributeMethod · 0.80
filterMethod · 0.80
includesMethod · 0.80
assertMethod · 0.80
assertElementExistsFunction · 0.70

Tested by

no test coverage detected