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
This commit is contained in:
Michael Telatynski 2022-10-18 17:07:23 +01:00 committed by GitHub
parent b04991a962
commit 2cf8a9a2f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 60 additions and 58 deletions

View file

@ -60,7 +60,7 @@ describe("Create Room", () => {
cy.url().should("contain", "/#/room/#test-room-1:localhost");
cy.stopMeasuring("from-submit-to-room");
cy.get(".mx_RoomHeader_nametext").contains(name);
cy.get(".mx_RoomHeader_topic").contains(topic);
cy.contains(".mx_RoomHeader_nametext", name);
cy.contains(".mx_RoomHeader_topic", topic);
});
});

View file

@ -62,7 +62,7 @@ describe("Editing", () => {
cy.get(".mx_BasicMessageComposer_input").type("Foo{backspace}{backspace}{backspace}{enter}");
cy.checkA11y();
});
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", "Message");
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", "Message");
// Assert that the edit composer has gone away
cy.get(".mx_EditMessageComposer").should("not.exist");

View file

@ -46,7 +46,7 @@ describe("Consent", () => {
// Accept terms & conditions
cy.get(".mx_QuestionDialog").within(() => {
cy.get("#mx_BaseDialog_title").contains("Terms and Conditions");
cy.contains("#mx_BaseDialog_title", "Terms and Conditions");
cy.get(".mx_Dialog_primary").click();
});
@ -58,7 +58,7 @@ describe("Consent", () => {
cy.visit(url);
cy.get('[type="submit"]').click();
cy.get("p").contains("Danke schon");
cy.contains("p", "Danke schon");
});
});

View file

