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

Method seeAttributesOnElements

lib/helper/WebDriver.js:1791–1814  ·  view source on GitHub ↗

* {{> seeAttributesOnElements }}

(locator, attributes)

Source from the content-addressed store, hash-verified

1789 * {{> seeAttributesOnElements }}
1790 */
1791 async seeAttributesOnElements(locator, attributes) {
1792 const res = await this._locate(locator)
1793 assertElementExists(res, locator)
1794 const elemAmount = res.length
1795
1796 let attrs = await forEachAsync(res, async el => {
1797 return forEachAsync(Object.keys(attributes), async attr => el.getAttribute(attr))
1798 })
1799
1800 const values = Object.keys(attributes).map(key => attributes[key])
1801 if (!Array.isArray(attrs)) attrs = [attrs]
1802 let chunked = chunkArray(attrs, values.length)
1803 chunked = chunked.filter(val => {
1804 for (let i = 0; i < val.length; ++i) {
1805 const _actual = Number.isNaN(val[i]) || typeof values[i] === 'string' ? val[i] : Number.parseInt(val[i], 10)
1806 const _expected = Number.isNaN(values[i]) || typeof values[i] === 'string' ? values[i] : Number.parseInt(values[i], 10)
1807 // the attribute could be a boolean
1808 if (typeof _actual === 'boolean') return _actual === _expected
1809 if (_actual !== _expected) return false
1810 }
1811 return true
1812 })
1813 return assert.ok(chunked.length === elemAmount, `expected all elements (${new Locator(locator)}) to have attributes ${JSON.stringify(attributes)}`)
1814 }
1815
1816 /**
1817 * {{> grabNumberOfVisibleElements }}

Callers

nothing calls this directly

Calls 6

_locateMethod · 0.95
chunkArrayFunction · 0.90
forEachAsyncFunction · 0.85
getAttributeMethod · 0.80
filterMethod · 0.80
assertElementExistsFunction · 0.70

Tested by

no test coverage detected