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

Make Playwright tests async #6911

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1ee653a
upgrade playwright to 1.41
radium-v Feb 12, 2024
278e5cf
only use one playwright config
radium-v Feb 12, 2024
4108a64
remove custom hasAttribute assertion
radium-v Feb 12, 2024
aca76c4
remove custom toHaveBooleanAttribute assertion
radium-v Feb 12, 2024
97da2c6
mark flaky tests with test.fixme
radium-v Feb 12, 2024
7fe1076
replace deprecated shadowroot attributes in fast-style fixture
radium-v Feb 12, 2024
0b8e8ff
Change files
radium-v Feb 12, 2024
1971af4
make accordion and accordion-item tests async
radium-v Feb 12, 2024
c887404
make anchor tests async
radium-v Feb 12, 2024
b59b939
make anchored-region tests async
radium-v Feb 12, 2024
b16402b
make breadcrumb and breadcrumb-item tests async
radium-v Feb 12, 2024
9227100
make button tests async
radium-v Feb 12, 2024
3421139
make calendar tests async
radium-v Feb 12, 2024
3a9591f
make checkbox tests async
radium-v Feb 12, 2024
9155036
make combobox tests async
radium-v Feb 12, 2024
bdf1165
make data-grid tests async
radium-v Feb 12, 2024
6749cbc
make design-token tests async
radium-v Feb 12, 2024
0f12d33
make dialog tests async
radium-v Feb 12, 2024
f069d58
make disclosure tests async
radium-v Feb 12, 2024
2342351
make divider tests async
radium-v Feb 12, 2024
1754604
make flipper tests async
radium-v Feb 12, 2024
7985007
make form-associated tests async
radium-v Feb 12, 2024
63fda9e
make horizontal-scroll tests async
radium-v Feb 12, 2024
118beaf
make listbox and listbox-option tests async
radium-v Feb 12, 2024
8922b80
make menu and menu-item tests async
radium-v Feb 12, 2024
6a5ca54
make number-field tests async
radium-v Feb 12, 2024
01dcd88
make progress and progress-ring tests async
radium-v Feb 12, 2024
f9fa737
make radio and radio-group tests async
radium-v Feb 12, 2024
26a52a6
make search tests async
radium-v Feb 12, 2024
0eb8add
make select tests async
radium-v Feb 12, 2024
437915c
make slider-label and slider tests async
radium-v Feb 12, 2024
3b1d01f
make switch tests async
radium-v Feb 12, 2024
4a51b4d
make tab, tabs, and tab-panel tests async
radium-v Feb 12, 2024
26555c8
make text-area tests async
radium-v Feb 12, 2024
0724db7
make text-field tests async
radium-v Feb 12, 2024
2776966
make toolbar tests async
radium-v Feb 12, 2024
4e2e967
make tooltip tests async
radium-v Feb 12, 2024
63f4c88
make tree-view and tree-item tests async
radium-v Feb 12, 2024
b1b7334
make utilities tests async
radium-v Feb 12, 2024
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
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "upgrade playwright to 1.41",
"packageName": "@microsoft/fast-foundation",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "upgrade playwright to 1.41",
"packageName": "@microsoft/fast-ssr",
"email": "[email protected]",
"dependentChangeType": "none"
}
2 changes: 1 addition & 1 deletion packages/web-components/fast-foundation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
"@custom-elements-manifest/to-markdown": "^0.1.0",
"@microsoft/api-extractor": "7.24.2",
"@microsoft/tsdoc-config": "^0.13.4",
"@playwright/test": "^1.25.2",
"@playwright/test": "^1.41.2",
"@rollup/plugin-node-resolve": "^13.3.0",
"@storybook/addon-docs": "6.5.10",
"@storybook/addon-essentials": "6.5.10",
Expand Down
59 changes: 3 additions & 56 deletions packages/web-components/fast-foundation/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Locator, PlaywrightTestConfig } from "@playwright/test";
import { expect } from "@playwright/test";
import type { PlaywrightTestConfig } from "@playwright/test";

