Skip to content

Commit 94d9dca

Browse files
authored
feat: more versatile options for the control-center (#25)
* feat: more versatile options for the control-center * reduce presets * detect better whether CC chart is installed * remove redundant parameters that can be done by using CC_TESTS env var * show which version of CC is using the app
1 parent 72905b9 commit 94d9dca

15 files changed

+498
-160
lines changed

CC.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
## Usage examples for PiT tests in control-center
3+
4+
##### Run proxy
5+
./scripts/pit/run.sh --proxy
6+
7+
##### Delete cluster in DO
8+
./scripts/pit/run.sh --proxy --delete --vendor=do
9+
10+
##### Install cluster and helm chart for a specific CC version
11+
./scripts/pit/run.sh --starters=control-center --keep-cc \
12+
--cc-version=1.3.0-beta2 \
13+
--skip-pw
14+
15+
##### Compile apps and CC for a specific platform version, and load local images in cluster
16+
./scripts/pit/run.sh --starters=control-center --keep-cc \
17+
--version=24.8.0.beta2 \
18+
--skip-current \
19+
--skip-helm \
20+
--skip-pw
21+
22+
##### Push local images to docker central (need to be build as above)
23+
CCPUSH=true \
24+
./scripts/pit/run.sh --starters=control-center --keep-cc \
25+
--version=24.8.0.beta2 \
26+
--skip-current \
27+
--skip-build \
28+
--skip-helm \
29+
--skip-pw
30+
31+
./scripts/pit/run.sh --function pushLocalToDockerhub next
32+
33+
##### Install test apps and run tests for new version (needs to have everything set as above)
34+
./scripts/pit/run.sh --starters=control-center --keep-cc \
35+
--version=24.8.0.beta2 \
36+
--skip-current \
37+
--skip-build \
38+
--skip-helm \
39+
--keep-apps \
40+
--headed
41+
42+
##### Run browser tests without headed slow-motion
43+
FAST=true \
44+
./scripts/pit/run.sh --starters=control-center --keep-cc \
45+
--version=24.8.0.beta2 \
46+
--skip-current \
47+
--skip-build \
48+
--skip-helm \
49+
--keep-apps \
50+
--headed
51+
52+
##### Remove tests apps from CC
53+
CC_TESTS=cc-remove-apps.js \
54+
./scripts/pit/run.sh --starters=control-center --keep-cc \
55+
--offline \
56+
--skip-setup \
57+
--headed
58+
59+
##### Create a cluster in DO with latest version of CC, compile apps and deploy then
60+
FAST=true ./scripts/pit/run.sh \
61+
--starters=control-center --keep-cc --version=24.8.0.beta2 --headed --skip-current --vendor=do
62+
63+
64+
65+
66+
67+
68+
69+

README.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
# [Platform-In-Test Script]
2-
3-
# How To Use
4-
5-
```
6-
./scripts/pit/run.sh --help
7-
```
8-
9-
```
101
Use: ./scripts/pit/run.sh with the next options:
112

123
--version=string Vaadin version to test, if not given it only tests current stable, otherwise it runs tests against current stable and then against given version.
@@ -23,13 +14,15 @@ Use: ./scripts/pit/run.sh with the next options:
2314
--skip-prod Skip production validations
2415
--skip-dev Skip dev-mode validations
2516
--skip-clean Do not clean maven cache
26-
--skip-helm Do not re-install control-center with helm and continue running tests, implies (--offline, --skip-build, --keep-cc)
17+
--skip-helm Do not re-install control-center with helm and continue running tests, implies (--offline, --keep-cc)
2718
--skip-pw Do not run playwright tests
2819
--cluster=name Run tests in an existing k8s cluster
2920
--vendor=name Use a specific cluster vendor to run control-center tests options: [dd, kind, do] (default: kind)
3021
--keep-cc Keep control-center running after tests
22+
--keep-apps Keep installed apps in control-center, implies --keep-cc
3123
--proxy-cc Forward port 443 from k8s cluster to localhost
3224
--events-cc Display events from control-center
25+
--cc-version Install this version for current
3326
--skip-build Skip building the docker images for control-center
3427
--delete-cluster Delete the cluster/s
3528
--dashboard=* Install kubernetes dashboard, options [install, uninstall] (default: install)
@@ -113,7 +106,4 @@ Use: ./scripts/pit/run.sh with the next options:
113106
· designer-tutorial
114107
· walking-skeleton:v24.7-hybrid
115108
· releases-graph
116-
```
117-
118-
119-
109+
· expo-flow

scripts/pit/its/cc-identity-management.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const {log, err, args, createPage, closePage, takeScreenshot, waitForServerReady
112112
await pageApp.getByRole('button', {name: 'Sign In'}).click()
113113
await takeScreenshot(pageApp, __filename, `logged-in-${app}`);
114114
await expect(pageApp.getByRole('button', { name: 'New order' })).toBeVisible();
115+
await closePage(pageApp);
115116

116117
log('Cleaning up...\n');
117118
try {
@@ -142,13 +143,13 @@ const {log, err, args, createPage, closePage, takeScreenshot, waitForServerReady
142143
await page.getByLabel('Replicas').fill('1');
143144
await page.getByRole('button', { name: 'Update' }).click();
144145

145-
await pageApp.waitForTimeout(30000);
146+
pageApp = await createPage(arg.headless, arg.ignoreHTTPSErrors);
146147
await waitForServerReady(pageApp, appUrl);
147148
await takeScreenshot(pageApp, __filename, 'app-after-cleanup');
148149
} catch (error) {
149150
err(`Error cleaning up: ${error}\n`);
150151
await takeScreenshot(page, __filename, 'error-cleaning');
151152
}
152-
await closePage(pageApp);
153153
await closePage(page);
154+
await closePage(pageApp);
154155
})();

scripts/pit/its/cc-install-apps.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
const { expect} = require('@playwright/test');
22
const fs = require('fs');
3-
const {log, err, args, run, createPage, closePage, takeScreenshot, waitForServerReady} = require('./test-utils');
3+
const {log, args, run, createPage, closePage, takeScreenshot, waitForServerReady} = require('./test-utils');
44

55
const arg = args();
66
let count = 0;
7+
const gracePeriodSecs = 90;
8+
const waitForReadyMsecs = 185000;
79

810
async function installApp(app, page) {
911
const host = arg.url.replace(/^.*:\/\//, '').replace(/\/.*$/, '');
@@ -12,7 +14,7 @@ async function installApp(app, page) {
1214
const cert = [ domain, uri ].map(a => `${a}.pem`).filter( a => fs.existsSync(a))[0]
1315
const tag = arg.tag || 'latest';
1416
const registry = arg.registry || 'k8sdemos';
15-
console.log(`Installing App: ${app} URI: ${uri} Cert: ${cert}`);
17+
log(`Installing App: ${app} URI: ${uri} Cert: ${cert} Img: ${registry}/${app}:${tag}`);
1618

1719
await page.getByRole('listitem').filter({ hasText: 'Settings'}).click()
1820
await page.getByRole('button', {name: /Create|New/}).click()
@@ -25,8 +27,20 @@ async function installApp(app, page) {
2527
await page.getByPlaceholder('Image Pull Secret').locator('input').fill(arg.secret);
2628
await takeScreenshot(page, __filename, `form-with-secret-${app}`);
2729
}
28-
await page.getByLabel('Startup Delay (secs)').fill(process.env.GITHUB_ACTIONS ? '90' : '90');
30+
await page.getByLabel('Startup Delay (secs)').fill(`${gracePeriodSecs}`);
31+
32+
await page.getByRole('button', {name: 'Environment Variable'}).click();
33+
await takeScreenshot(page, __filename, `env-dialog-opened-${app}`);
34+
35+
const envDialog = page.getByRole('dialog', { name: 'Environment Variables' });
36+
await envDialog.getByPlaceholder('Name').locator('input').fill('SPRING_FLYWAY_ENABLED');
37+
await envDialog.getByPlaceholder('Value').locator('input').fill('false');
38+
await envDialog.getByLabel("Add").click();
39+
await takeScreenshot(page, __filename, `env-dialog-filled-${app}`);
40+
await envDialog.getByLabel("Close").click();
41+
2942
await page.getByLabel('Application URI', {exact: true}).locator('input[type="text"]').fill(uri)
43+
3044
if (cert) {
3145
log(`Uploading certificate ${cert} for ${app}...\n`);
3246
await page.getByLabel('Upload').click();
@@ -37,7 +51,6 @@ async function installApp(app, page) {
3751
await takeScreenshot(page, __filename, `form-filled-${app}`);
3852
await page.locator('.detail-layout').getByRole('button', {name: 'Deploy'}).click();
3953
} else {
40-
log(`No certificate found for ${app}...\n`);
4154
log(`No certificate found for ${app}\n`);
4255
run(`pwd`);
4356
run(`ls -l`);
@@ -70,27 +83,27 @@ async function installApp(app, page) {
7083
await page.getByRole('button', {name: 'Sign In'}).click()
7184
await takeScreenshot(page, __filename, 'logged-in');
7285

73-
for (const app of ['bakery-cc', 'bakery']) {
86+
const apps = ['cc-starter', 'bakery-cc', 'bakery'];
87+
for (const app of apps) {
7488
await installApp(app, page);
7589
}
7690

7791
await takeScreenshot(page, __filename, 'installed-apps');
7892
const startTime = Date.now();
79-
log(`Giving a grace period of 40 secs to wait for 2 apps to be avalable ...\n`);
80-
await page.waitForTimeout(40000);
93+
log(`Giving a grace period of ${gracePeriodSecs} secs to wait for ${apps.length} apps to be avalable ...\n`);
94+
await page.waitForTimeout(gracePeriodSecs);
8195
await page.reload();
82-
log(`Waiting for 2 applications to be available in dashboard ...\n`);
96+
log(`Waiting for ${apps.length} applications to be available in dashboard ...\n`);
8397
await takeScreenshot(page, __filename, 'waiting for apps');
8498

8599
const selector = 'vaadin-grid-cell-content span[theme="badge success"]';
86-
await expect(page.locator(selector).nth(0)).toBeVisible({ timeout: 280000 });
87-
const firstAppTime = (Date.now() - startTime) / 1000;
88-
await takeScreenshot(page, __filename, 'app-1-available');
89-
log(`First application is available after ${firstAppTime.toFixed(2)} seconds\n`);
90-
91-
await expect(page.locator(selector).nth(1)).toBeVisible({ timeout: 280000 });
92-
const secondAppTime = (Date.now() - startTime) / 1000;
93-
await takeScreenshot(page, __filename, 'app-2-available');
94-
log(`Second application is available after ${secondAppTime.toFixed(2)} seconds\n`);
100+
101+
for (let i = 0; i < apps.length; i++) {
102+
await expect(page.locator(selector).nth(i)).toBeVisible({ timeout: waitForReadyMsecs });
103+
const firstAppTime = (Date.now() - startTime) / 1000;
104+
await takeScreenshot(page, __filename, 'app-1-available');
105+
log(`application ${i + 1} is available after ${firstAppTime.toFixed(2)} seconds\n`);
106+
}
107+
95108
await closePage(page);
96109
})();

scripts/pit/its/cc-remove-apps.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const {log, args, createPage, closePage, takeScreenshot, waitForServerReady} = require('./test-utils');
2+
3+
const arg = args();
4+
5+
async function remove(app, page) {
6+
log(`Removing ${app}...\n`);
7+
await page.getByRole('link', { name: 'Settings', }).click();
8+
await takeScreenshot(page, __filename, 'settings');
9+
10+
const anchorSelector = `//vaadin-grid-cell-content[.//span[normalize-space(text())="${app}"]]`;
11+
const anchors = page.locator(anchorSelector);
12+
const c = await anchors.count();
13+
if (c <= 0) {
14+
log(`App ${app} not found`);
15+
return;
16+
}
17+
if (c == 1) {
18+
const text = await anchors.nth(0).textContent();
19+
log(`Found one element ${text}`);
20+
}
21+
if (c > 1) {
22+
log(`App ${app} link found multiple times`);
23+
for (let i = 0; i < c; i++) {
24+
const text = await anchors.nth(i).textContent();
25+
log(`Element ${i}: ${text}`);
26+
}
27+
}
28+
await anchors.nth(0).click();
29+
30+
await page.getByRole('button', { name: 'Delete' }).click();
31+
await page.getByLabel('I understand that this will').check();
32+
await page.getByRole('button', { name: 'Delete' }).click();
33+
}
34+
35+
(async () => {
36+
if (!arg.login) {
37+
log(`Skipping the setup of Control center because of missing --email= parameter\n`)
38+
process.exit(1);
39+
}
40+
const page = await createPage(arg.headless, arg.ignoreHTTPSErrors);
41+
await waitForServerReady(page, arg.url);
42+
await takeScreenshot(page, __filename, 'view-loaded');
43+
44+
log(`Logging in as ${arg.login} ${arg.pass}...\n`);
45+
await page.getByLabel('Email').fill(arg.login);
46+
await page.getByLabel('Password').fill(arg.pass);
47+
await page.getByRole('button', {name: 'Sign In'}).click()
48+
await takeScreenshot(page, __filename, 'logged-in');
49+
50+
for (const app of ['bakery-cc', 'bakery', 'cc-starter']) {
51+
await remove(app, page);
52+
}
53+
54+
await closePage(page);
55+
})();

scripts/pit/its/cc-setup.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,29 @@ const {log, run, args, createPage, closePage, takeScreenshot, waitForServerReady
2727

2828
await takeScreenshot(page, __filename, 'logged-in');
2929

30-
await page.getByLabel('New Password').fill(arg.pass);
31-
await page.getByLabel('Confirm Password').fill(arg.pass);
32-
await page.getByRole('button', { name: 'Submit' }).click();
33-
34-
await takeScreenshot(page, __filename, 'password-changed');
35-
36-
await page.getByLabel('First Name').fill(arg.login.split('@')[0]);
37-
await page.getByLabel('Last Name').fill(arg.login.split('@')[1]);
38-
await page.getByRole('button', { name: 'Submit' }).click();
39-
await takeScreenshot(page, __filename, 'user-configured');
40-
41-
await waitForServerReady(page, arg.url);
30+
const newsPass = page.getByLabel('New Password');
31+
if (await newsPass.count() == 0) {
32+
log("Seems that CC was already setup trying to login")
33+
await page.getByLabel('Email').fill(arg.login);
34+
await page.getByLabel('Password').fill(arg.pass);
35+
await page.getByRole('button', {name: 'Sign In'}).click()
36+
await takeScreenshot(page, __filename, 'logged-in');
37+
} else {
38+
await newsPass.fill(arg.pass);
39+
await page.getByLabel('Confirm Password').fill(arg.pass);
40+
await page.getByRole('button', { name: 'Submit' }).click();
41+
42+
await takeScreenshot(page, __filename, 'password-changed');
43+
44+
await page.getByLabel('First Name').fill(arg.login.split('@')[0]);
45+
await page.getByLabel('Last Name').fill(arg.login.split('@')[1]);
46+
await page.getByRole('button', { name: 'Submit' }).click();
47+
await takeScreenshot(page, __filename, 'user-configured');
48+
await waitForServerReady(page, arg.url);
49+
await page.getByRole('button', { name: 'Manage applications' }).click();
50+
}
4251

43-
await page.getByRole('button', { name: 'Manage applications' }).click();
52+
await page.getByRole('listitem').filter({ hasText: 'Settings'}).click()
4453
await expect(page.getByRole('heading', { name: 'Applications' })).toBeVisible();
45-
await page.waitForTimeout(5000);
46-
4754
await closePage(page);
4855
})();

scripts/pit/its/test-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ async function createPage(headless, ignoreHTTPSErrors) {
9090
const browser = await chromium.launch({
9191
headless: headless,
9292
chromiumSandbox: false,
93-
slowMo: headless ? 400: 1000,
93+
slowMo: process.env.FAST ? 0 : headless ? 400: 1000,
9494
args: ['--window-position=0,0']
9595
});
9696
const context = await browser.newContext({ignoreHTTPSErrors: ignoreHTTPSErrors, viewport: { width: 1792, height: 970 } });

0 commit comments

Comments
 (0)