-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix identity manager Visual tests and add to the list (#16)
* fix identity manager Visual tests and add to the list * add more screenshots * wait for server ready when connecting to deployed app * fix localization Visual tests and add to the list * check that app is running before enabling features, and clean up * fix quotes in NPM command when node is in .vaadin, improve logs * add --cluster= parameter in order to run tests in any cluster * set cluster context, and check https in installed apps * fix kubectl port-forward in windows * fix return when running playwrightTests in CC * rename vars and check port 443 --------- Co-authored-by: edler-san <[email protected]>
- Loading branch information
Showing
10 changed files
with
356 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,119 @@ | ||
const {chromium} = require('playwright'); | ||
const sleep = ms => new Promise(r => setTimeout(r, ms)); | ||
const path = require('path'); | ||
const {expect} = require('@playwright/test'); | ||
|
||
const ADMIN_EMAIL = '[email protected]'; | ||
const ADMIN_PASSWORD = 'adminPassword'; | ||
|
||
let headless = false, host = 'localhost', port = '8000', hub = false; | ||
process.argv.forEach(a => { | ||
if (/^--headless/.test(a)) { | ||
headless = true; | ||
} else if (/^--ip=/.test(a)) { | ||
ip = a.split('=')[1]; | ||
} else if (/^--port=/.test(a)) { | ||
port = a.split('=')[1]; | ||
} | ||
}); | ||
const { expect} = require('@playwright/test'); | ||
const fs = require('fs'); | ||
const {log, err, args, run, createPage, closePage, takeScreenshot, waitForServerReady} = require('./test-utils'); | ||
const { assert } = require('console'); | ||
|
||
(async () => { | ||
const browser = await chromium.launch({ | ||
headless: headless, | ||
chromiumSandbox: false | ||
}); | ||
const context = await browser.newContext({ignoreHTTPSErrors: true}); | ||
|
||
// 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, ' '))); | ||
|
||
// Go to http://${host}:${port}/ | ||
await page.goto(`http://${host}:${port}/`); | ||
|
||
await page.getByLabel('Email').fill(ADMIN_EMAIL) | ||
await page.getByLabel('Password', {exact: true}).fill(ADMIN_PASSWORD) | ||
await page.getByRole('button', {name: 'Sign In'}).click() | ||
|
||
await page.goto(`http://${host}:${port}/settings/apps/app1`); | ||
|
||
const locOpt = page.getByLabel('Localization').click(); | ||
if(await !page.getByLabel('Localization').isChecked()){ | ||
await page.getByLabel('Localization').click({timeout:60000}) | ||
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 user = '[email protected]'; | ||
const password = 'admin'; | ||
const downloadsDir = './downloads'; | ||
const propsFile = 'translations.properties'; | ||
|
||
await page.getByRole('button', {name: 'Update'}).click() | ||
|
||
await page.goto(`http://${host}:${port}/app/app1/i18n/translations`); | ||
|
||
await page.getByRole('menuitem').click() | ||
await page.getByText('Upload translations').click() | ||
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'); | ||
|
||
log(`Logging in CC 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() | ||
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(`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 takeScreenshot(pageApp, __filename, 'app-running'); | ||
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, 'localization-enabled'); | ||
|
||
fs.writeFileSync(propsFile, 'app.title=Bakery\n'); | ||
await page.getByLabel('Manage translations').locator('svg').click(); | ||
await page.getByText('Upload translations').click(); | ||
await page.getByLabel('I understand that this will').check(); | ||
const fileChooserPromise = page.waitForEvent('filechooser'); | ||
await page.getByText('Upload Files...').click(); | ||
await page.getByRole('button', { name: 'Upload Files...' }).click(); | ||
const fileChooser = await fileChooserPromise; | ||
await fileChooser.setFiles(path.join(__dirname, 'translations.properties')); | ||
await page.getByLabel('I understand that this will replace all corresponding data.').check() | ||
await page.getByRole('button', {name: 'Replace data'}).click() | ||
|
||
await page.getByText('Hello anonymous!').click(); | ||
await page.locator('vaadin-grid-cell-content').getByRole('textbox').fill('Test'); | ||
|
||
await page.getByText('Say hello').click(); | ||
await page.locator('vaadin-grid-cell-content').getByRole('textbox').fill('Say bonjour'); | ||
await page.locator('.confirm-button').click(); | ||
|
||
expect(page.getByText('Hello anonymous!')).toBeVisible() | ||
expect(page.locator('vaadin-grid-cell-content').filter({ hasText: 'Say bonjour' })).toBeVisible() | ||
|
||
// --------------------- | ||
await context.close(); | ||
await browser.close(); | ||
await fileChooser.setFiles(propsFile); | ||
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(); | ||
const download = await downloadPromise; | ||
const filePath = `${downloadsDir}/${download.suggestedFilename()}`; | ||
await download.saveAs(filePath); | ||
|
||
await run(`unzip -d ${downloadsDir} -o ${filePath}`); | ||
const str = await fs.readFileSync('./downloads/translations.properties', 'utf8'); | ||
assert(str.includes('app.title=Panaderia')); | ||
await fs.rmSync(downloadsDir, { recursive: true }); | ||
|
||
log(`Starting preview server\n`); | ||
await page.getByRole('button', { name: 'Start preview' }).click(); | ||
await page.waitForTimeout(5000); | ||
|
||
log(`Testing that preview page: ${previewUrl} is up and running\n`); | ||
const pagePrev = await createPage(arg.headless, true /* preview pages do not have a valid certificate */); | ||
await waitForServerReady(pagePrev, previewUrl); | ||
await takeScreenshot(pagePrev, __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(pagePrev, __filename, 'preview-loaded'); | ||
} | ||
// TODO: bakery is not internationalized | ||
// await expect(pagePrev.getByText('Panaderia', { exact: true })).toBeVisible(); | ||
await closePage(pagePrev); | ||
|
||
log('Cleaning up...\n'); | ||
try { | ||
await page.getByRole('button', { name: 'Stop preview' }).click(); | ||
await page.getByRole('link', { name: 'Settings' }).click(); | ||
await page.waitForTimeout(2000); | ||
await page.locator('vaadin-grid').getByText('bakery-cc', { exact: true }).click(); | ||
await page.waitForTimeout(2000); | ||
await page.getByLabel('Localization').uncheck(); | ||
await page.getByRole('button', { name: 'Disable' }).click(); | ||
await page.getByRole('button', { name: 'Update' }).click(); | ||
} catch (error) { | ||
err(`Error cleaning up: ${error}\n`); | ||
await takeScreenshot(page, __filename, 'error-cleaning'); | ||
} | ||
await closePage(page); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.