* Verifies that all CSS elements are as expected before taking a snapshot. * * @param {!puppeteer.Page} page a Puppeteer control browser tab/page. * @param {string} testName the full name of the test. * @param {!Array } selectors Array of CSS selectors that must * eventually appear o
( page, testName, selectors, timeoutMillis = CSS_SELECTOR_TIMEOUT_MS )
| 60 | * @throws {Error} an encountered error. |
| 61 | */ |
| 62 | async function verifySelectorsVisible( |
| 63 | page, |
| 64 | testName, |
| 65 | selectors, |
| 66 | timeoutMillis = CSS_SELECTOR_TIMEOUT_MS |
| 67 | ) { |
| 68 | log('verbose', 'Waiting for existence of all:', cyan(selectors.join(', '))); |
| 69 | try { |
| 70 | await Promise.all( |
| 71 | selectors.map((selector) => |
| 72 | waitForSelectorExistence(page, selector, timeoutMillis) |
| 73 | ) |
| 74 | ); |
| 75 | } catch (e) { |
| 76 | throw new Error( |
| 77 | `${cyan(testName)} | The CSS selector ` + |
| 78 | `${cyan(e.message)} does not match any elements in the page` |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | log('verbose', 'Waiting for visibility of all:', cyan(selectors.join(', '))); |
| 83 | try { |
| 84 | await Promise.all( |
| 85 | selectors.map((selector) => |
| 86 | waitForElementVisibility(page, selector, {visible: true}, timeoutMillis) |
| 87 | ) |
| 88 | ); |
| 89 | } catch (e) { |
| 90 | throw new Error( |
| 91 | `${cyan(testName)} | An element with the CSS ` + |
| 92 | `selector ${cyan(e.message)} is still invisible after ` + |
| 93 | `${CSS_SELECTOR_TIMEOUT_MS} ms` |
| 94 | ); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Wait for all AMP loader indicators to disappear. |
no test coverage detected