@ -21,13 +21,6 @@ import { SynapseInstance } from "../../plugins/synapsedocker";
describe("Login", () => {
let synapse: SynapseInstance;
beforeEach(() => {
cy.visit("/#/login");
cy.startSynapse("consent").then(data => {
synapse = data;
});
});
afterEach(() => {
cy.stopSynapse(synapse);
});
@ -37,7 +30,11 @@ describe("Login", () => {
const password = "p4s5W0rD";
beforeEach(() => {
cy.registerUser(synapse, username, password);
cy.startSynapse("consent").then(data => {
synapse = data;
cy.registerUser(synapse, username, password);
cy.visit("/#/login");
});
});
it("logs in with an existing account and lands on the home screen", () => {
@ -65,14 +62,17 @@ describe("Login", () => {
describe("logout", () => {
beforeEach(() => {
cy.initTestUser(synapse, "Erin");
cy.startSynapse("consent").then(data => {
synapse = data;
cy.initTestUser(synapse, "Erin");
});
});
it("should go to login page on logout", () => {
cy.get('[aria-label="User menu"]').click();
// give a change for the outstanding requests queue to settle before logging out
cy.wait(500);
cy.wait(2000);
cy.get(".mx_UserMenu_contextMenu").within(() => {
cy.get(".mx_UserMenu_iconSignOut").click();
@ -94,7 +94,7 @@ describe("Login", () => {
cy.get('[aria-label="User menu"]').click();
// give a change for the outstanding requests queue to settle before logging out
cy.wait(500);
cy.wait(2000);
cy.get(".mx_UserMenu_contextMenu").within(() => {
cy.get(".mx_UserMenu_iconSignOut").click();

View file

@ -122,7 +122,7 @@ describe("Polls", () => {
createPoll(pollParams);
// Wait for message to send, get its ID and save as @pollId
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", pollParams.title)
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", pollParams.title)
.invoke("attr", "data-scroll-tokens").as("pollId");
cy.get<string>("@pollId").then(pollId => {
@ -190,7 +190,7 @@ describe("Polls", () => {
createPoll(pollParams);
// Wait for message to send, get its ID and save as @pollId
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", pollParams.title)
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", pollParams.title)
.invoke("attr", "data-scroll-tokens").as("pollId");
cy.get<string>("@pollId").then(pollId => {

View file

@ -93,7 +93,7 @@ describe("Room Directory", () => {
cy.get(".mx_RoomDirectory_dialogWrapper").percySnapshotElement("Room Directory - filtered no results");
cy.get('.mx_RoomDirectory_dialogWrapper [name="dirsearch"]').type("{selectAll}{backspace}test1234");
cy.get(".mx_RoomDirectory_dialogWrapper").contains(".mx_RoomDirectory_listItem", name)
cy.contains(".mx_RoomDirectory_dialogWrapper .mx_RoomDirectory_listItem", name)
.should("exist").as("resultRow");
cy.get(".mx_RoomDirectory_dialogWrapper").percySnapshotElement("Room Directory - filtered one result");
cy.get("@resultRow").find(".mx_AccessibleButton").contains("Join").click();

View file

@ -293,7 +293,7 @@ describe("Sliding Sync", () => {
]);
cy.contains(".mx_RoomTile", "Reject").click();
cy.get(".mx_RoomView").contains(".mx_AccessibleButton", "Reject").click();
cy.contains(".mx_RoomView .mx_AccessibleButton", "Reject").click();
// wait for the rejected room to disappear
cy.get(".mx_RoomTile").should('have.length', 3);
@ -328,8 +328,8 @@ describe("Sliding Sync", () => {
cy.getClient().then(cli => cli.setRoomTag(roomId, "m.favourite", { order: 0.5 }));
});
cy.get('.mx_RoomSublist[aria-label="Favourites"]').contains(".mx_RoomTile", "Favourite DM").should("exist");
cy.get('.mx_RoomSublist[aria-label="People"]').contains(".mx_RoomTile", "Favourite DM").should("not.exist");
cy.contains('.mx_RoomSublist[aria-label="Favourites"] .mx_RoomTile', "Favourite DM").should("exist");
cy.contains('.mx_RoomSublist[aria-label="People"] .mx_RoomTile', "Favourite DM").should("not.exist");
});
// Regression test for a bug in SS mode, but would be useful to have in non-SS mode too.

View file

@ -83,26 +83,26 @@ describe("Spaces", () => {
cy.get('input[label="Name"]').type("Let's have a Riot");
cy.get('input[label="Address"]').should("have.value", "lets-have-a-riot");
cy.get('textarea[label="Description"]').type("This is a space to reminisce Riot.im!");
cy.get(".mx_AccessibleButton").contains("Create").click();
cy.contains(".mx_AccessibleButton", "Create").click();
});
// Create the default General & Random rooms, as well as a custom "Jokes" room
cy.get('input[label="Room name"][value="General"]').should("exist");
cy.get('input[label="Room name"][value="Random"]').should("exist");
cy.get('input[placeholder="Support"]').type("Jokes");
cy.get(".mx_AccessibleButton").contains("Continue").click();
cy.contains(".mx_AccessibleButton", "Continue").click();
// Copy matrix.to link
cy.get(".mx_SpacePublicShare_shareButton").focus().realClick();
cy.getClipboardText().should("eq", "https://matrix.to/#/#lets-have-a-riot:localhost");
// Go to space home
cy.get(".mx_AccessibleButton").contains("Go to my first room").click();
cy.contains(".mx_AccessibleButton", "Go to my first room").click();
// Assert rooms exist in the room list
cy.get(".mx_RoomList").contains(".mx_RoomTile", "General").should("exist");
cy.get(".mx_RoomList").contains(".mx_RoomTile", "Random").should("exist");
cy.get(".mx_RoomList").contains(".mx_RoomTile", "Jokes").should("exist");
cy.contains(".mx_RoomList .mx_RoomTile", "General").should("exist");
cy.contains(".mx_RoomList .mx_RoomTile", "Random").should("exist");
cy.contains(".mx_RoomList .mx_RoomTile", "Jokes").should("exist");
});
it("should allow user to create private space", () => {
@ -113,7 +113,7 @@ describe("Spaces", () => {
cy.get('input[label="Name"]').type("This is not a Riot");
cy.get('input[label="Address"]').should("not.exist");
cy.get('textarea[label="Description"]').type("This is a private space of mourning Riot.im...");
cy.get(".mx_AccessibleButton").contains("Create").click();
cy.contains(".mx_AccessibleButton", "Create").click();
});
cy.get(".mx_SpaceRoomView_privateScope_meAndMyTeammatesButton").click();
@ -122,20 +122,20 @@ describe("Spaces", () => {
cy.get('input[label="Room name"][value="General"]').should("exist");
cy.get('input[label="Room name"][value="Random"]').should("exist");
cy.get('input[placeholder="Support"]').type("Projects");
cy.get(".mx_AccessibleButton").contains("Continue").click();
cy.contains(".mx_AccessibleButton", "Continue").click();
cy.get(".mx_SpaceRoomView").should("contain", "Invite your teammates");
cy.get(".mx_AccessibleButton").contains("Skip for now").click();
cy.contains(".mx_AccessibleButton", "Skip for now").click();
// Assert rooms exist in the room list
cy.get(".mx_RoomList").contains(".mx_RoomTile", "General").should("exist");
cy.get(".mx_RoomList").contains(".mx_RoomTile", "Random").should("exist");
cy.get(".mx_RoomList").contains(".mx_RoomTile", "Projects").should("exist");
cy.contains(".mx_RoomList .mx_RoomTile", "General").should("exist");
cy.contains(".mx_RoomList .mx_RoomTile", "Random").should("exist");
cy.contains(".mx_RoomList .mx_RoomTile", "Projects").should("exist");
// Assert rooms exist in the space explorer
cy.get(".mx_SpaceHierarchy_list").contains(".mx_SpaceHierarchy_roomTile", "General").should("exist");
cy.get(".mx_SpaceHierarchy_list").contains(".mx_SpaceHierarchy_roomTile", "Random").should("exist");
cy.get(".mx_SpaceHierarchy_list").contains(".mx_SpaceHierarchy_roomTile", "Projects").should("exist");
cy.contains(".mx_SpaceHierarchy_list .mx_SpaceHierarchy_roomTile", "General").should("exist");
cy.contains(".mx_SpaceHierarchy_list .mx_SpaceHierarchy_roomTile", "Random").should("exist");
cy.contains(".mx_SpaceHierarchy_list .mx_SpaceHierarchy_roomTile", "Projects").should("exist");
});
it("should allow user to create just-me space", () => {
@ -155,10 +155,10 @@ describe("Spaces", () => {
cy.get(".mx_SpaceRoomView_privateScope_justMeButton").click();
cy.get(".mx_AddExistingToSpace_entry").click();
cy.get(".mx_AccessibleButton").contains("Add").click();
cy.contains(".mx_AccessibleButton", "Add").click();
cy.get(".mx_RoomList").contains(".mx_RoomTile", "Sample Room").should("exist");
cy.get(".mx_SpaceHierarchy_list").contains(".mx_SpaceHierarchy_roomTile", "Sample Room").should("exist");
cy.contains(".mx_RoomList .mx_RoomTile", "Sample Room").should("exist");
cy.contains(".mx_SpaceHierarchy_list .mx_SpaceHierarchy_roomTile", "Sample Room").should("exist");
});
it("should allow user to invite another to a space", () => {
@ -186,7 +186,7 @@ describe("Spaces", () => {
cy.get(".mx_InviteDialog_other").within(() => {
cy.get('input[type="text"]').type(bot.getUserId());
cy.get(".mx_AccessibleButton").contains("Invite").click();
cy.contains(".mx_AccessibleButton", "Invite").click();
});
cy.get(".mx_InviteDialog_other").should("not.exist");

View file

@ -53,6 +53,7 @@ describe("Threads", () => {
cy.window().should("have.prop", "beforeReload", true);
cy.leaveBeta("Threads");
cy.wait(1000);
// after reload the property should be gone
cy.window().should("not.have.prop", "beforeReload");
});
@ -66,6 +67,7 @@ describe("Threads", () => {
cy.window().should("have.prop", "beforeReload", true);
cy.joinBeta("Threads");
cy.wait(1000);
// after reload the property should be gone
cy.window().should("not.have.prop", "beforeReload");
});
@ -92,7 +94,7 @@ describe("Threads", () => {
cy.get(".mx_RoomView_body .mx_BasicMessageComposer_input").type("Hello Mr. Bot{enter}");
// Wait for message to send, get its ID and save as @threadId
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
.invoke("attr", "data-scroll-tokens").as("threadId");
// Bot starts thread
@ -116,21 +118,21 @@ describe("Threads", () => {
cy.get(".mx_RoomView_body .mx_ThreadSummary .mx_ThreadSummary_content").should("contain", "Test");
// User reacts to message instead
cy.get(".mx_ThreadView .mx_EventTile").contains(".mx_EventTile_line", "Hello there")
cy.contains(".mx_ThreadView .mx_EventTile .mx_EventTile_line", "Hello there")
.find('[aria-label="React"]').click({ force: true }); // Cypress has no ability to hover
cy.get(".mx_EmojiPicker").within(() => {
cy.get('input[type="text"]').type("wave");
cy.get('[role="menuitem"]').contains("👋").click();
cy.contains('[role="menuitem"]', "👋").click();
});
// User redacts their prior response
cy.get(".mx_ThreadView .mx_EventTile").contains(".mx_EventTile_line", "Test")
cy.contains(".mx_ThreadView .mx_EventTile .mx_EventTile_line", "Test")
.find('[aria-label="Options"]').click({ force: true }); // Cypress has no ability to hover
cy.get(".mx_IconizedContextMenu").within(() => {
cy.get('[role="menuitem"]').contains("Remove").click();
cy.contains('[role="menuitem"]', "Remove").click();
});
cy.get(".mx_TextInputDialog").within(() => {
cy.get(".mx_Dialog_primary").contains("Remove").click();
cy.contains(".mx_Dialog_primary", "Remove").click();
});
// User asserts summary was updated correctly
@ -171,7 +173,7 @@ describe("Threads", () => {
cy.get(".mx_RoomView_body .mx_ThreadSummary .mx_ThreadSummary_content").should("contain", "Great!");
// User edits & asserts
cy.get(".mx_ThreadView .mx_EventTile_last").contains(".mx_EventTile_line", "Great!").within(() => {
cy.contains(".mx_ThreadView .mx_EventTile_last .mx_EventTile_line", "Great!").within(() => {
cy.get('[aria-label="Edit"]').click({ force: true }); // Cypress has no ability to hover
cy.get(".mx_BasicMessageComposer_input").type(" How about yourself?{enter}");
});
@ -234,7 +236,7 @@ describe("Threads", () => {
cy.get(".mx_RoomView_body .mx_BasicMessageComposer_input").type("Hello Mr. Bot{enter}");
// Create thread
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
.realHover().find(".mx_MessageActionBar_threadButton").click();
cy.get(".mx_ThreadView_timelinePanelWrapper").should("have.length", 1);
@ -256,7 +258,7 @@ describe("Threads", () => {
cy.get(".mx_RoomView_body .mx_BasicMessageComposer_input").type("Hello Mr. Bot{enter}");
// Create thread
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
.realHover().find(".mx_MessageActionBar_threadButton").click();
cy.get(".mx_ThreadView_timelinePanelWrapper").should("have.length", 1);
@ -268,7 +270,7 @@ describe("Threads", () => {
cy.get(".mx_BaseCard_close").click();
// Open existing thread
cy.get(".mx_RoomView_body .mx_EventTile").contains(".mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
cy.contains(".mx_RoomView_body .mx_EventTile[data-scroll-tokens]", "Hello Mr. Bot")
.realHover().find(".mx_MessageActionBar_threadButton").click();
cy.get(".mx_ThreadView_timelinePanelWrapper").should("have.length", 1);
cy.get(".mx_BaseCard .mx_EventTile").should("contain", "Hello Mr. Bot");

View file

@ -329,7 +329,7 @@ describe("Timeline", () => {
cy.getComposer().type(`${MESSAGE}{enter}`);
// Reply to the message
cy.get(".mx_RoomView_body").contains(".mx_EventTile_line", "Hello world").within(() => {
cy.contains(".mx_RoomView_body .mx_EventTile_line", "Hello world").within(() => {
cy.get('[aria-label="Reply"]').click({ force: true }); // Cypress has no ability to hover
});
};

View file

@ -24,7 +24,7 @@ function assertNoToasts(): void {
}
function getToast(expectedTitle: string): Chainable<JQuery> {
return cy.get(".mx_Toast_toast").contains("h2", expectedTitle).should("exist").closest(".mx_Toast_toast");
return cy.contains(".mx_Toast_toast h2", expectedTitle).should("exist").closest(".mx_Toast_toast");
}
function acceptToast(expectedTitle: string): void {

View file

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

View file

@ -153,7 +153,7 @@ Cypress.Commands.add("openRoomSettings", (tab?: string): Chainable<JQuery<HTMLEl
Cypress.Commands.add("switchTab", (tab: string): Chainable<JQuery<HTMLElement>> => {
return cy.get(".mx_TabbedView_tabLabels").within(() => {
cy.get(".mx_TabbedView_tabLabel").contains(tab).click();
cy.contains(".mx_TabbedView_tabLabel", tab).click();
});
});
@ -162,13 +162,13 @@ Cypress.Commands.add("closeDialog", (): Chainable<JQuery<HTMLElement>> => {
});
Cypress.Commands.add("joinBeta", (name: string): Chainable<JQuery<HTMLElement>> => {
return cy.get(".mx_BetaCard_title").contains(name).closest(".mx_BetaCard").within(() => {
return cy.contains(".mx_BetaCard_title", name).closest(".mx_BetaCard").within(() => {
return cy.get(".mx_BetaCard_buttons").contains("Join the beta").click();
});
});
Cypress.Commands.add("leaveBeta", (name: string): Chainable<JQuery<HTMLElement>> => {
return cy.get(".mx_BetaCard_title").contains(name).closest(".mx_BetaCard").within(() => {
return cy.contains(".mx_BetaCard_title", name).closest(".mx_BetaCard").within(() => {
return cy.get(".mx_BetaCard_buttons").contains("Leave the beta").click();
});
});

View file

@ -426,7 +426,7 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
const { hsUrl, isUrl, hasAccessToken, accessToken, userId, deviceId, isGuest } = await getStoredSessionVars();
if (hasAccessToken && !accessToken) {
abortLogin();
await abortLogin();
}
if (accessToken && userId && hsUrl) {