Skip to content

Commit 3a5823d

Browse files
Liviu RauDevtools-frontend LUCI CQ
authored andcommitted
Highlight selected elements when debugging e2e tests
As we step though the e2e test actions all elements select with `$` function in frontend will get a red border. When selecting the next element we make sure that we reset the aspect of the previous one. Bug: 407460244 Change-Id: I7bb8b2a6653584f1c34a151ff01f47280abfbe80 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6429836 Reviewed-by: Eric Leese <[email protected]> Commit-Queue: Liviu Rau <[email protected]>
1 parent 61fbc23 commit 3a5823d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/e2e_non_hosted/shared/frontend-helper.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type * as puppeteer from 'puppeteer-core';
66

77
import {AsyncScope} from '../../conductor/async-scope.js';
88
import {installPageErrorHandlers} from '../../conductor/events.js';
9+
import {TestConfig} from '../../conductor/test_config.js';
910

1011
import {PageWrapper} from './page-wrapper.js';
1112

@@ -26,6 +27,8 @@ type DeducedElementType<ElementType extends Element|null, Selector extends strin
2627
ElementType extends null ? puppeteer.NodeFor<Selector>: ElementType;
2728

2829
export class DevToolsPage extends PageWrapper {
30+
#currentHighlightedElement?: HighlightedElement;
31+
2932
async setExperimentEnabled(experiment: string, enabled: boolean) {
3033
await this.evaluate(`(async () => {
3134
const Root = await import('./core/root/root.js');
@@ -112,9 +115,24 @@ export class DevToolsPage extends PageWrapper {
112115
const rootElement = root ? root : this.page;
113116
const element = await rootElement.$(`${handler}/${selector}`) as
114117
puppeteer.ElementHandle<DeducedElementType<ElementType, Selector>>;
118+
await this.#maybeHighlight(element);
115119
return element;
116120
}
117121

122+
async #maybeHighlight(element: puppeteer.ElementHandle) {
123+
if (!TestConfig.debug) {
124+
return;
125+
}
126+
if (!element) {
127+
return;
128+
}
129+
if (this.#currentHighlightedElement) {
130+
await this.#currentHighlightedElement.reset();
131+
}
132+
this.#currentHighlightedElement = new HighlightedElement(element);
133+
await this.#currentHighlightedElement.highlight();
134+
}
135+
118136
async performActionOnSelector(selector: string, options: {root?: puppeteer.ElementHandle}, action: Action):
119137
Promise<puppeteer.ElementHandle> {
120138
// TODO(crbug.com/1410168): we should refactor waitFor to be compatible with
@@ -296,3 +314,24 @@ export async function setupDevToolsPage(context: puppeteer.BrowserContext, setti
296314
await devToolsPage.setDockingSide(settings.dockingMode);
297315
return devToolsPage;
298316
}
317+
318+
class HighlightedElement {
319+
constructor(readonly element: puppeteer.ElementHandle) {
320+
}
321+
322+
async reset() {
323+
await this.element.evaluate(el => {
324+
if (el instanceof HTMLElement) {
325+
el.style.outline = '';
326+
}
327+
});
328+
}
329+
330+
async highlight() {
331+
await this.element.evaluate(el => {
332+
if (el instanceof HTMLElement) {
333+
el.style.outline = '2px solid red';
334+
}
335+
});
336+
}
337+
}

0 commit comments

Comments
 (0)