From 297cb4677b957e85bcf8f01ee163e1dc45e6ad1a Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Thu, 24 Feb 2022 16:47:06 +0100 Subject: [PATCH] Allow access to clipboard in Cypress tests (#2147) --- .../manage/clients/AuthorizationTab.ts | 2 ++ cypress/support/util/grantClipboardAccess.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 cypress/support/util/grantClipboardAccess.ts diff --git a/cypress/support/pages/admin_console/manage/clients/AuthorizationTab.ts b/cypress/support/pages/admin_console/manage/clients/AuthorizationTab.ts index a4a700084a..e5f180614a 100644 --- a/cypress/support/pages/admin_console/manage/clients/AuthorizationTab.ts +++ b/cypress/support/pages/admin_console/manage/clients/AuthorizationTab.ts @@ -1,6 +1,7 @@ import type PolicyRepresentation from "@keycloak/keycloak-admin-client/lib/defs/policyRepresentation"; import type ResourceRepresentation from "@keycloak/keycloak-admin-client/lib/defs/resourceRepresentation"; import type ScopeRepresentation from "@keycloak/keycloak-admin-client/lib/defs/scopeRepresentation"; +import grantClipboardAccess from "../../../../util/grantClipboardAccess"; type PermissionType = "resource" | "scope"; @@ -133,6 +134,7 @@ export default class AuthorizationTab { } copy() { + grantClipboardAccess(); cy.findByTestId(this.exportCopyButton).click(); return this; } diff --git a/cypress/support/util/grantClipboardAccess.ts b/cypress/support/util/grantClipboardAccess.ts new file mode 100644 index 0000000000..daf2ebeada --- /dev/null +++ b/cypress/support/util/grantClipboardAccess.ts @@ -0,0 +1,13 @@ +export default function grantClipboardAccess() { + // Use the Chrome debugger protocol to grant access to the clipboard. + // https://chromedevtools.github.io/devtools-protocol/tot/Browser/#method-grantPermissions + cy.wrap( + Cypress.automation("remote:debugger:protocol", { + command: "Browser.grantPermissions", + params: { + permissions: ["clipboardReadWrite", "clipboardSanitizedWrite"], + origin: window.location.origin, + }, + }) + ); +}