From 5b23ff2f60c4cee2ed30773b0f51aac2d099459b Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Tue, 28 Jan 2025 11:48:13 +0100 Subject: [PATCH] fix identity manager Visual tests and add to the list --- scripts/pit/its/cc-identity-management.js | 178 +++++++--------------- scripts/pit/its/cc-install-apps.js | 67 ++++---- scripts/pit/its/cc-setup.js | 10 +- scripts/pit/its/test-utils.js | 11 +- scripts/pit/lib/lib-ccenter.sh | 4 +- 5 files changed, 111 insertions(+), 159 deletions(-) diff --git a/scripts/pit/its/cc-identity-management.js b/scripts/pit/its/cc-identity-management.js index c077178a..3b38198c 100644 --- a/scripts/pit/its/cc-identity-management.js +++ b/scripts/pit/its/cc-identity-management.js @@ -1,143 +1,83 @@ -const { chromium } = require('playwright'); -const path = require('path'); -const { expect } = require('@playwright/test'); +const { expect} = require('@playwright/test'); const fs = require('fs'); +const {log, args, createPage, closePage, takeScreenshot, waitForServerReady} = require('./test-utils'); -let headless = false, port = '8000', url, email, pass='Servantes', ignoreHTTPSErrors = false; -process.argv.forEach(a => { - if (/^--headless/.test(a)) { - headless = true; - } else if (/^--port=/.test(a)) { - port = a.split('=')[1]; - } else if (/^--url=/.test(a)) { - url = a.split('=')[1]; - } else if (/^--email=/.test(a)) { - email = a.split('=')[1]; - } else if (/^--pass=/.test(a)) { - pass = a.split('=')[1]; - } else if (/^--notls/.test(a)) { - ignoreHTTPSErrors = true; - } -}); - -if (!email) { - log(`Skipping the setup of Control center because of missing --email= parameter\n`) - return; -} - -const log = s => process.stderr.write(` ${s}`); -const screenshots = "screenshots.out" -let sscount = 0; -async function takeScreenshot(page, name) { - const scr = path.basename(__filename); - const file = `${screenshots}/${scr}-${++sscount}-${name}.png`; - await page.waitForTimeout(1000); - await page.screenshot({ path: file }); - log(`Screenshot taken: ${file}\n`); -} - (async () => { - const browser = await chromium.launch({ - headless: headless, - chromiumSandbox: false, - slowMo: 500 - }); - const context = await browser.newContext({ ignoreHTTPSErrors: ignoreHTTPSErrors }); - - // Open new page - const page = await context.newPage(); - page.on('console', msg => console.log("> CONSOLE:", (msg.text() + ' - ' + msg.location().url).replace(/\s+/g, ' '))); - page.on('pageerror', err => console.log("> PAGEERROR:", ('' + err).replace(/\s+/g, ' '))); + const arg = args(); + if (!arg.login) { + log(`Skipping the setup of Control center because of missing --email= parameter\n`) + process.exit(1); + } + const app = `bakery-cc`; + const role = 'admin'; + const group = 'admin'; + const user = 'admin@vaadin.com'; + const checkboxSelectorRole = `//vaadin-grid-cell-content[.//text()="${role}"]/preceding-sibling::vaadin-grid-cell-content[1]//vaadin-checkbox//input`; + const checkboxSelectorGroup = `//vaadin-grid-cell-content[.//text()="${group}"]/preceding-sibling::vaadin-grid-cell-content[1]//vaadin-checkbox//input`; + const anchorSelectorURL = `//vaadin-grid-cell-content[.//span[normalize-space(text())="${app}"]]//a`; - await page.goto(`${url}`); + const page = await createPage(arg.headless, arg.ignoreHTTPSErrors); + await waitForServerReady(page, arg.url); await expect(page.getByLabel('Email')).toBeVisible(); - await takeScreenshot(page, 'view-loaded'); + await takeScreenshot(page, __filename, 'view-loaded'); - await page.getByLabel('Email').fill(email); - await page.getByLabel('Password').fill(pass); - await page.waitForTimeout(500); + log(`Logging in as ${arg.login} ${arg.pass}...\n`); + await page.getByLabel('Email').fill(arg.login); + await page.getByLabel('Password').fill(arg.pass); await page.getByRole('button', {name: 'Sign In'}).click() - log(`Logging in as ${email} ${pass}...\n`); - await takeScreenshot(page, 'logged-in'); + await takeScreenshot(page, __filename, 'logged-in'); + + await page.getByRole('link', { name: 'Settings', }).click(); + await takeScreenshot(page, __filename, 'settings'); + const url = await page.locator(anchorSelectorURL).getAttribute('href'); + log(`App: ${app} installed in: ${url}\n`); + + await page.locator('vaadin-select vaadin-input-container div').click(); + await page.getByRole('option', { name: 'bakery-cc' }).locator('div').nth(2).click(); + await takeScreenshot(page, __filename, 'selected-app'); + await page.getByRole('link', { name: 'Identity Management' }).click(); + await page.getByRole('button', { name: 'Enable Identity Management' }).click(); + await takeScreenshot(page, __filename, 'app-updated'); + await takeScreenshot(page, __filename, 'identity-management-enabled'); - await page.locator('vaadin-grid').getByText('App1', { exact: true }).click(); await page.getByRole('link', { name: 'Roles' }).click(); await page.getByRole('button', { name: 'Create' }).click(); - await page.getByLabel('Name').fill('ADMIN'); + await page.getByLabel('Name').fill(role); + await page.getByLabel('Description').fill(role); + await takeScreenshot(page, __filename, 'role-filled'); await page.getByRole('contentinfo').getByRole('button', { name: 'Create' }).click(); + await takeScreenshot(page, __filename, 'role-created'); await page.getByRole('link', { name: 'Groups' }).click(); - await page.getByLabel('Name').fill('ADMIN'); - await page.locator('#input-vaadin-checkbox-118').check(); - await page.getByRole('contentinfo').getByRole('button', { name: 'Create' }).click(); - - await page.getByRole('link', { name: 'Users' }).click(); await page.getByRole('button', { name: 'Create' }).click(); - await page.getByLabel('First Name').fill('admin@vaadin.com'); - await page.getByLabel('First Name').fill('Admin'); - await page.getByLabel('Last Name').fill('Vaadin'); - await page.getByLabel('E-mail Address').fill('admin@vaadin.com'); - await page.locator('#input-vaadin-checkbox-250').check(); - - await page.getByLabel('Password', { exact: true }).fill('admin'); + await page.getByLabel('Name').fill(group); + await page.locator(checkboxSelectorRole).click(); + await takeScreenshot(page, __filename, 'group-filled'); await page.getByRole('contentinfo').getByRole('button', { name: 'Create' }).click(); - - - // await page.getByLabel('Identity Management').click() - // await page.locator('vaadin-grid').getByText('App1', { exact: true }).click(); - // await page.getByLabel('Identity Management').check(); - // await page.getByRole('button', { name: 'Update' }).click(); + await takeScreenshot(page, __filename, 'group-created'); await page.getByRole('link', { name: 'Users' }).click(); await page.getByRole('button', { name: 'Create' }).click(); - await page.getByLabel('First Name').fill('admin'); - await page.getByLabel('Last Name').fill('vaadin'); - await page.getByLabel('E-mail Address').fill('admin@vaadin.com'); - await page.getByLabel('Password', { exact: true }).fill('1234....'); - await page.getByRole('contentinfo').getByRole('button', { name: 'Create' }) - - - - - - - - // await page.getByRole('contentinfo').getByRole('button', { name: 'Create' }).click(); - - // await page.goto(`${url}/app/app1/idm/users`); - // await page.getByRole('button', {name: 'Create'}).click() - - // await page.getByLabel('First Name').fill(USER_FIRST_NAME) - // await page.getByLabel('Last Name').fill(USER_LAST_NAME) - // await page.getByLabel('E-mail Address').fill(USER_EMAIL) - // await page.getByLabel('Password', { exact: true }).fill(USER_PASSWORD) - - // await page.locator('.detail-layout').getByRole('button', {name: 'Create'}).click() - - // await expect(await page.getByRole('listitem') - // .filter({ hasText: 'Users'}) - // .textContent()).toEqual('Users1'); - - // await page.goto(`https://app1-local.alcala.org`); - // await page.getByLabel('Email').fill(USER_EMAIL) - // await page.getByLabel('Password', {exact: true}).fill(USER_PASSWORD) - // await page.getByRole('button', {name: 'Sign In'}).click() + await page.getByLabel('First Name').fill(role); + await page.getByLabel('Last Name').fill('user'); + await page.getByLabel('E-mail Address').fill(user); + await page.getByLabel('Password', { exact: true }).fill(role); + await page.locator(checkboxSelectorGroup).click(); + await takeScreenshot(page, __filename, 'user-filled'); + await page.getByRole('contentinfo').getByRole('button', { name: 'Create' }).click(); + await takeScreenshot(page, __filename, 'user-created'); - // await expect(page).toHaveURL(new RegExp('^https://app1-local.alcala.org')); + await page.goto(url); + await takeScreenshot(page, __filename, `app-${app}-loaded`); - // await page.goto(`http://${host}:${port}/app/app1/idm/users`); - // await page.getByText([USER_FIRST_NAME, USER_LAST_NAME].join(' ')).click() - // await page.getByRole('button', {name: 'Delete'}).click() - // await sleep(1000) - // await page.getByRole('button', {name: 'Delete'}).click() - // await sleep(1000) - // await expect(await page.getByRole('listitem') - // .filter({ hasText: 'Users'}) - // .textContent()).toEqual('Users0'); + log(`Logging in ${app} as ${user} ...\n`); + await page.getByLabel('Email').fill(user); + await page.getByLabel('Password').fill(role); + await page.getByRole('button', {name: 'Sign In'}).click() + await takeScreenshot(page, __filename, `logged-in-${app}`); + await expect(page.getByRole('button', { name: 'New order' })).toBeVisible(); - // --------------------- - await context.close(); - await browser.close(); + await closePage(page); })(); diff --git a/scripts/pit/its/cc-install-apps.js b/scripts/pit/its/cc-install-apps.js index 5b990863..0c9de63c 100644 --- a/scripts/pit/its/cc-install-apps.js +++ b/scripts/pit/its/cc-install-apps.js @@ -2,40 +2,24 @@ const { expect} = require('@playwright/test'); const fs = require('fs'); const {log, args, createPage, closePage, takeScreenshot, waitForServerReady} = require('./test-utils'); +const arg = args(); +let count = 0; -(async () => { - const arg = args(); - if (!arg.email) { - log(`Skipping the setup of Control center because of missing --email= parameter\n`) - process.exit(1); - } - - const app = `app1`; +async function installApp(app, page) { const host = arg.url.replace(/^.*:\/\//, '').replace(/\/.*$/, ''); const domain = host.replace(/[^.]+\./, ''); const uri = `${app}.${domain}`; const cert = [ domain, uri ].map(a => `${a}.pem`).filter( a => fs.existsSync(a))[0] - console.log(`Depoying App: ${app} URI: ${uri} Cert: ${cert}`); - - const page = await createPage(arg.headless, arg.ignoreHTTPSErrors); - await waitForServerReady(page, arg.url); + console.log(`Installing App: ${app} URI: ${uri} Cert: ${cert}`); - await expect(page.getByLabel('Email')).toBeVisible(); - await takeScreenshot(page, __filename, 'view-loaded'); - - await page.getByLabel('Email').fill(arg.email); - await page.getByLabel('Password').fill(arg.pass); - await page.waitForTimeout(500); - await page.getByRole('button', {name: 'Sign In'}).click() - log(`Logging in as ${arg.email} ${arg.pass}...\n`); - await takeScreenshot(page, __filename, 'logged-in'); + await takeScreenshot(page, __filename, `page-loaded-${app}`); await page.getByRole('listitem').filter({ hasText: 'Settings'}).click() await page.getByRole('button', {name: 'Deploy'}).click() - await takeScreenshot(page, __filename, 'form-opened'); + await takeScreenshot(page, __filename, `form-opened-${app}`); await page.getByLabel('Application Name', {exact: true}).fill(app) - await page.getByLabel('Image', {exact: true}).fill('k8sdemos/bakery-cc:latest') + await page.getByLabel('Image', {exact: true}).fill(`k8sdemos/${app}:latest`) await page.getByLabel('Application URI', {exact: true}).locator('input[type="text"]').fill(uri) if (cert) { await page.getByLabel('Upload').click(); @@ -49,14 +33,41 @@ const {log, args, createPage, closePage, takeScreenshot, waitForServerReady} = r await page.locator('.detail-layout').getByRole('button', {name: 'Deploy'}).click(); } - await takeScreenshot(page, __filename, 'form-filled'); + await takeScreenshot(page, __filename, `form-filled-${app}`); + await page.getByRole('listitem').filter({ hasText: 'Settings'}).click() - await expect(await page.getByRole('listitem') - .filter({ hasText: 'Applications'}) - .textContent()).toEqual('Applications1'); + await takeScreenshot(page, __filename, `application-created-${app}`); + + await expect(page.locator('vaadin-grid').getByText(app, { exact: true })).toBeVisible(); + await expect(await page.getByRole('listitem').filter({ hasText: 'Applications'}) + .textContent()).toEqual(`Applications${++count}`); +} + +(async () => { + if (!arg.login) { + log(`Skipping the setup of Control center because of missing --email= parameter\n`) + process.exit(1); + } + const page = await createPage(arg.headless, arg.ignoreHTTPSErrors); + await waitForServerReady(page, arg.url); + await takeScreenshot(page, __filename, 'view-loaded'); + + log(`Logging in as ${arg.login} ${arg.pass}...\n`); + await page.getByLabel('Email').fill(arg.login); + await page.getByLabel('Password').fill(arg.pass); + await page.waitForTimeout(500); + await page.getByRole('button', {name: 'Sign In'}).click() + await takeScreenshot(page, __filename, 'logged-in'); + + for (const app of ['bakery-cc', 'bakery']) { + await installApp(app, page); + } - await takeScreenshot(page, __filename, 'application-created'); + log(`Waiting for the applications to be available...\n`); + const selector = 'vaadin-grid-cell-content span[theme="badge success"]'; + await expect(page.locator(selector).nth(0)).toBeVisible({ timeout: 180000 }); + await expect(page.locator(selector).nth(1)).toBeVisible({ timeout: 180000 }); await closePage(page); })(); diff --git a/scripts/pit/its/cc-setup.js b/scripts/pit/its/cc-setup.js index d1d29d8d..ceb04c28 100644 --- a/scripts/pit/its/cc-setup.js +++ b/scripts/pit/its/cc-setup.js @@ -3,7 +3,7 @@ const {log, run, args, createPage, closePage, takeScreenshot, waitForServerReady (async () => { const arg = args(); - if (!arg.email) { + if (!arg.login) { log(`Skipping the setup of Control center because of missing --email= parameter\n`) process.exit(1); } @@ -20,8 +20,8 @@ const {log, run, args, createPage, closePage, takeScreenshot, waitForServerReady await expect(page.getByLabel('Email')).toBeVisible(); await takeScreenshot(page, __filename, 'view-after-loaded'); - log(`login with user ${arg.email} and password ${arg.tmppass}`); - await page.getByLabel('Email').fill(arg.email); + log(`login with user ${arg.login} and password ${arg.tmppass}`); + await page.getByLabel('Email').fill(arg.login); await page.getByLabel('Password').fill(arg.tmppass); await page.getByRole('button', {name: 'Sign In'}).click() @@ -33,8 +33,8 @@ const {log, run, args, createPage, closePage, takeScreenshot, waitForServerReady await takeScreenshot(page, __filename, 'password-changed'); - await page.getByLabel('First Name').fill(arg.email); - await page.getByLabel('Last Name').fill(arg.email); + await page.getByLabel('First Name').fill(arg.login); + await page.getByLabel('Last Name').fill(arg.login); await page.getByRole('button', { name: 'Submit' }).click(); await takeScreenshot(page, __filename, 'user-configured'); diff --git a/scripts/pit/its/test-utils.js b/scripts/pit/its/test-utils.js index 78d5e54b..7a585be9 100644 --- a/scripts/pit/its/test-utils.js +++ b/scripts/pit/its/test-utils.js @@ -28,8 +28,8 @@ const args = () => { ret.port = a.split('=')[1]; } else if (/^--url=/.test(a)) { ret.url = a.split('=')[1]; - } else if (/^--email=/.test(a)) { - ret.email = a.split('=')[1]; + } else if (/^--login=/.test(a)) { + ret.login = a.split('=')[1]; } else if (/^--pass=/.test(a)) { ret.pass = a.split('=')[1]; } else if (/^--tmppass=/.test(a)) { @@ -39,8 +39,8 @@ const args = () => { } }); if (!ret.url) { - ret.url = `http://${host}:${port}/`; - } + ret.url = `http://${ret.host}:${ret.port}/`; + } return ret; }; @@ -66,7 +66,8 @@ const screenshots = "screenshots.out" let sscount = 0; async function takeScreenshot(page, name, descr) { const scr = path.basename(name); - const file = `${screenshots}/${scr}-${++sscount}-${descr}.png`; + const cnt = String(++sscount).padStart(2, "0"); + const file = `${screenshots}/${scr}-${cnt}-${descr}.png`; await page.waitForTimeout(1000); await page.screenshot({ path: file }); log(`Screenshot taken: ${file}\n`); diff --git a/scripts/pit/lib/lib-ccenter.sh b/scripts/pit/lib/lib-ccenter.sh index 65c5beab..47016a7a 100644 --- a/scripts/pit/lib/lib-ccenter.sh +++ b/scripts/pit/lib/lib-ccenter.sh @@ -19,7 +19,7 @@ CC_CLUSTER=cc-cluster CC_NS=control-center ## UI tests to run after the control-center is installed -CC_TESTS="cc-setup.js cc-install-apps.js" +CC_TESTS="cc-setup.js cc-install-apps.js cc-identity-management.js" checkDockerRunning() { if ! docker ps > /dev/null 2>&1; then @@ -138,7 +138,7 @@ runPwTests() { [ -n "$SKIPPW" ] && return 0 [ -z "$CC_CERT" -o -z "$CC_KEY" ] && NO_TLS=--notls || NO_TLS="" for f in $CC_TESTS; do - runPlaywrightTests "$PIT_SCR_FOLDER/its/$f" "" "prod" "control-center" --url=https://$CC_CONTROL --email=$CC_EMAIL $NO_TLS || return 1 + runPlaywrightTests "$PIT_SCR_FOLDER/its/$f" "" "prod" "control-center" --url=https://$CC_CONTROL --login=$CC_EMAIL $NO_TLS || return 1 sleep 3 done }