From 4c94155ff02abfc8fe92682f5e834798894478ea Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Thu, 25 Aug 2022 10:46:43 +0100
Subject: [PATCH] Improve Cypress & Percy stability (#9217)

* Improve Cypress & Percy stability

* Update percy snapshot width
---
 cypress/e2e/crypto/crypto.spec.ts     | 8 ++++----
 cypress/e2e/register/register.spec.ts | 3 ++-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/cypress/e2e/crypto/crypto.spec.ts b/cypress/e2e/crypto/crypto.spec.ts
index a829acbd56..d465f0c1e1 100644
--- a/cypress/e2e/crypto/crypto.spec.ts
+++ b/cypress/e2e/crypto/crypto.spec.ts
@@ -58,10 +58,10 @@ const startDMWithBob = function(this: CryptoTestContext) {
 
 const testMessages = function(this: CryptoTestContext) {
     // check the invite message
-    cy.contains(".mx_EventTile_body", "Hey!")
-        .closest(".mx_EventTile")
-        .should("not.have.descendants", ".mx_EventTile_e2eIcon_warning")
-        .should("have.descendants", ".mx_EventTile_receiptSent");
+    cy.contains(".mx_EventTile_body", "Hey!").closest(".mx_EventTile").within(() => {
+        cy.get(".mx_EventTile_e2eIcon_warning").should("not.exist");
+        cy.get(".mx_EventTile_receiptSent").should("exist");
+    });
 
     // Bob sends a response
     cy.get<Room>("@bobsRoom").then((room) => {
diff --git a/cypress/e2e/register/register.spec.ts b/cypress/e2e/register/register.spec.ts
index 5e9cfd3e5f..8d1076f0b7 100644
--- a/cypress/e2e/register/register.spec.ts
+++ b/cypress/e2e/register/register.spec.ts
@@ -37,7 +37,8 @@ describe("Registration", () => {
 
         cy.get(".mx_ServerPicker_change", { timeout: 15000 }).click();
         cy.get(".mx_ServerPickerDialog_continue").should("be.visible");
-        cy.percySnapshot("Server Picker");
+        // Only snapshot the server picker otherwise in the background `matrix.org` may or may not be available
+        cy.get(".mx_Dialog").percySnapshotElement("Server Picker", { widths: [516] });
         cy.checkA11y();
 
         cy.get(".mx_ServerPickerDialog_otherHomeserver").type(synapse.baseUrl);