1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-28 15:22:05 +03:00

Improve stability of Playwright screenshot tests (#11983)

This commit is contained in:
Michael Telatynski
2023-12-04 11:02:48 +00:00
committed by GitHub
parent 74ea0d134e
commit e180ca841b
23 changed files with 71 additions and 80 deletions

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { test as base, expect, Locator } from "@playwright/test";
import { test as base, expect as baseExpect, Locator, Page, ExpectMatcherState, ElementHandle } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
import _ from "lodash";
@ -197,6 +197,35 @@ export const test = base.extend<
},
});
test.use({});
export const expect = baseExpect.extend({
async toMatchScreenshot(this: ExpectMatcherState, receiver: Page | Locator, ...args) {
const page = "page" in receiver ? receiver.page() : receiver;
export { expect };
// 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;
}
`,
})) as ElementHandle<Element>;
await baseExpect(receiver).toHaveScreenshot(...args);
await style.evaluate((tag) => tag.remove());
return { pass: true, message: () => "", name: "toMatchScreenshot" };
},
});