Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add readiness checks to target page e2es before interacting with visualizations #1751

Merged
merged 2 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const TargetPageInjectedComponentSelectors = {
export const TabStopShadowDomSelectors = {
svg: 'svg',
lines: 'line',
ellipse: 'ellipse',
opaqueEllipse: 'ellipse:not([fill="transparent"])',
transparentEllipse: 'ellipse[fill="transparent"]',
text: 'text',
};
18 changes: 12 additions & 6 deletions src/tests/end-to-end/common/page-controllers/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,18 @@ export class Page {
});
}

public async getShadowRootOfSelector(selector: string): Promise<Puppeteer.ElementHandle<Element>> {
return await this.screenshotOnError(async () =>
(
await this.underlyingPage.evaluateHandle(selectorInEval => document.querySelector(selectorInEval).shadowRoot, selector)
).asElement(),
);
public async waitForShadowRootOfSelector(selector: string): Promise<Puppeteer.ElementHandle<Element>> {
return await this.screenshotOnError(async () => {
const shadowRootHandle = await this.underlyingPage.waitForFunction(
selectorInEval => {
const container = document.querySelector(selectorInEval);
return container == undefined ? undefined : container.shadowRoot;
},
{ timeout: DEFAULT_PAGE_ELEMENT_WAIT_TIMEOUT_MS },
selector,
);
return shadowRootHandle.asElement();
});
}

public async clickSelector(selector: string): Promise<void> {
Expand Down
21 changes: 17 additions & 4 deletions src/tests/end-to-end/common/page-controllers/target-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,25 @@ export class TargetPage extends Page {
super(underlyingPage, options);
}

public async getShadowRoot(): Promise<ElementHandle<Element>> {
return await this.getShadowRootOfSelector('#insights-shadow-host');
public async waitForSelectorInShadowRoot(
selector: string,
options?: Puppeteer.WaitForSelectorOptions,
): Promise<Puppeteer.JSHandle<any>> {
const shadowRoot = await this.waitForShadowRoot();
return this.waitForDescendentSelector(shadowRoot, selector, options);
}

public async getShadowRootHtmlSnapshot(): Promise<Node> {
const shadowRoot = await this.getShadowRoot();
public async clickSelectorInShadowRoot(selector: string): Promise<void> {
const shadowRoot = await this.waitForShadowRoot();
await this.clickDescendentSelector(shadowRoot, selector, { visible: true });
}

public async waitForShadowRoot(): Promise<ElementHandle<Element>> {
return await this.waitForShadowRootOfSelector('#insights-shadow-host');
}

public async waitForShadowRootHtmlSnapshot(): Promise<Node> {
const shadowRoot = await this.waitForShadowRoot();
return await formatChildElementForSnapshot(shadowRoot, '#insights-shadow-container');
}
}
2 changes: 1 addition & 1 deletion src/tests/end-to-end/tests/popup/adhoc-panel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('Popup -> Ad-hoc tools', () => {
await popupPage.enableToggleByAriaLabel(toggleAriaLabel);

await targetPage.bringToFront();
expect(await targetPage.getShadowRootHtmlSnapshot()).toMatchSnapshot();
expect(await targetPage.waitForShadowRootHtmlSnapshot()).toMatchSnapshot();
},
);
});
4 changes: 1 addition & 3 deletions src/tests/end-to-end/tests/target-page/issue-dialog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ describe('Target Page issue dialog', () => {

await targetPage.bringToFront();

const shadowRoot = await targetPage.getShadowRoot();
await targetPage.clickDescendentSelector(shadowRoot, TargetPageInjectedComponentSelectors.failureLabel, { visible: true });

await targetPage.clickSelectorInShadowRoot(TargetPageInjectedComponentSelectors.failureLabel);
await targetPage.waitForSelector(TargetPageInjectedComponentSelectors.issueDialog);

const results = await scanForAccessibilityIssues(targetPage, TargetPageInjectedComponentSelectors.issueDialog);
Expand Down
49 changes: 23 additions & 26 deletions src/tests/end-to-end/tests/target-page/tabstop.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { ElementHandle } from 'puppeteer';

import { Browser } from '../../common/browser';
import { launchBrowser } from '../../common/browser-factory';
import { TabStopShadowDomSelectors, TargetPageInjectedComponentSelectors } from '../../common/element-identifiers/target-page-selectors';
import { TabStopShadowDomSelectors } from '../../common/element-identifiers/target-page-selectors';
import { PopupPage } from '../../common/page-controllers/popup-page';
import { TargetPage } from '../../common/page-controllers/target-page';

describe('tabstop tests', () => {
describe('Tab stops visualization', () => {
let browser: Browser;
let targetPage: TargetPage;
let popupPage: PopupPage;
Expand All @@ -24,36 +22,35 @@ describe('tabstop tests', () => {
}
});

test('works when tabstop is triggered from adhoc panel', async () => {
it('should show the expected visuals in the target page after enabling from popup and tabbing through target page', async () => {
popupPage = await browser.newPopupPage(targetPage);
await popupPage.gotoAdhocPanel();
await popupPage.enableToggleByAriaLabel('Tab stops');

await targetPage.bringToFront();
await targetPage.waitForShadowRoot();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this.


// Should highlight first element with a transparent circle
await targetPage.keyPress('Tab');
await targetPage.waitForSelectorInShadowRoot(TabStopShadowDomSelectors.svg);
await targetPage.waitForSelectorInShadowRoot(TabStopShadowDomSelectors.transparentEllipse);

// Should highlight second element with a transparent circle and change first element's
// highlight to an opaque circle with a "1" in it, connected by a line
await targetPage.keyPress('Tab');
await targetPage.waitForSelectorInShadowRoot(TabStopShadowDomSelectors.svg);
await targetPage.waitForSelectorInShadowRoot(TabStopShadowDomSelectors.transparentEllipse);
await targetPage.waitForSelectorInShadowRoot(TabStopShadowDomSelectors.opaqueEllipse);
await targetPage.waitForSelectorInShadowRoot(TabStopShadowDomSelectors.lines);
await targetPage.waitForSelectorInShadowRoot(TabStopShadowDomSelectors.text);

// Only 2 focusable elements on this test page, so should move focus to the browser chrome
// without changing the visualizations
await targetPage.keyPress('Tab');

const shadowRoot = await targetPage.getShadowRoot();
await targetPage.waitForDescendentSelector(shadowRoot, TargetPageInjectedComponentSelectors.tabStopVisulizationStart, {
visible: true,
});

await validateTabStopVisualizationOnTargetPage(shadowRoot);
await targetPage.waitForSelectorInShadowRoot(TabStopShadowDomSelectors.svg);
await targetPage.waitForSelectorInShadowRoot(TabStopShadowDomSelectors.transparentEllipse);
await targetPage.waitForSelectorInShadowRoot(TabStopShadowDomSelectors.opaqueEllipse);
await targetPage.waitForSelectorInShadowRoot(TabStopShadowDomSelectors.lines);
await targetPage.waitForSelectorInShadowRoot(TabStopShadowDomSelectors.text);
});

async function validateTabStopVisualizationOnTargetPage(shadowRoot: ElementHandle<Element>): Promise<void> {
const svgs = await shadowRoot.$$(TabStopShadowDomSelectors.svg);
const ellipses = await shadowRoot.$$(TabStopShadowDomSelectors.ellipse);
const lines = await shadowRoot.$$(TabStopShadowDomSelectors.lines);
const texts = await shadowRoot.$$(TabStopShadowDomSelectors.text);

// 3 tabs produce 1 svg, 2 ellipses, 1 texts and 1 line between them

expect(svgs).toHaveLength(1);
expect(ellipses).toHaveLength(2);
expect(lines).toHaveLength(1);
expect(texts).toHaveLength(1);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ describe('Target Page visualization boxes', () => {
it.each(adhocTools)('for adhoc tool "%s" should pass accessibility validation', async adhocTool => {
await popupPage.enableToggleByAriaLabel(adhocTool);

const shadowRoot = await targetPage.getShadowRoot();
await targetPage.waitForDescendentSelector(shadowRoot, TargetPageInjectedComponentSelectors.insightsVisualizationBox, {
visible: true,
});
await targetPage.waitForSelectorInShadowRoot(TargetPageInjectedComponentSelectors.insightsVisualizationBox, { visible: true });

const results = await scanForAccessibilityIssues(targetPage, TargetPageInjectedComponentSelectors.insightsRootContainer);
expect(results).toHaveLength(0);
Expand Down