Skip to content

Commit

Permalink
check that app is running before enabling features, and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
manolo committed Jan 29, 2025
1 parent af678bb commit 683655e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 29 deletions.
50 changes: 40 additions & 10 deletions scripts/pit/its/cc-identity-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,28 @@ const {log, args, createPage, closePage, takeScreenshot, waitForServerReady} = r
await page.getByRole('button', {name: 'Sign In'}).click()
await takeScreenshot(page, __filename, 'logged-in');

log(`Changing Settings for ${app}...\n`);
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`);

log(`Checking that ${app} installed in ${url} is running ...\n`);
// When app is not running, localization cannot be enabled
let pageApp = await createPage(arg.headless, arg.ignoreHTTPSErrors);
await waitForServerReady(pageApp, url);
await closePage(pageApp);
await takeScreenshot(page, __filename, 'app-running');

log(`Enabling identity Management ...\n`);
await page.locator('vaadin-select vaadin-input-container div').click();
await page.getByRole('option', { name: app }).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, 'enabled');
await takeScreenshot(page, __filename, 'identity-enabled');

log(`Adding Role, Group and User ...\n`);
await page.getByRole('link', { name: 'Roles' }).click();
await page.getByRole('button', { name: 'Create' }).click();
await takeScreenshot(page, __filename, 'role-form');
Expand Down Expand Up @@ -69,15 +79,35 @@ const {log, args, createPage, closePage, takeScreenshot, waitForServerReady} = r
await page.getByRole('contentinfo').getByRole('button', { name: 'Create' }).click();
await takeScreenshot(page, __filename, 'user-created');

await waitForServerReady(page, url);
await takeScreenshot(page, __filename, `app-${app}-loaded`);

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();
pageApp = await createPage(arg.headless, arg.ignoreHTTPSErrors);
await waitForServerReady(pageApp, url);
await takeScreenshot(pageApp, __filename, `app-${app}-loaded`);
await pageApp.getByLabel('Email').fill(user);
await pageApp.getByLabel('Password').fill(role);
await pageApp.getByRole('button', {name: 'Sign In'}).click()
await takeScreenshot(pageApp, __filename, `logged-in-${app}`);
await expect(pageApp.getByRole('button', { name: 'New order' })).toBeVisible();
await closePage(pageApp);

log('Cleaning up...\n');
await page.getByRole('link', { name: 'Roles' }).click();
await page.getByText('admin').nth(1).click();
await page.getByRole('button', { name: 'Delete' }).click();
await page.getByRole('button', { name: 'Delete' }).nth(0).click();
await page.getByRole('link', { name: 'Groups' }).click();
await page.getByText('admin', { exact: true }).click();
await page.getByRole('button', { name: 'Delete' }).click();
await page.getByRole('button', { name: 'Delete' }).nth(0).click();
await page.getByRole('link', { name: 'Users' }).click();
await page.getByText('admin user').click();
await page.getByRole('button', { name: 'Delete' }).click();
await page.getByRole('button', { name: 'Delete' }).nth(0).click();
await page.getByRole('link', { name: 'Settings' }).click();
await page.locator('vaadin-grid').getByText('bakery-cc', { exact: true }).click();
await page.getByLabel('Identity Management').uncheck();
await page.getByRole('button', { name: 'Disable' }).click();
await page.getByRole('button', { name: 'Update' }).click();

await closePage(page);
})();
41 changes: 31 additions & 10 deletions scripts/pit/its/cc-localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,27 @@ const { assert } = require('console');
await page.getByRole('button', {name: 'Sign In'}).click()
await takeScreenshot(page, __filename, 'logged-in');

log(`Changing Settings for ${app}...\n`);
await page.getByRole('link', { name: 'Settings', }).click();
await takeScreenshot(page, __filename, 'settings');
const anchorSelectorURL = `//vaadin-grid-cell-content[.//span[normalize-space(text())="${app}"]]//a`;
const url = await page.locator(anchorSelectorURL).getAttribute('href');
const previewUrl = url.replace(/:\/\//, '://preview.');
log(`App: ${app} installed in: ${url} preview: ${previewUrl}\n`);

log(`Checking that ${app} installed in ${url} is running ...\n`);
// When app is not running, localization cannot be enabled
const pageApp = await createPage(arg.headless, arg.ignoreHTTPSErrors);
await waitForServerReady(pageApp, url);
await closePage(pageApp);

log(`Uploading and updating localization keys ...\n`);
await page.locator('vaadin-select vaadin-input-container div').click();
await page.getByRole('option', { name: app }).locator('div').nth(2).click();
await takeScreenshot(page, __filename, 'selected-app');

await page.getByRole('link', { name: 'Localization' }).click();
await page.getByRole('button', { name: 'Enable Localization' }).click();
await takeScreenshot(page, __filename, 'enabled');
await takeScreenshot(page, __filename, 'localization-screen');

fs.writeFileSync(propsFile, 'app.title=Bakery\n');
await page.getByLabel('Manage translations').locator('svg').click();
Expand All @@ -54,10 +61,13 @@ const { assert } = require('console');
await page.getByRole('button', { name: 'Replace data' }).click();
fs.unlinkSync(propsFile);

await takeScreenshot(page, __filename, 'localization-loaded');
await page.getByText('Bakery', { exact: true }).click();
await page.locator('vaadin-text-area.inline textarea').fill('Panaderia');
await page.locator('vaadin-grid').getByRole('button').first().click();
await takeScreenshot(page, __filename, 'localization-changed');

log(`Downloading and checking localization keys ...\n`);
await page.getByLabel('Manage translations').locator('svg').click();
const downloadPromise = page.waitForEvent('download');
await page.getByText('Download translations').click();
Expand All @@ -70,19 +80,30 @@ const { assert } = require('console');
assert(str.includes('app.title=Panaderia'));
await fs.rmdirSync(downloadsDir, { recursive: true });

log(`Testing that preview page: ${previewUrl} is up and running\n`);
await page.getByRole('button', { name: 'Start preview' }).click();

log(`Logging in Preview CC as ${user} ${password}...\n`);
const pagePrev = await createPage(arg.headless, true);
await waitForServerReady(pagePrev, previewUrl);
await pagePrev.getByLabel('Email').fill(user);
await pagePrev.getByLabel('Password').fill(password);
await pagePrev.getByRole('button', {name: 'Sign In'}).click()
await takeScreenshot(pagePrev, __filename, 'preview-logged-in');
await expect(pagePrev.getByRole('button', { name: 'New order' })).toBeVisible();
await takeScreenshot(page, __filename, 'preview-ready');
const text = await pagePrev.getByText(/Password|Dashboard/).textContent();
if (text.includes('Password')) {
await pagePrev.getByLabel('Email').fill(user);
await pagePrev.getByLabel('Password').fill(password);
await pagePrev.getByRole('button', {name: 'Sign In'}).click()
await takeScreenshot(pagePrev, __filename, 'preview-logged-in');
await expect(pagePrev.getByRole('button', { name: 'New order' })).toBeVisible();
await takeScreenshot(page, __filename, 'preview-loaded');
}
await expect(pagePrev.getByText('Panaderia', { exact: true })).toBeVisible();
await closePage(pagePrev);

log('Cleaning up...\n');
await page.getByRole('button', { name: 'Stop preview' }).click();
await page.getByRole('link', { name: 'Settings' }).click();
await page.locator('vaadin-grid').getByText('bakery-cc', { exact: true }).click();
await page.getByLabel('Localization').uncheck();
await page.getByRole('button', { name: 'Disable' }).click();
await page.getByRole('button', { name: 'Update' }).click();

await closePage(pagePrev);
await closePage(page);
})();
29 changes: 20 additions & 9 deletions scripts/pit/its/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ defineConfig({
expect: {timeout: 30 * 1000},
});