const config: PlaywrightTestConfig = {
projects: [{ name: "chromium" }, { name: "firefox" }, { name: "webkit" }],
reporter: "list",
testMatch: /.*\.pw\.spec\.ts$/,
retries: 3,
fullyParallel: process.env.CI ? false : true,
timeout: process.env.CI ? 10000 : 30000,
use: {
baseURL: "http://localhost:6006/iframe.html",
deviceScaleFactor: 1,
launchOptions: { args: ["--force-device-scale-factor=1"] },
viewport: {
height: 1280,
width: 720,
Expand All @@ -24,56 +24,3 @@ const config: PlaywrightTestConfig = {
};

export default config;

expect.extend({
async toHaveBooleanAttribute(recieved: Locator, name: string) {
const options = {
comment: "Object.is equality",
isNot: this.isNot,
promise: this.promise,
};

name = name.trim();

await (await recieved.elementHandle())?.waitForElementState("stable");

const [hasAttribute, attributeValue] = await recieved.evaluate((node, name) => {
return [node.hasAttribute(name), node.getAttribute(name)];
}, name);

if (this.isNot) {
return {
pass: hasAttribute,
message: () => `expected ${name} to not be present`,
};
}

return {
pass: hasAttribute && (attributeValue === "" || attributeValue === name),
message: () => `${this.utils.matcherHint(
"toHaveBooleanAttribute",
undefined,
undefined,
options
)}

expected ${recieved} to have boolean attribute \`${name}\``,
};
},

async hasAttribute(recieved: Locator, attribute: string) {
if (await recieved.isVisible()) {
await (await recieved.elementHandle())?.waitForElementState("stable");
}

const pass = await recieved.evaluate(
(node, attribute) => node.hasAttribute(attribute),
attribute
);

return {
message: () => `expected ${recieved} to have attribute \`${attribute}\``,
pass,
};
},
});
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
import type { Locator, Page } from "@playwright/test";
import { expect, test } from "@playwright/test";
import { fixtureURL } from "../__test__/helpers.js";
import type { FASTAccordionItem } from "./accordion-item.js";

test.describe("Accordion item", () => {
let page: Page;
let element: Locator;
let root: Locator;
let heading: Locator;
let button: Locator;

test.beforeAll(async ({ browser }) => {
page = await browser.newPage();

element = page.locator("fast-accordion-item");

root = page.locator("#root");

heading = page.locator(`[role="heading"]`);

button = element.locator("button");
test("should set a default heading level of 2 when `headinglevel` is not provided", async ({
page,
}) => {
const root = page.locator("#root");
const element = page.locator("fast-accordion-item");

await page.goto(fixtureURL("accordion-item--accordion-item"));
});

test.afterAll(async () => {
await page.close();
});

test("should set a default heading level of 2 when `headinglevel` is not provided", async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-accordion-item>
Expand All @@ -38,12 +20,20 @@ test.describe("Accordion item", () => {
`;
});

await expect(element).not.hasAttribute("headinglevel");
await expect(element).not.toHaveAttribute("headinglevel");

await expect(element).toHaveJSProperty("headinglevel", 2);
});

test("should set the `aria-level` attribute on the internal heading element equal to the heading level", async () => {
test("should set the `aria-level` attribute on the internal heading element equal to the heading level", async ({
page,
}) => {
const root = page.locator("#root");
const element = page.locator("fast-accordion-item");
const heading = page.locator(`[role="heading"]`);

await page.goto(fixtureURL("accordion-item--accordion-item"));

await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-accordion-item>
Expand All @@ -60,7 +50,15 @@ test.describe("Accordion item", () => {
await expect(heading).toHaveAttribute("aria-level", "3");
});

test("should set `aria-expanded` property on the internal control equal to the `expanded` property", async () => {
test("should set `aria-expanded` property on the internal control equal to the `expanded` property", async ({
page,
}) => {
const root = page.locator("#root");
const element = page.locator("fast-accordion-item");
const button = element.locator("button");

await page.goto(fixtureURL("accordion-item--accordion-item"));

await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-accordion-item expanded></fast-accordion-item>
Expand All @@ -76,23 +74,39 @@ test.describe("Accordion item", () => {
await expect(button).toHaveAttribute("aria-expanded", "false");
});

test("should set `disabled` attribute on the internal control equal to the `disabled` property", async () => {
test("should set `disabled` attribute on the internal control equal to the `disabled` property", async ({
page,
}) => {
const root = page.locator("#root");
const element = page.locator("fast-accordion-item");
const button = element.locator("button");

await page.goto(fixtureURL("accordion-item--accordion-item"));

await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-accordion-item disabled></fast-accordion-item>
`;
});

await expect(button).toHaveBooleanAttribute("disabled");
await expect(button).toHaveAttribute("disabled");

await element.evaluate<void, FASTAccordionItem>(node => {
node.disabled = false;
});

await expect(button).not.toHaveBooleanAttribute("disabled");
await expect(button).not.toHaveAttribute("disabled");
});

test("should set internal properties to match the id when provided", async () => {
test("should set internal properties to match the id when provided", async ({
page,
}) => {
const root = page.locator("#root");
const element = page.locator("fast-accordion-item");
const button = element.locator("button");

await page.goto(fixtureURL("accordion-item--accordion-item"));

await root.evaluate(node => {
node.innerHTML = /* html */ `
<fast-accordion-item id="foo"></fast-accordion-item>
Expand Down
Loading
Loading