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

Commit 2cf8a9a

Browse files
authored
Stabilise Cypress login tests (#9446)
* Attempt to stabilise login tests * More stability * Stabilise s'more * don't clear LS as we rely on it for enablements * Add small delay * Iterate * Update login.ts
1 parent b04991a commit 2cf8a9a

File tree

14 files changed

+60
-58
lines changed

14 files changed

+60
-58
lines changed

cypress/e2e/create-room/create-room.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe("Create Room", () => {
6060

6161
cy.url().should("contain", "/#/room/#test-room-1:localhost");
6262
cy.stopMeasuring("from-submit-to-room");
63-
cy.get(".mx_RoomHeader_nametext").contains(name);
64-
cy.get(".mx_RoomHeader_topic").contains(topic);
63+
cy.contains(".mx_RoomHeader_nametext", name);
64+
cy.contains(".mx_RoomHeader_topic", topic);
6565
});
6666
});

cypress/e2e/editing/editing.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe("Editing", () => {
6262
cy.get(".mx_BasicMessageComposer_input").type("Foo{backspace}{backspace}{backspace}{enter}");
6363
cy.checkA11y();
6464
});
65-
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", "Message");
65+
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", "Message");
6666

6767
// Assert that the edit composer has gone away
6868
cy.get(".mx_EditMessageComposer").should("not.exist");

cypress/e2e/login/consent.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe("Consent", () => {
4646

4747
// Accept terms & conditions
4848
cy.get(".mx_QuestionDialog").within(() => {
49-
cy.get("#mx_BaseDialog_title").contains("Terms and Conditions");
49+
cy.contains("#mx_BaseDialog_title", "Terms and Conditions");
5050
cy.get(".mx_Dialog_primary").click();
5151
});
5252

@@ -58,7 +58,7 @@ describe("Consent", () => {
5858
cy.visit(url);
5959

6060
cy.get('[type="submit"]').click();
61-
cy.get("p").contains("Danke schon");
61+
cy.contains("p", "Danke schon");
6262
});
6363
});
6464

