Merge branch 'main' into 21461-excessive-scrollbars-fix
[arvados.git] / services / workbench2 / cypress / support / commands.js
index 135f9cfd6d0c704d2c81c762e5c97479f3f23e94..da7300a43014cbefde2f3edd2842fb61d9aa8c87 100644 (file)
@@ -28,6 +28,7 @@
 // -- This will overwrite an existing command --
 // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
 
+import 'cypress-wait-until';
 import { extractFilesData } from "services/collection-service/collection-service-files-response";
 
 const controllerURL = Cypress.env("controller_url");
@@ -349,10 +350,19 @@ Cypress.Commands.add("updateResource", (token, suffix, uuid, data) => {
 });
 
 Cypress.Commands.add("loginAs", user => {
+    // This shouldn't be necessary unless we need to call loginAs multiple times
+    // in the same test.
     cy.clearCookies();
-    cy.clearLocalStorage();
+    cy.clearAllLocalStorage();
+    cy.clearAllSessionStorage();
     cy.visit(`/token/?api_token=${user.token}`);
-    cy.url({ timeout: 15000 }).should("contain", "/projects/");
+    // Use waitUntil to avoid permafail race conditions with window.location being undefined
+    cy.waitUntil(() => cy.window().then(win =>
+        win?.location?.href &&
+        win.location.href.includes("/projects/")
+    ), { timeout: 15000 });
+    // Wait for page to settle before getting elements
+    cy.waitForDom();
     cy.get("div#root").should("contain", "Arvados Workbench (zzzzz)");
     cy.get("div#root").should("not.contain", "Your account is inactive");
 });