* Mimic Array.filter() API, but with an async callback function. * Execute each callback on each array item serially. Useful when using WebDriver API. * * Added due because of problem with chrome driver when too many requests * are made simultaneously. https://bugs.chromium.org/p/chromedriver/is
(array, callback)
| 3023 | * @return {Promise<Array>} - Array of values. |
| 3024 | */ |
| 3025 | async function filterAsync(array, callback) { |
| 3026 | const inputArray = Array.isArray(array) ? array : [array] |
| 3027 | const values = [] |
| 3028 | for (let index = 0; index < inputArray.length; index++) { |
| 3029 | const res = await callback(inputArray[index], index, inputArray) |
| 3030 | const value = Array.isArray(res) ? res[0] : res |
| 3031 | |
| 3032 | if (value) { |
| 3033 | values.push(inputArray[index]) |
| 3034 | } |
| 3035 | } |
| 3036 | return values |
| 3037 | } |
| 3038 | |
| 3039 | async function findClickable(locator, locateFn) { |
| 3040 | locator = new Locator(locator) |
no test coverage detected