From 2c80bf597ef004fcf2e130817d93a883fe846797 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Fri, 30 Jul 2021 20:12:32 +0200 Subject: [PATCH] Run Cypress tests on Keycloak theme (#925) --- .github/workflows/cypress.yml | 75 +++++++++---------- .../integration/identity_providers.spec.ts | 5 +- cypress/support/index.js | 7 +- cypress/support/util/AdminClient.ts | 2 +- 4 files changed, 46 insertions(+), 43 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 601e59dcde..87fcf5eb34 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -1,53 +1,50 @@ -name: Cypress run - +name: Cypress on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] - + branches: [master] jobs: cypress-run: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [16.x] - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - check-latest: true + - uses: actions/checkout@v2 - - run: npm ci - - run: npm run build + - name: Build Keycloak server + run: docker build --tag keycloak . - - name: Run Keycloak - run: ./start.mjs & sleep 40 + - name: Start Keycloak server + run: | + docker run --detach --publish 8080:8080 --env KEYCLOAK_USER=admin --env KEYCLOAK_PASSWORD=admin --name keycloak keycloak + sleep 10 - - name: Run Admin Console - run: npx http-server ./build -P http://localhost:8180/ & sleep 30 + - name: Configure Keycloak server + run: | + docker exec keycloak /opt/jboss/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080/auth --realm master --user admin --password admin + docker exec keycloak /opt/jboss/keycloak/bin/kcadm.sh update realms/master -s "adminTheme=keycloak.v2" - - name: Admin Console client - run: ./import.mjs + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: 16 + check-latest: true - - name: Cypress run - run: npm run start:cypress-tests + - name: Install dependencies + run: npm ci - - name: Add Cypress videos artifacts - uses: actions/upload-artifact@v2 - if: failure() - with: - name: cypress-videos - path: assets/videos + - name: Run Cypress + run: CYPRESS_BASE_URL=http://localhost:8080/auth/admin/ CYPRESS_KEYCLOAK_SERVER=http://localhost:8080 npm run start:cypress-tests - - name: Add Cypress screenshots artifacts - uses: actions/upload-artifact@v2 - if: failure() - with: - name: cypress-screenshots - path: assets/screenshots \ No newline at end of file + - name: Add Cypress videos artifacts + uses: actions/upload-artifact@v2 + if: failure() + with: + name: cypress-videos + path: assets/videos + + - name: Add Cypress screenshots artifacts + uses: actions/upload-artifact@v2 + if: failure() + with: + name: cypress-screenshots + path: assets/screenshots diff --git a/cypress/integration/identity_providers.spec.ts b/cypress/integration/identity_providers.spec.ts index 7f8facc641..35a005c632 100644 --- a/cypress/integration/identity_providers.spec.ts +++ b/cypress/integration/identity_providers.spec.ts @@ -97,12 +97,13 @@ describe("Identity provider test", () => { it("should create a oidc provider using discovery url", () => { const oidcProviderName = "oidc"; + const keycloakServer = Cypress.env("KEYCLOAK_SERVER"); createProviderPage .clickCreateDropdown() .clickItem(oidcProviderName) .fillDiscoveryUrl( - "http://localhost:8180/auth/realms/master/.well-known/openid-configuration" + `${keycloakServer}/auth/realms/master/.well-known/openid-configuration` ) .shouldBeSuccessful() .fill("oidc", "123") @@ -112,7 +113,7 @@ describe("Identity provider test", () => { ); createProviderPage.shouldHaveAuthorizationUrl( - "http://localhost:8180/auth/realms/master/protocol/openid-connect/auth" + `${keycloakServer}/auth/realms/master/protocol/openid-connect/auth` ); }); diff --git a/cypress/support/index.js b/cypress/support/index.js index d68db96df2..3bfd6d1f36 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -14,7 +14,12 @@ // *********************************************************** // Import commands.js using ES2015 syntax: -import './commands' +import "./commands"; // Alternatively you can use CommonJS syntax: // require('./commands') + +// Set Keycloak server to development path if not set. +if (!Cypress.env("KEYCLOAK_SERVER")) { + Cypress.env("KEYCLOAK_SERVER", "http://localhost:8180"); +} diff --git a/cypress/support/util/AdminClient.ts b/cypress/support/util/AdminClient.ts index 9c6b3c238a..8c6a0a8ca5 100644 --- a/cypress/support/util/AdminClient.ts +++ b/cypress/support/util/AdminClient.ts @@ -6,7 +6,7 @@ export default class AdminClient { private client: KeycloakAdminClient; constructor() { this.client = new KeycloakAdminClient({ - baseUrl: "http://localhost:8180/auth", + baseUrl: `${Cypress.env("KEYCLOAK_SERVER")}/auth`, realmName: "master", }); }