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

Method seeAttributesOnElements

lib/helper/Puppeteer.js:2121–2153  ·  view source on GitHub ↗

* {{> seeAttributesOnElements }}

(locator, attributes)

Source from the content-addressed store, hash-verified

2119 * {{> seeAttributesOnElements }}
2120 */
2121 async seeAttributesOnElements(locator, attributes) {
2122 const elements = await this._locate(locator)
2123 assertElementExists(elements, locator)
2124
2125 const expectedAttributes = Object.entries(attributes)
2126
2127 const valuesPromises = elements.map(async element => {
2128 const elementAttributes = {}
2129 await Promise.all(
2130 expectedAttributes.map(async ([attribute, expectedValue]) => {
2131 const actualValue = await element.evaluate((el, attr) => el[attr] || el.getAttribute(attr), attribute)
2132 elementAttributes[attribute] = actualValue
2133 }),
2134 )
2135 return elementAttributes
2136 })
2137
2138 const actualAttributes = await Promise.all(valuesPromises)
2139
2140 const matchingElements = actualAttributes.filter(attrs =>
2141 expectedAttributes.every(([attribute, expectedValue]) => {
2142 const actualValue = attrs[attribute]
2143 if (!actualValue) return false
2144 if (actualValue.toString().match(new RegExp(expectedValue.toString()))) return true
2145 return expectedValue === actualValue
2146 }),
2147 )
2148
2149 const elementsCount = elements.length
2150 const matchingCount = matchingElements.length
2151
2152 return equals(`all elements (${new Locator(locator)}) to have attributes ${JSON.stringify(attributes)}`).assert(matchingCount, elementsCount)
2153 }
2154
2155 /**
2156 * {{> dragSlider }}

Callers 4

testsFunction · 0.45

Calls 9

_locateMethod · 0.95
equalsFunction · 0.90
entriesMethod · 0.80
evaluateMethod · 0.80
getAttributeMethod · 0.80
filterMethod · 0.80
assertMethod · 0.80
assertElementExistsFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected