X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/46fe1e60a1cd96a39163911edd821b3e316ca606..e3155febbe9e476d320b0b14be3e8efa2030b57b:/services/workbench2/cypress/support/commands.js diff --git a/services/workbench2/cypress/support/commands.js b/services/workbench2/cypress/support/commands.js index 135f9cfd6d..05664e6b30 100644 --- a/services/workbench2/cypress/support/commands.js +++ b/services/workbench2/cypress/support/commands.js @@ -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"); @@ -181,11 +182,11 @@ Cypress.Commands.add("createWorkflow", (token, data) => { }); }); -Cypress.Commands.add("createCollection", (token, data) => { +Cypress.Commands.add("createCollection", (token, data, keep = false) => { return cy.createResource(token, "collections", { collection: JSON.stringify(data), ensure_unique_name: true, - }); + }, keep); }); Cypress.Commands.add("getCollection", (token, uuid) => { @@ -320,16 +321,19 @@ Cypress.Commands.add("getResource", (token, suffix, uuid) => { }); }); -Cypress.Commands.add("createResource", (token, suffix, data) => { +Cypress.Commands.add("createResource", (token, suffix, data, keep = false) => { return cy .doRequest("POST", "/arvados/v1/" + suffix, data, null, token, true) .its("body") .then(function (resource) { - createdResources.push({ suffix, uuid: resource.uuid }); + if (! keep) { + createdResources.push({ suffix, uuid: resource.uuid }); + }; return resource; }); }); + Cypress.Commands.add("deleteResource", (token, suffix, uuid, failOnStatusCode = true) => { return cy .doRequest("DELETE", "/arvados/v1/" + suffix + "/" + uuid, null, null, token, false, true, failOnStatusCode) @@ -349,10 +353,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"); }); @@ -484,7 +497,7 @@ function b64toBlob(b64Data, contentType = "", sliceSize = 512) { // From https://github.com/cypress-io/cypress/issues/7306#issuecomment-1076451070= // This command requires the async package (https://www.npmjs.com/package/async) Cypress.Commands.add("waitForDom", () => { - cy.window().then( + cy.window({ timeout: 10000 }).then( { // Don't timeout before waitForDom finishes timeout: 10000,