Skip to content

Commit

Permalink
fix identity manager Visual tests and add to the list (#13)
Browse files Browse the repository at this point in the history
* fix identity manager Visual tests and add to the list

* add more screenshots

* wait for server ready when connecting to deployed app
  • Loading branch information
manolo authored Jan 29, 2025
1 parent 0a27a7c commit 6def259
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 159 deletions.
181 changes: 62 additions & 119 deletions scripts/pit/its/cc-identity-management.js
Original file line number Diff line number Diff line change
@@ -1,143 +1,86 @@
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 = '[email protected]';
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, '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 takeScreenshot(page, __filename, 'role-form');
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('[email protected]');
await page.getByLabel('First Name').fill('Admin');
await page.getByLabel('Last Name').fill('Vaadin');
await page.getByLabel('E-mail Address').fill('[email protected]');
await page.locator('#input-vaadin-checkbox-250').check();

await page.getByLabel('Password', { exact: true }).fill('admin');
await takeScreenshot(page, __filename, 'group-form');
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('[email protected]');
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 takeScreenshot(page, __filename, 'user-form');
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 waitForServerReady(page, 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);
})();
70 changes: 42 additions & 28 deletions scripts/pit/its/cc-install-apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
console.log(`Installing App: ${app} URI: ${uri} Cert: ${cert}`);

const page = await createPage(arg.headless, arg.ignoreHTTPSErrors);
await waitForServerReady(page, arg.url);

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();
Expand All @@ -49,14 +33,44 @@ 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 takeScreenshot(page, __filename, 'application-created');
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);
}

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 takeScreenshot(page, __filename, 'app-1-available');
log(`First application is available\n`);
await expect(page.locator(selector).nth(1)).toBeVisible({ timeout: 180000 });
await takeScreenshot(page, __filename, 'app-2-available');
log(`Second application is available\n`);
await closePage(page);
})();
10 changes: 5 additions & 5 deletions scripts/pit/its/cc-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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()

Expand All @@ -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');

Expand Down
11 changes: 6 additions & 5 deletions scripts/pit/its/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -39,8 +39,8 @@ const args = () => {
}
});
if (!ret.url) {
ret.url = `http://${host}:${port}/`;
}
ret.url = `http://${ret.host}:${ret.port}/`;
}
return ret;
};

Expand All @@ -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`);
Expand Down
4 changes: 2 additions & 2 deletions scripts/pit/lib/lib-ccenter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6def259

Please sign in to comment.