cypress/e2e/login/login.spec.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ import { SynapseInstance } from "../../plugins/synapsedocker";
2121
describe("Login", () => {
2222
let synapse: SynapseInstance;
2323

24-
beforeEach(() => {
25-
cy.visit("/#/login");
26-
cy.startSynapse("consent").then(data => {
27-
synapse = data;
28-
});
29-
});
30-
3124
afterEach(() => {
3225
cy.stopSynapse(synapse);
3326
});
@@ -37,7 +30,11 @@ describe("Login", () => {
3730
const password = "p4s5W0rD";
3831

3932
beforeEach(() => {
40-
cy.registerUser(synapse, username, password);
33+
cy.startSynapse("consent").then(data => {
34+
synapse = data;
35+
cy.registerUser(synapse, username, password);
36+
cy.visit("/#/login");
37+
});
4138
});
4239

4340
it("logs in with an existing account and lands on the home screen", () => {
@@ -65,14 +62,17 @@ describe("Login", () => {
6562

6663
describe("logout", () => {
6764
beforeEach(() => {
68-
cy.initTestUser(synapse, "Erin");
65+
cy.startSynapse("consent").then(data => {
66+
synapse = data;
67+
cy.initTestUser(synapse, "Erin");
68+
});
6969
});
7070

7171
it("should go to login page on logout", () => {
7272
cy.get('[aria-label="User menu"]').click();
7373

7474
// give a change for the outstanding requests queue to settle before logging out
75-
cy.wait(500);
75+
cy.wait(2000);
7676

7777
cy.get(".mx_UserMenu_contextMenu").within(() => {
7878
cy.get(".mx_UserMenu_iconSignOut").click();
@@ -94,7 +94,7 @@ describe("Login", () => {
9494
cy.get('[aria-label="User menu"]').click();
9595

9696
// give a change for the outstanding requests queue to settle before logging out
97-
cy.wait(500);
97+
cy.wait(2000);
9898

9999
cy.get(".mx_UserMenu_contextMenu").within(() => {
100100
cy.get(".mx_UserMenu_iconSignOut").click();

cypress/e2e/polls/polls.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe("Polls", () => {
122122
createPoll(pollParams);
123123

124124
// Wait for message to send, get its ID and save as @pollId
125-
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", pollParams.title)
125+
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", pollParams.title)
126126
.invoke("attr", "data-scroll-tokens").as("pollId");
127127

128128
cy.get<string>("@pollId").then(pollId => {
@@ -190,7 +190,7 @@ describe("Polls", () => {
190190
createPoll(pollParams);
191191

192192
// Wait for message to send, get its ID and save as @pollId
193-
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", pollParams.title)
193+
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", pollParams.title)
194194
.invoke("attr", "data-scroll-tokens").as("pollId");
195195

196196
cy.get<string>("@pollId").then(pollId => {

cypress/e2e/room-directory/room-directory.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe("Room Directory", () => {
9393
cy.get(".mx_RoomDirectory_dialogWrapper").percySnapshotElement("Room Directory - filtered no results");
9494

9595
cy.get('.mx_RoomDirectory_dialogWrapper [name="dirsearch"]').type("{selectAll}{backspace}test1234");
96-
cy.get(".mx_RoomDirectory_dialogWrapper").contains(".mx_RoomDirectory_listItem", name)
96+
cy.contains(".mx_RoomDirectory_dialogWrapper .mx_RoomDirectory_listItem", name)
9797
.should("exist").as("resultRow");
9898
cy.get(".mx_RoomDirectory_dialogWrapper").percySnapshotElement("Room Directory - filtered one result");
9999
cy.get("@resultRow").find(".mx_AccessibleButton").contains("Join").click();

cypress/e2e/sliding-sync/sliding-sync.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ describe("Sliding Sync", () => {
293293
]);
294294

295295
cy.contains(".mx_RoomTile", "Reject").click();
296-
cy.get(".mx_RoomView").contains(".mx_AccessibleButton", "Reject").click();
296+
cy.contains(".mx_RoomView .mx_AccessibleButton", "Reject").click();
297297

298298
// wait for the rejected room to disappear
299299
cy.get(".mx_RoomTile").should('have.length', 3);
@@ -328,8 +328,8 @@ describe("Sliding Sync", () => {
328328
cy.getClient().then(cli => cli.setRoomTag(roomId, "m.favourite", { order: 0.5 }));
329329
});
330330

331-
cy.get('.mx_RoomSublist[aria-label="Favourites"]').contains(".mx_RoomTile", "Favourite DM").should("exist");
332-
cy.get('.mx_RoomSublist[aria-label="People"]').contains(".mx_RoomTile", "Favourite DM").should("not.exist");
331+
cy.contains('.mx_RoomSublist[aria-label="Favourites"] .mx_RoomTile', "Favourite DM").should("exist");
332+
cy.contains('.mx_RoomSublist[aria-label="People"] .mx_RoomTile', "Favourite DM").should("not.exist");
333333
});
334334

335335
// Regression test for a bug in SS mode, but would be useful to have in non-SS mode too.

cypress/e2e/spaces/spaces.spec.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,26 @@ describe("Spaces", () => {
8383
cy.get('input[label="Name"]').type("Let's have a Riot");
8484
cy.get('input[label="Address"]').should("have.value", "lets-have-a-riot");
8585
cy.get('textarea[label="Description"]').type("This is a space to reminisce Riot.im!");
86-
cy.get(".mx_AccessibleButton").contains("Create").click();
86+
cy.contains(".mx_AccessibleButton", "Create").click();
8787
});
8888

8989
// Create the default General & Random rooms, as well as a custom "Jokes" room
9090
cy.get('input[label="Room name"][value="General"]').should("exist");
9191
cy.get('input[label="Room name"][value="Random"]').should("exist");
9292
cy.get('input[placeholder="Support"]').type("Jokes");
93-
cy.get(".mx_AccessibleButton").contains("Continue").click();
93+
cy.contains(".mx_AccessibleButton", "Continue").click();
9494

9595
// Copy matrix.to link
9696
cy.get(".mx_SpacePublicShare_shareButton").focus().realClick();
9797
cy.getClipboardText().should("eq", "https://matrix.to/#/#lets-have-a-riot:localhost");
9898

9999
// Go to space home
100-
cy.get(".mx_AccessibleButton").contains("Go to my first room").click();
100+
cy.contains(".mx_AccessibleButton", "Go to my first room").click();
101101

102102
// Assert rooms exist in the room list
103-
cy.get(".mx_RoomList").contains(".mx_RoomTile", "General").should("exist");
104-
cy.get(".mx_RoomList").contains(".mx_RoomTile", "Random").should("exist");
105-
cy.get(".mx_RoomList").contains(".mx_RoomTile", "Jokes").should("exist");
103+
cy.contains(".mx_RoomList .mx_RoomTile", "General").should("exist");
104+
cy.contains(".mx_RoomList .mx_RoomTile", "Random").should("exist");
105+
cy.contains(".mx_RoomList .mx_RoomTile", "Jokes").should("exist");
106106
});
107107

108108
it("should allow user to create private space", () => {
@@ -113,7 +113,7 @@ describe("Spaces", () => {
113113
cy.get('input[label="Name"]').type("This is not a Riot");
114114
cy.get('input[label="Address"]').should("not.exist");
115115
cy.get('textarea[label="Description"]').type("This is a private space of mourning Riot.im...");
116-
cy.get(".mx_AccessibleButton").contains("Create").click();
116+
cy.contains(".mx_AccessibleButton", "Create").click();
117117
});
118118

119119
cy.get(".mx_SpaceRoomView_privateScope_meAndMyTeammatesButton").click();
@@ -122,20 +122,20 @@ describe("Spaces", () => {
122122
cy.get('input[label="Room name"][value="General"]').should("exist");
123123
cy.get('input[label="Room name"][value="Random"]').should("exist");
124124
cy.get('input[placeholder="Support"]').type("Projects");
125-
cy.get(".mx_AccessibleButton").contains("Continue").click();
125+
cy.contains(".mx_AccessibleButton", "Continue").click();
126126

127127
cy.get(".mx_SpaceRoomView").should("contain", "Invite your teammates");
128-
cy.get(".mx_AccessibleButton").contains("Skip for now").click();
128+
cy.contains(".mx_AccessibleButton", "Skip for now").click();
129129

130130
// Assert rooms exist in the room list
131-
cy.get(".mx_RoomList").contains(".mx_RoomTile", "General").should("exist");
132-
cy.get(".mx_RoomList").contains(".mx_RoomTile", "Random").should("exist");
133-
cy.get(".mx_RoomList").contains(".mx_RoomTile", "Projects").should("exist");
131+
cy.contains(".mx_RoomList .mx_RoomTile", "General").should("exist");
132+
cy.contains(".mx_RoomList .mx_RoomTile", "Random").should("exist");
133+
cy.contains(".mx_RoomList .mx_RoomTile", "Projects").should("exist");
134134

135135
// Assert rooms exist in the space explorer
136-
cy.get(".mx_SpaceHierarchy_list").contains(".mx_SpaceHierarchy_roomTile", "General").should("exist");
137-
cy.get(".mx_SpaceHierarchy_list").contains(".mx_SpaceHierarchy_roomTile", "Random").should("exist");
138-
cy.get(".mx_SpaceHierarchy_list").contains(".mx_SpaceHierarchy_roomTile", "Projects").should("exist");
136+
cy.contains(".mx_SpaceHierarchy_list .mx_SpaceHierarchy_roomTile", "General").should("exist");
137+
cy.contains(".mx_SpaceHierarchy_list .mx_SpaceHierarchy_roomTile", "Random").should("exist");
138+
cy.contains(".mx_SpaceHierarchy_list .mx_SpaceHierarchy_roomTile", "Projects").should("exist");
139139
});
140140

141141
it("should allow user to create just-me space", () => {
@@ -155,10 +155,10 @@ describe("Spaces", () => {
155155
cy.get(".mx_SpaceRoomView_privateScope_justMeButton").click();
156156

157157
cy.get(".mx_AddExistingToSpace_entry").click();
158-
cy.get(".mx_AccessibleButton").contains("Add").click();
158+
cy.contains(".mx_AccessibleButton", "Add").click();
159159

160-
cy.get(".mx_RoomList").contains(".mx_RoomTile", "Sample Room").should("exist");
161-
cy.get(".mx_SpaceHierarchy_list").contains(".mx_SpaceHierarchy_roomTile", "Sample Room").should("exist");
160+
cy.contains(".mx_RoomList .mx_RoomTile", "Sample Room").should("exist");
161+
cy.contains(".mx_SpaceHierarchy_list .mx_SpaceHierarchy_roomTile", "Sample Room").should("exist");
162162
});
163163

164164
it("should allow user to invite another to a space", () => {
@@ -186,7 +186,7 @@ describe("Spaces", () => {
186186

187187
cy.get(".mx_InviteDialog_other").within(() => {
188188
cy.get('input[type="text"]').type(bot.getUserId());
189-
cy.get(".mx_AccessibleButton").contains("Invite").click();
189+
cy.contains(".mx_AccessibleButton", "Invite").click();
190190
});
191191

192192
cy.get(".mx_InviteDialog_other").should("not.exist");

cypress/e2e/threads/threads.spec.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe("Threads", () => {
5353
cy.window().should("have.prop", "beforeReload", true);
5454

5555
cy.leaveBeta("Threads");
56+
cy.wait(1000);
5657
// after reload the property should be gone
5758
cy.window().should("not.have.prop", "beforeReload");
5859
});
@@ -66,6 +67,7 @@ describe("Threads", () => {
6667
cy.window().should("have.prop", "beforeReload", true);
6768

6869
cy.joinBeta("Threads");
70+
cy.wait(1000);
6971
// after reload the property should be gone
7072
cy.window().should("not.have.prop", "beforeReload");
7173
});
@@ -92,7 +94,7 @@ describe("Threads", () => {
9294
cy.get(".mx_RoomView_body .mx_BasicMessageComposer_input").type("Hello Mr. Bot{enter}");
9395

9496
// Wait for message to send, get its ID and save as @threadId
95-
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
97+
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
9698
.invoke("attr", "data-scroll-tokens").as("threadId");
9799

98100
// Bot starts thread
@@ -116,21 +118,21 @@ describe("Threads", () => {
116118
cy.get(".mx_RoomView_body .mx_ThreadSummary .mx_ThreadSummary_content").should("contain", "Test");
117119

118120
// User reacts to message instead
119-
cy.get(".mx_ThreadView .mx_EventTile").contains(".mx_EventTile_line", "Hello there")
121+
cy.contains(".mx_ThreadView .mx_EventTile .mx_EventTile_line", "Hello there")
120122
.find('[aria-label="React"]').click({ force: true }); // Cypress has no ability to hover
121123
cy.get(".mx_EmojiPicker").within(() => {
122124
cy.get('input[type="text"]').type("wave");
123-
cy.get('[role="menuitem"]').contains("👋").click();
125+
cy.contains('[role="menuitem"]', "👋").click();
124126
});
125127

126128
// User redacts their prior response
127-
cy.get(".mx_ThreadView .mx_EventTile").contains(".mx_EventTile_line", "Test")
129+
cy.contains(".mx_ThreadView .mx_EventTile .mx_EventTile_line", "Test")
128130
.find('[aria-label="Options"]').click({ force: true }); // Cypress has no ability to hover
129131
cy.get(".mx_IconizedContextMenu").within(() => {
130-
cy.get('[role="menuitem"]').contains("Remove").click();
132+
cy.contains('[role="menuitem"]', "Remove").click();
131133
});
132134
cy.get(".mx_TextInputDialog").within(() => {
133-
cy.get(".mx_Dialog_primary").contains("Remove").click();
135+
cy.contains(".mx_Dialog_primary", "Remove").click();
134136
});
135137

136138
// User asserts summary was updated correctly
@@ -171,7 +173,7 @@ describe("Threads", () => {
171173
cy.get(".mx_RoomView_body .mx_ThreadSummary .mx_ThreadSummary_content").should("contain", "Great!");
172174

173175
// User edits & asserts
174-
cy.get(".mx_ThreadView .mx_EventTile_last").contains(".mx_EventTile_line", "Great!").within(() => {
176+
cy.contains(".mx_ThreadView .mx_EventTile_last .mx_EventTile_line", "Great!").within(() => {
175177
cy.get('[aria-label="Edit"]').click({ force: true }); // Cypress has no ability to hover
176178
cy.get(".mx_BasicMessageComposer_input").type(" How about yourself?{enter}");
177179
});
@@ -234,7 +236,7 @@ describe("Threads", () => {
234236
cy.get(".mx_RoomView_body .mx_BasicMessageComposer_input").type("Hello Mr. Bot{enter}");
235237

236238
// Create thread
237-
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
239+
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
238240
.realHover().find(".mx_MessageActionBar_threadButton").click();
239241
cy.get(".mx_ThreadView_timelinePanelWrapper").should("have.length", 1);
240242

@@ -256,7 +258,7 @@ describe("Threads", () => {
256258
cy.get(".mx_RoomView_body .mx_BasicMessageComposer_input").type("Hello Mr. Bot{enter}");
257259

258260
// Create thread
259-
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
261+
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
260262
.realHover().find(".mx_MessageActionBar_threadButton").click();
261263
cy.get(".mx_ThreadView_timelinePanelWrapper").should("have.length", 1);
262264

@@ -268,7 +270,7 @@ describe("Threads", () => {
268270
cy.get(".mx_BaseCard_close").click();
269271

270272
// Open existing thread
271-
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
273+
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
272274
.realHover().find(".mx_MessageActionBar_threadButton").click();
273275
cy.get(".mx_ThreadView_timelinePanelWrapper").should("have.length", 1);
274276
cy.get(".mx_BaseCard .mx_EventTile").should("contain", "Hello Mr. Bot");

cypress/e2e/timeline/timeline.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ describe("Timeline", () => {
329329
cy.getComposer().type(`${MESSAGE}{enter}`);
330330

331331
// Reply to the message
332-
cy.get(".mx_RoomView_body").contains(".mx_EventTile_line", "Hello world").within(() => {
332+
cy.contains(".mx_RoomView_body .mx_EventTile_line", "Hello world").within(() => {
333333
cy.get('[aria-label="Reply"]').click({ force: true }); // Cypress has no ability to hover
334334
});
335335
};

cypress/e2e/toasts/analytics-toast.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function assertNoToasts(): void {
2424
}
2525

2626
function getToast(expectedTitle: string): Chainable<JQuery> {
27-
return cy.get(".mx_Toast_toast").contains("h2", expectedTitle).should("exist").closest(".mx_Toast_toast");
27+
return cy.contains(".mx_Toast_toast h2", expectedTitle).should("exist").closest(".mx_Toast_toast");
2828
}
2929

3030
function acceptToast(expectedTitle: string): void {

cypress/support/login.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Cypress.Commands.add("loginUser", (synapse: SynapseInstance, username: string, p
9191
Cypress.Commands.add("initTestUser", (synapse: SynapseInstance, displayName: string, prelaunchFn?: () => void): Chainable<UserCredentials> => {
9292
// XXX: work around Cypress not clearing IDB between tests
9393
cy.window({ log: false }).then(win => {
94-
win.indexedDB.databases().then(databases => {
94+
win.indexedDB.databases()?.then(databases => {
9595
databases.forEach(database => {
9696
win.indexedDB.deleteDatabase(database.name);
9797
});

cypress/support/settings.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Cypress.Commands.add("openRoomSettings", (tab?: string): Chainable<JQuery<HTMLEl
153153

154154
Cypress.Commands.add("switchTab", (tab: string): Chainable<JQuery<HTMLElement>> => {
155155
return cy.get(".mx_TabbedView_tabLabels").within(() => {
156-
cy.get(".mx_TabbedView_tabLabel").contains(tab).click();
156+
cy.contains(".mx_TabbedView_tabLabel", tab).click();
157157
});
158158
});
159159

@@ -162,13 +162,13 @@ Cypress.Commands.add("closeDialog", (): Chainable<JQuery<HTMLElement>> => {
162162
});
163163

164164
Cypress.Commands.add("joinBeta", (name: string): Chainable<JQuery<HTMLElement>> => {
165-
return cy.get(".mx_BetaCard_title").contains(name).closest(".mx_BetaCard").within(() => {
165+
return cy.contains(".mx_BetaCard_title", name).closest(".mx_BetaCard").within(() => {
166166
return cy.get(".mx_BetaCard_buttons").contains("Join the beta").click();
167167
});
168168
});
169169

170170
Cypress.Commands.add("leaveBeta", (name: string): Chainable<JQuery<HTMLElement>> => {
171-
return cy.get(".mx_BetaCard_title").contains(name).closest(".mx_BetaCard").within(() => {
171+
return cy.contains(".mx_BetaCard_title", name).closest(".mx_BetaCard").within(() => {
172172
return cy.get(".mx_BetaCard_buttons").contains("Leave the beta").click();
173173
});
174174
});

src/Lifecycle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
426426
const { hsUrl, isUrl, hasAccessToken, accessToken, userId, deviceId, isGuest } = await getStoredSessionVars();
427427

428428
if (hasAccessToken && !accessToken) {
429-
abortLogin();
429+
await abortLogin();
430430
}
431431

432432
if (accessToken && userId && hsUrl) {

0 commit comments

Comments
 (0)