Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Stabilise screenshot tests (#12835)
Browse files Browse the repository at this point in the history
* Hide tooltips in screenshot tests by default

Signed-off-by: Michael Telatynski <[email protected]>

* Blank out dialog backgrounds by default

Signed-off-by: Michael Telatynski <[email protected]>

* Crop image-upload-preview screenshot

Signed-off-by: Michael Telatynski <[email protected]>

* Update screenshots

Signed-off-by: Michael Telatynski <[email protected]>

* Stabilise width of masked user is in user profile

Signed-off-by: Michael Telatynski <[email protected]>

* Tidy

Signed-off-by: Michael Telatynski <[email protected]>

* Update screenshots

Signed-off-by: Michael Telatynski <[email protected]>

---------

Signed-off-by: Michael Telatynski <[email protected]>
  • Loading branch information
t3chguy authored Jul 30, 2024
1 parent 077549e commit a189758
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 42 deletions.
2 changes: 1 addition & 1 deletion playwright/e2e/file-upload/image-upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ test.describe("Image Upload", () => {

await expect(page.getByRole("button", { name: "Upload" })).toBeEnabled();
await expect(page.getByRole("button", { name: "Close dialog" })).toBeEnabled();
await expect(page).toMatchScreenshot("image-upload-preview.png");
await expect(page.locator(".mx_Dialog")).toMatchScreenshot("image-upload-preview.png");
});
});
2 changes: 1 addition & 1 deletion playwright/e2e/register/register.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test.describe("Registration", () => {

await expect(page.getByRole("textbox", { name: "Username", exact: true })).toBeVisible();
// Hide the server text as it contains the randomly allocated Homeserver port
const screenshotOptions = { mask: [page.locator(".mx_ServerPicker_server")] };
const screenshotOptions = { mask: [page.locator(".mx_ServerPicker_server")], includeDialogBackground: true };
await expect(page).toMatchScreenshot("registration.png", screenshotOptions);
await checkA11y();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test.describe("Appearance user settings tab", () => {
// -4 value is 12px
await fontDropdown.getByLabel("Font size").selectOption({ value: "-4" });

await expect(page).toMatchScreenshot("window-12px.png");
await expect(page).toMatchScreenshot("window-12px.png", { includeDialogBackground: true });
});

test("should support enabling system font", async ({ page, app, user }) => {
Expand Down
6 changes: 0 additions & 6 deletions playwright/e2e/timeline/timeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ test.describe("Timeline", () => {
{
// Exclude timestamp from snapshot of mx_MainSplit
mask: [page.locator(".mx_MessageTimestamp")],
hideTooltips: true,
},
);

Expand All @@ -428,7 +427,6 @@ test.describe("Timeline", () => {
await expect(page.locator(".mx_MainSplit")).toMatchScreenshot("expanded-gels-and-messages-irc-layout.png", {
// Exclude timestamp from snapshot of mx_MainSplit
mask: [page.locator(".mx_MessageTimestamp")],
hideTooltips: true,
});

// 3. Alignment of expanded GELS and placeholder of deleted message
Expand All @@ -449,7 +447,6 @@ test.describe("Timeline", () => {
await expect(page.locator(".mx_MainSplit")).toMatchScreenshot("expanded-gels-redaction-placeholder.png", {
// Exclude timestamp from snapshot of mx_MainSplit
mask: [page.locator(".mx_MessageTimestamp")],
hideTooltips: true,
});

// 4. Alignment of expanded GELS, placeholder of deleted message, and emote
Expand All @@ -472,7 +469,6 @@ test.describe("Timeline", () => {
await expect(page.locator(".mx_MainSplit")).toMatchScreenshot("expanded-gels-emote-irc-layout.png", {
// Exclude timestamp from snapshot of mx_MainSplit
mask: [page.locator(".mx_MessageTimestamp")],
hideTooltips: true,
});
});

Expand All @@ -485,7 +481,6 @@ test.describe("Timeline", () => {
display: none !important;
}
`,
hideTooltips: true,
};

await sendEvent(app.client, room.roomId);
Expand Down Expand Up @@ -1108,7 +1103,6 @@ test.describe("Timeline", () => {
// Exclude timestamp and read marker from snapshot
const screenshotOptions = {
mask: [page.locator(".mx_MessageTimestamp")],
hideTooltips: true,
css: `
.mx_TopUnreadMessagesBar, .mx_MessagePanel_myReadMarker {
display: none !important;
Expand Down
6 changes: 6 additions & 0 deletions playwright/e2e/user-view/user-view.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ test.describe("UserView", () => {
await expect(rightPanel.getByText("1 session")).toBeVisible();
await expect(rightPanel).toMatchScreenshot("user-info.png", {
mask: [page.locator(".mx_UserInfo_profile_mxid")],
css: `
/* Use monospace font for consistent mask width */
.mx_UserInfo_profile_mxid {
font-family: Inconsolata !important;
}
`,
});
});
});
78 changes: 45 additions & 33 deletions playwright/element-web-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ export const expect = baseExpect.extend({
name: `${string}.png`,
options?: {
mask?: Array<Locator>;
omitBackground?: boolean;
hideTooltips?: boolean;
includeDialogBackground?: boolean;
showTooltips?: boolean;
timeout?: number;
css?: string;
},
Expand All @@ -324,45 +324,57 @@ export const expect = baseExpect.extend({

const page = "page" in receiver ? receiver.page() : receiver;

let hideTooltipsCss: string | undefined;
if (options?.hideTooltips) {
hideTooltipsCss = `
let css = `
.mx_MessagePanel_myReadMarker {
display: none !important;
}
.mx_RoomView_MessageList {
height: auto !important;
}
.mx_DisambiguatedProfile_displayName {
color: var(--cpd-color-blue-1200) !important;
}
.mx_BaseAvatar {
background-color: var(--cpd-color-fuchsia-1200) !important;
color: white !important;
}
.mx_ReplyChain {
border-left-color: var(--cpd-color-blue-1200) !important;
}
/* Avoid flakiness from hover styling */
.mx_ReplyChain_show {
color: var(--cpd-color-text-secondary) !important;
}
/* Use monospace font for timestamp for consistent mask width */
.mx_MessageTimestamp {
font-family: Inconsolata !important;
}
`;

if (!options?.showTooltips) {
css += `
.mx_Tooltip_visible {
visibility: hidden !important;
}
`;
}

if (!options?.includeDialogBackground) {
css += `
/* Make the dialog backdrop solid so any dialog screenshots don't show any components behind them */
.mx_Dialog_background {
background-color: #030c1b !important;
}
`;
}

if (options?.css) {
css += options.css;
}

// We add a custom style tag before taking screenshots
const style = (await page.addStyleTag({
content: `
.mx_MessagePanel_myReadMarker {
display: none !important;
}
.mx_RoomView_MessageList {
height: auto !important;
}
.mx_DisambiguatedProfile_displayName {
color: var(--cpd-color-blue-1200) !important;
}
.mx_BaseAvatar {
background-color: var(--cpd-color-fuchsia-1200) !important;
color: white !important;
}
.mx_ReplyChain {
border-left-color: var(--cpd-color-blue-1200) !important;
}
/* Avoid flakiness from hover styling */
.mx_ReplyChain_show {
color: var(--cpd-color-text-secondary) !important;
}
/* Use monospace font for timestamp for consistent mask width */
.mx_MessageTimestamp {
font-family: Inconsolata !important;
}
${hideTooltipsCss ?? ""}
${options?.css ?? ""}
`,
content: css,
})) as ElementHandle<Element>;

const screenshotName = sanitizeFilePathBeforeExtension(name);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a189758

Please sign in to comment.