* {{> seeAttributesOnElements }}
(locator, attributes)
| 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 }} |
no test coverage detected