Files
Cactidocumentation/resources/workflowdemo-browser.cjs
T

51 lines
2.6 KiB
JavaScript

const assert = require('node:assert/strict');
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch(process.env.CHROME_BIN
? { executablePath: process.env.CHROME_BIN } : {});
try {
for (const role of ['ALLOWED', 'DENIED']) {
const context = await browser.newContext({ viewport: { width: 1100, height: 720 } });
const page = await context.newPage();
const root = new URL(process.env.CACTI_URL);
await page.goto(new URL('index.php', root).href);
await page.locator('[name=login_username]').fill(process.env[role + '_USER']);
await page.locator('[name=login_password]').fill(process.env[role + '_PASSWORD']);
await page.locator('input[type=submit], button[type=submit]').first().click();
await page.waitForLoadState('networkidle');
assert.ok((await page.locator('body').innerText()).includes(process.env[role + '_USER']));
await page.goto(new URL('plugins/workflowdemo/workflowdemo_devices.php', root).href);
const rows = page.locator('#wf-results tbody td');
if (role === 'DENIED') {
assert.match(await page.locator('body').innerText(), /denied|permission|authorized/i);
assert.equal(await rows.count(), 0);
} else {
await rows.first().waitFor();
assert.deepEqual(await rows.allTextContents(), ['core-a', 'edge-a']);
const filter = page.locator('input[name=filter]').first();
await filter.fill('edge');
await filter.press('Enter');
await page.waitForFunction(() => document.querySelector('#wf-results td')?.textContent === 'edge-a');
assert.deepEqual(await rows.allTextContents(), ['edge-a', 'edge-b']);
await page.getByRole('link', { name: 'Name', exact: true }).click();
await page.waitForFunction(() => document.querySelector('#wf-results td')?.textContent === 'edge-c');
assert.deepEqual(await rows.allTextContents(), ['edge-c', 'edge-b']);
await page.getByRole('link', { name: 'Next', exact: true }).click();
await page.waitForFunction(() => document.querySelector('#wf-results td')?.textContent === 'edge-a');
assert.deepEqual(await rows.allTextContents(), ['edge-a']);
if (process.env.SCREENSHOT) {
await page.screenshot({path:process.env.SCREENSHOT, clip:{x:0,y:0,width:1100,height:235}});
}
await page.locator('input[name=filter]').first().fill('absent');
await page.locator('input[name=filter]').first().press('Enter');
await page.getByText('No matching devices', {exact:true}).waitFor();
assert.equal(await rows.count(), 0);
}
await context.close();
}
} finally {
await browser.close();
}
})().catch(error => { console.error(error); process.exitCode = 1; });