From 3be2087f9d9ed107f4e46d5cdcda51f9fea9214d Mon Sep 17 00:00:00 2001 From: Johan Bay Date: Wed, 5 Aug 2020 06:24:30 +0000 Subject: [PATCH] Eliminate initial timeout in waitForFunction Bug: 1112692 Change-Id: I28bc29b0f5c2af55d3cf54614fe4d6641b64dd76 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2336716 Reviewed-by: Mathias Bynens Reviewed-by: Jack Franklin Reviewed-by: Changhao Han Commit-Queue: Changhao Han Commit-Queue: Mathias Bynens --- test/e2e/console/console-eval-fake_test.ts | 5 +++++ test/e2e/cross_tool_integration/browser_test.ts | 6 +++++- test/e2e/elements/style-pane-properties_test.ts | 8 +++++++- test/e2e/helpers/console-helpers.ts | 5 ++++- test/e2e/helpers/elements-helpers.ts | 5 ++++- test/e2e/helpers/memory-helpers.ts | 11 ++++++----- test/e2e/helpers/sources-helpers.ts | 16 +++++++++++++--- test/e2e/layers/layers_test.ts | 6 +++++- test/e2e/memory/memory_test.ts | 4 ++++ test/e2e/sources/can-show-wasm-scopes_test.ts | 4 ++-- test/shared/helper.ts | 8 +++----- 11 files changed, 58 insertions(+), 20 deletions(-) diff --git a/test/e2e/console/console-eval-fake_test.ts b/test/e2e/console/console-eval-fake_test.ts index 897231a684..2620136f75 100644 --- a/test/e2e/console/console-eval-fake_test.ts +++ b/test/e2e/console/console-eval-fake_test.ts @@ -37,6 +37,11 @@ describe('The Console Tab', async () => { await frontend.keyboard.press('Enter'); }); + // Wait for the console to be usable again. + await frontend.waitForFunction(() => { + return document.querySelectorAll('.console-user-command-result').length === 2; + }); + await step('retrieve the console log', async () => { messages = await getCurrentConsoleMessages(); }); diff --git a/test/e2e/cross_tool_integration/browser_test.ts b/test/e2e/cross_tool_integration/browser_test.ts index 1a676ebf2f..0e9fd22669 100644 --- a/test/e2e/cross_tool_integration/browser_test.ts +++ b/test/e2e/cross_tool_integration/browser_test.ts @@ -5,7 +5,7 @@ import {assert} from 'chai'; import {describe, it} from 'mocha'; -import {closeAllCloseableTabs, getBrowserAndPages, goToResource} from '../../shared/helper.js'; +import {closeAllCloseableTabs, getBrowserAndPages, goToResource, timeout} from '../../shared/helper.js'; import {getCurrentConsoleMessages} from '../helpers/console-helpers.js'; import {openPanelViaMoreTools} from '../helpers/settings-helpers.js'; @@ -17,6 +17,8 @@ describe('Browser', async () => { // Open a few closeable panels await openPanelViaMoreTools('Animations'); + // FIXME(crbug/1112692): Refactor test to remove the timeout. + await timeout(100); await openPanelViaMoreTools('Rendering'); const messages = await getCurrentConsoleMessages(); @@ -37,6 +39,8 @@ describe('Browser', async () => { // Open a few closeable panels await openPanelViaMoreTools('Animations'); + // FIXME(crbug/1112692): Refactor test to remove the timeout. + await timeout(100); await openPanelViaMoreTools('Rendering'); await closeAllCloseableTabs(); diff --git a/test/e2e/elements/style-pane-properties_test.ts b/test/e2e/elements/style-pane-properties_test.ts index ce1b4acf7a..c5c9d2f8b5 100644 --- a/test/e2e/elements/style-pane-properties_test.ts +++ b/test/e2e/elements/style-pane-properties_test.ts @@ -6,7 +6,7 @@ import {assert} from 'chai'; import {describe, it} from 'mocha'; import * as puppeteer from 'puppeteer'; -import {click, getBrowserAndPages, goToResource, waitFor} from '../../shared/helper.js'; +import {click, getBrowserAndPages, goToResource, timeout, waitFor} from '../../shared/helper.js'; import {assertContentOfSelectedElementsNode, getAriaLabelSelectorFromPropertiesSelector, getComputedStylesForDomNode, getCSSPropertySwatchStyle, getDisplayedCSSPropertyNames, getDisplayedStyleRules, getStyleSectionSubtitles, waitForElementsStyleSection, waitForStyleRule} from '../helpers/elements-helpers.js'; const PROPERTIES_TO_DELETE_SELECTOR = '#properties-to-delete'; @@ -32,6 +32,9 @@ describe('The Styles pane', async () => { await goToResource('elements/simple-styled-page.html'); await waitForElementsStyleSection(); + // FIXME(crbug/1112692): Refactor test to remove the timeout. + await timeout(100); + // Select the H1 element by pressing down, since is the default selected element. const onH1RuleAppeared = waitForStyleRule('h1'); await frontend.keyboard.press('ArrowDown'); @@ -126,6 +129,9 @@ describe('The Styles pane', async () => { await goToResource('elements/stylesheets-with-various-sources.html'); await waitForElementsStyleSection(); + // FIXME(crbug/1112692): Refactor test to remove the timeout. + await timeout(100); + // Select the div element by pressing down, since is the default selected element. const onDivRuleAppeared = waitForStyleRule('div'); await frontend.keyboard.press('ArrowDown'); diff --git a/test/e2e/helpers/console-helpers.ts b/test/e2e/helpers/console-helpers.ts index 2d7b1dfe66..8550d5864b 100644 --- a/test/e2e/helpers/console-helpers.ts +++ b/test/e2e/helpers/console-helpers.ts @@ -4,7 +4,7 @@ import * as puppeteer from 'puppeteer'; -import {$, click, getBrowserAndPages, goToResource, pasteText, waitFor} from '../../shared/helper.js'; +import {$, click, getBrowserAndPages, goToResource, pasteText, timeout, waitFor} from '../../shared/helper.js'; export const CONSOLE_TAB_SELECTOR = '#tab-console'; export const CONSOLE_MESSAGES_SELECTOR = '.console-group-messages'; @@ -74,6 +74,9 @@ export async function getCurrentConsoleMessages( const selector = withAnchor ? CONSOLE_MESSAGE_TEXT_AND_ANCHOR_SELECTOR : CONSOLE_FIRST_MESSAGES_SELECTOR; + // FIXME(crbug/1112692): Refactor test to remove the timeout. + await timeout(100); + // Get the messages from the console. return frontend.evaluate(selector => { return Array.from(document.querySelectorAll(selector)).map(message => message.textContent); diff --git a/test/e2e/helpers/elements-helpers.ts b/test/e2e/helpers/elements-helpers.ts index 6c4a85a467..c9a986b43e 100644 --- a/test/e2e/helpers/elements-helpers.ts +++ b/test/e2e/helpers/elements-helpers.ts @@ -138,7 +138,8 @@ export const forcePseudoState = async (pseudoState: string) => { // Open element state pane and wait for it to be loaded asynchronously await click('[aria-label="Toggle Element State"]'); await waitFor(`[aria-label="${pseudoState}"]`); - + // FIXME(crbug/1112692): Refactor test to remove the timeout. + await timeout(100); await click(`[aria-label="${pseudoState}"]`); }; @@ -283,5 +284,7 @@ export const navigateToElementsTab = async () => { export const clickOnFirstLinkInStylesPanel = async () => { const stylesPane = await waitFor('div.styles-pane'); + // FIXME(crbug/1112692): Refactor test to remove the timeout. + await timeout(100); await click('div.styles-section-subtitle span.devtools-link', {root: stylesPane}); }; diff --git a/test/e2e/helpers/memory-helpers.ts b/test/e2e/helpers/memory-helpers.ts index 3a482d4120..4a757883d5 100644 --- a/test/e2e/helpers/memory-helpers.ts +++ b/test/e2e/helpers/memory-helpers.ts @@ -2,9 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import {assert} from 'chai'; - -import {$$, click, goToResource, waitFor, waitForNone} from '../../shared/helper.js'; +import {$$, click, goToResource, waitFor, waitForFunction, waitForNone} from '../../shared/helper.js'; const NEW_HEAP_SNAPSHOT_BUTTON = 'button[aria-label="Take heap snapshot"]'; const MEMORY_PANEL_CONTENT = 'div[aria-label="Memory panel"]'; @@ -27,8 +25,11 @@ export async function takeHeapSnapshot() { export async function waitForHeapSnapshotData() { await waitFor('#profile-views'); await waitFor('#profile-views .data-grid'); - const rowCount = await getCountOfDataGridRows('#profile-views table.data'); - assert.notEqual(rowCount, 0); + const rowCountNotZero = async () => { + const rowCount = await getCountOfDataGridRows('#profile-views table.data'); + return rowCount !== 0; + }; + await waitForFunction(rowCountNotZero); } export async function getCountOfDataGridRows(selector: string) { diff --git a/test/e2e/helpers/sources-helpers.ts b/test/e2e/helpers/sources-helpers.ts index 8a9cf6161b..4435acf725 100644 --- a/test/e2e/helpers/sources-helpers.ts +++ b/test/e2e/helpers/sources-helpers.ts @@ -5,7 +5,7 @@ import {assert} from 'chai'; import * as puppeteer from 'puppeteer'; -import {$$, click, getBrowserAndPages, getHostedModeServerPort, goToResource, pressKey, step, typeText, waitFor} from '../../shared/helper.js'; +import {$$, click, getBrowserAndPages, getHostedModeServerPort, goToResource, pressKey, step, typeText, waitFor, waitForFunction} from '../../shared/helper.js'; export const PAUSE_ON_EXCEPTION_BUTTON = '[aria-label="Pause on exceptions"]'; export const PAUSE_BUTTON = '[aria-label="Pause script execution"]'; @@ -113,6 +113,10 @@ export async function sourceLineNumberSelector(lineNumber: number) { export async function checkBreakpointIsActive(lineNumber: number) { await step(`check that the breakpoint is still active at line ${lineNumber}`, async () => { + await waitForFunction(async () => { + const elements = await $$(SOURCES_LINES_SELECTOR); + return elements.length >= lineNumber; + }); const sourcesLines = await $$(SOURCES_LINES_SELECTOR); const codeLineNums = await Promise.all(sourcesLines.map(elements => { return elements.evaluate(el => el.className); @@ -310,7 +314,7 @@ export async function getScopeNames() { return scopeNames; } -export async function getValuesForScope(scope: string, expandCount = 0) { +export async function getValuesForScope(scope: string, expandCount = 0, waitForNoOfValues = 0) { const scopeSelector = `[aria-label="${scope}"]`; await waitFor(scopeSelector); for (let i = 0; i < expandCount; i++) { @@ -319,7 +323,13 @@ export async function getValuesForScope(scope: string, expandCount = 0) { await click(unexpandedSelector); } const valueSelector = `${scopeSelector} + ol .name-and-value`; - const valueSelectorElements = await $$(valueSelector); + const valueSelectorElements = await waitForFunction(async () => { + const elements = await $$(valueSelector); + if (elements.length >= waitForNoOfValues) { + return elements; + } + return undefined; + }); const values = await Promise.all(valueSelectorElements.map(elem => elem.evaluate(n => n.textContent as string))); return values; } diff --git a/test/e2e/layers/layers_test.ts b/test/e2e/layers/layers_test.ts index 01b362746d..13f052c120 100644 --- a/test/e2e/layers/layers_test.ts +++ b/test/e2e/layers/layers_test.ts @@ -5,7 +5,7 @@ import {assert} from 'chai'; import {describe, it} from 'mocha'; -import {getBrowserAndPages, getResourcesPath, goToResource, waitFor} from '../../shared/helper.js'; +import {getBrowserAndPages, getResourcesPath, goToResource, timeout, waitFor} from '../../shared/helper.js'; import {getCurrentUrl} from '../helpers/layers-helpers.js'; import {openPanelViaMoreTools} from '../helpers/settings-helpers.js'; @@ -17,6 +17,10 @@ describe('The Layers Panel', async () => { await openPanelViaMoreTools('Layers'); await waitFor('[aria-label="layers"]:not([test-current-url=""])'); + + // FIXME(crbug/1112692): Refactor test to remove the timeout. + await timeout(100); + const url = await getCurrentUrl(); assert.strictEqual(url, `${getResourcesPath()}/${targetUrl}`); }); diff --git a/test/e2e/memory/memory_test.ts b/test/e2e/memory/memory_test.ts index 44987c961e..b37a01b269 100644 --- a/test/e2e/memory/memory_test.ts +++ b/test/e2e/memory/memory_test.ts @@ -2,8 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import {assert} from 'chai'; import {describe, it} from 'mocha'; +import {$$} from '../../shared/helper.js'; import {navigateToMemoryTab, takeHeapSnapshot, waitForHeapSnapshotData} from '../helpers/memory-helpers.js'; describe('The Memory Panel', async () => { @@ -17,5 +19,7 @@ describe('The Memory Panel', async () => { await waitForHeapSnapshotData(); await takeHeapSnapshot(); await waitForHeapSnapshotData(); + const heapSnapShots = await $$('.heap-snapshot-sidebar-tree-item'); + assert.strictEqual(heapSnapShots.length, 2); }); }); diff --git a/test/e2e/sources/can-show-wasm-scopes_test.ts b/test/e2e/sources/can-show-wasm-scopes_test.ts index 75a7110e28..9ed76b3aed 100644 --- a/test/e2e/sources/can-show-wasm-scopes_test.ts +++ b/test/e2e/sources/can-show-wasm-scopes_test.ts @@ -66,12 +66,12 @@ describe('Source Tab', async () => { }); await step('check that the module scope content is as before', async () => { - const currentModuleScopeValues = await getValuesForScope('Module'); + const currentModuleScopeValues = await getValuesForScope('Module', 0, moduleScopeValues.length); assert.deepEqual(currentModuleScopeValues, moduleScopeValues); }); await step('check that the local scope content is as before', async () => { - const updatedLocalScopeValues = await getValuesForScope('Local'); + const updatedLocalScopeValues = await getValuesForScope('Local', 0, localScopeValues.length); assert.deepEqual(updatedLocalScopeValues, localScopeValues); }); diff --git a/test/shared/helper.ts b/test/shared/helper.ts index 5921e4ad00..94deae97cd 100644 --- a/test/shared/helper.ts +++ b/test/shared/helper.ts @@ -178,9 +178,6 @@ export const $textContent = async (textContent: string, root?: puppeteer.JSHandl const {frontend} = getBrowserAndPages(); const rootElement = root ? root as puppeteer.ElementHandle : frontend; const element = await rootElement.$('pierceShadowText/' + textContent); - if (!element) { - throw new Error(`Unable to find element with textContent ${textContent}`); - } return element; }; @@ -206,18 +203,19 @@ export const waitForNone = async (selector: string, root?: puppeteer.JSHandle, a export const waitForElementWithTextContent = (textContent: string, root?: puppeteer.JSHandle, asyncScope = new AsyncScope()) => { return asyncScope.exec(() => waitForFunction(async () => { - return await $textContent(textContent, root); + const elem = await $textContent(textContent, root); + return elem || undefined; }, asyncScope)); }; export const waitForFunction = async(fn: () => Promise, asyncScope = new AsyncScope()): Promise => { return await asyncScope.exec(async () => { while (true) { - await timeout(100); const result = await fn(); if (result) { return result; } + await timeout(100); } }); };