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

Commit c6d9228

Browse files
authored
Fix flaky Cypress test cypress/e2e/widgets/stickers.spec.ts (#11440)
* Fix tests choosing the wrong room by matching on exact room name in viewRoomByName * Allow either of the two different URLs for thumbnails in sticker test * Find room by looking inside Rooms for something with the right text * Check for the download URL of a thumbnail only, which will appear after the thumbnail 404s * Click the title div instead of the contained span, to avoid clicking something potentially off-screen * Find by label text because that works when room list is folded * Find room by title because label text is different * Attempt to allow opening room by name in all needed cases
1 parent 9d417ce commit c6d9228

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

cypress/e2e/widgets/stickers.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ function expectTimelineSticker(roomId: string) {
8686
// Make sure it's in the right room
8787
cy.get(".mx_EventTile_sticker > a").should("have.attr", "href").and("include", `/${roomId}/`);
8888

89-
// Make sure the image points at the sticker image
90-
cy.get<HTMLImageElement>(`img[alt="${STICKER_NAME}"]`)
91-
.should("have.attr", "src")
92-
.and("match", /thumbnail\/somewhere\?/);
89+
// Make sure the image points at the sticker image. We will briefly show it
90+
// using the thumbnail URL, but as soon as that fails, we will switch to the
91+
// download URL.
92+
cy.get<HTMLImageElement>(`img[alt="${STICKER_NAME}"][src*="download/somewhere"]`).should("exist");
9393
}
9494

9595
describe("Stickers", () => {

cypress/support/views.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ declare global {
2323
namespace Cypress {
2424
interface Chainable {
2525
/**
26-
* Opens the given room by name. The room must be visible in the room list.
27-
* It uses a start-anchored regexp to accommodate for room tiles for unread rooms containing additional
28-
* context in their aria labels, e.g. "Room name 3 unread messages."
26+
* Opens the given room by name. The room must be visible in the
27+
* room list, but the room list may be folded horizontally, and the
28+
* room may contain unread messages.
2929
*
30-
* @param name The room name to find and click on/open.
30+
* @param name The exact room name to find and click on/open.
3131
*/
3232
viewRoomByName(name: string): Chainable<JQuery<HTMLElement>>;
3333

@@ -65,10 +65,20 @@ declare global {
6565
}
6666

6767
Cypress.Commands.add("viewRoomByName", (name: string): Chainable<JQuery<HTMLElement>> => {
68-
return cy
69-
.findByRole("treeitem", { name: new RegExp("^" + name) })
70-
.should("have.class", "mx_RoomTile")
71-
.click();
68+
// We look for the room inside the room list, which is a tree called Rooms.
69+
//
70+
// There are 3 cases:
71+
// - the room list is folded:
72+
// then the aria-label on the room tile is the name (with nothing extra)
73+
// - the room list is unfolder and the room has messages:
74+
// then the aria-label contains the unread count, but the title of the
75+
// div inside the titleContainer equals the room name
76+
// - the room list is unfolded and the room has no messages:
77+
// then the aria-label is the name and so is the title of a div
78+
//
79+
// So by matching EITHER title=name OR aria-label=name we find this exact
80+
// room in all three cases.
81+
return cy.findByRole("tree", { name: "Rooms" }).find(`[title="${name}"],[aria-label="${name}"]`).first().click();
7282
});
7383

7484
Cypress.Commands.add("viewRoomById", (id: string): void => {

0 commit comments

Comments
 (0)