const log = (s) => process.stderr.write(` ${s}`);
function log(...args) {
process.stderr.write(`\x1b[0m> \x1b[0;32m${args}\x1b[0m`);
}
function out(...args) {
process.stderr.write(`\x1b[2m\x1b[196m${args}\x1b[0m`);
}
function err(...args) {
process.stderr.write(`\x1b[0;31m${args}\x1b[0m`);
}

const run = async (cmd) => (await promisify(exec)(cmd)).stdout;


const args = () => {
const ret = {
headless: false,
Expand Down Expand Up @@ -52,8 +62,8 @@ async function createPage(headless, ignoreHTTPSErrors) {
});
const context = await browser.newContext({ignoreHTTPSErrors: ignoreHTTPSErrors });
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, ' ')));
page.on('console', msg => out("> CONSOLE:", (msg.text() + ' - ' + msg.location().url).replace(/\s+/g, ' ')));
page.on('pageerror', err => err("> PAGEERROR:", ('' + err).replace(/\s+/g, ' ')));
page.browser = browser;
return page;
}
Expand All @@ -70,7 +80,7 @@ async function takeScreenshot(page, name, descr) {
const file = `${screenshots}/${scr}-${cnt}-${descr}.png`;
await page.waitForTimeout(1000);
await page.screenshot({ path: file });
log(`Screenshot taken: ${file}\n`);
out(`Screenshot taken: ${file}\n`);
}

// Wait for the server to be ready and to get a valid response
Expand All @@ -86,25 +96,26 @@ async function waitForServerReady(page, url, options = {}) {
const response = await page.goto(url);
// Check if the response status is not 503
if (response && response.status() < 400) {
log(`Attempt ${attempt} Server is ready and returned a valid response. ${response.status()}\n`);
out(`Attempt ${attempt} Server is ready and returned a valid response. ${response.status()}\n`);
return response;
} else {
log(`Attempt ${attempt} Server is not ready yet. ${response.status()}\n`);
out(`Attempt ${attempt} Server is not ready yet. ${response.status()}\n`);
}
} catch (error) {
if (error.message.includes('net::ERR_CERT_AUTHORITY_INVALID')) {
log(`Attempt ${attempt} Server has not a valid certificate, install it for ${url} or use --notls flag\n`);
err(`Attempt ${attempt} Server has not a valid certificate, install it for ${url} or use --notls flag\n`);
} else {
log(`Attempt ${attempt} Server failed with error: ${error.message}\n`);
err(`Attempt ${attempt} Server failed with error: ${error.message}\n`);
}
throw new Error(`Server Error ${error}.\n`);
}
await page.waitForTimeout(retryInterval);
}
throw new Error(`Server did not become ready after ${maxRetries} attempts.\n`);
}

module.exports = {
log,
log, out, err,
run,
args,
createPage,
Expand Down

0 comments on commit 683655e

Please sign in to comment.