| 1 | import fs from 'node:fs/promises'; |
| 2 | import path from 'node:path'; |
| 3 | import {chromium} from 'playwright'; |
| 4 | |
| 5 | const BASE_URL = process.env.COPILOT_BASE_URL || 'https://copilot-lab.socfortressmdr.us'; |
| 6 | const USERNAME = process.env.COPILOT_USERNAME; |
| 7 | const PASSWORD = process.env.COPILOT_PASSWORD; |
| 8 | |
| 9 | if (!USERNAME || !PASSWORD) { |
| 10 | console.error('Missing COPILOT_USERNAME or COPILOT_PASSWORD in environment.'); |
| 11 | process.exit(1); |
| 12 | } |
| 13 | |
| 14 | const OUT_DIR = path.resolve(process.cwd(), '..', '..', 'docs', 'assets', 'ui'); |
| 15 | const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); |
| 16 | |
| 17 | async function ensureDir(p) { |
| 18 | await fs.mkdir(p, {recursive: true}); |
| 19 | } |
| 20 | |
| 21 | async function main() { |
| 22 | await ensureDir(OUT_DIR); |
| 23 | |
| 24 | const browser = await chromium.launch({headless: true}); |
| 25 | const context = await browser.newContext({ |
| 26 | viewport: {width: 1440, height: 900}, |
| 27 | deviceScaleFactor: 2, |
| 28 | }); |
| 29 | const page = await context.newPage(); |
| 30 | |
| 31 | // Login |
| 32 | await page.goto(`${BASE_URL}/login`, {waitUntil: 'domcontentloaded'}); |
| 33 | await page.waitForTimeout(500); |
| 34 | |
| 35 | await page.getByPlaceholder(/username/i).or(page.getByRole('textbox', {name: /username/i})).first().fill(USERNAME); |
| 36 | await page.getByPlaceholder(/password/i).or(page.locator('input[type="password"]')).first().fill(PASSWORD); |
| 37 | await page.getByRole('button', {name: /sign in/i}).first().click(); |
| 38 | await page.waitForTimeout(2000); |
| 39 | if (page.url().includes('/login')) { |
| 40 | throw new Error('Login failed (still on /login)'); |
| 41 | } |
| 42 | |
| 43 | // Go to Customers |
| 44 | await page.goto(`${BASE_URL}/customers`, {waitUntil: 'domcontentloaded'}); |
| 45 | await page.waitForTimeout(2000); |
| 46 | |
| 47 | // Screenshot the customers list (baseline) |
| 48 | await page.screenshot({path: path.join(OUT_DIR, 'customers-list.png'), fullPage: true}); |
| 49 | |
| 50 | // Open a customer details modal/panel. |
| 51 | // Prefer a "Details" button if present; otherwise click the first visible row card. |
| 52 | const detailsBtn = page.getByRole('button', {name: /^Details$/i}).first(); |
| 53 | if (await detailsBtn.count().then((c) => c > 0)) { |
| 54 | await detailsBtn.click(); |
| 55 | } else { |
| 56 | // fallback: click the first customer card area |
| 57 | await page.locator('text=/Total:/').locator('..').click({timeout: 2000}).catch(() => undefined); |
| 58 | } |
| 59 | await page.waitForTimeout(1500); |
| 60 | |
| 61 | // Helper to click tabs by name |
| 62 | async function clickTab(name) { |
| 63 | await page.getByRole('tab', {name}).click({timeout: 5000}); |
| 64 | await page.waitForTimeout(1200); |
| 65 | } |
| 66 | |
| 67 | // Provision tab |
| 68 | await clickTab(/Provision/i); |
| 69 | await page.screenshot({path: path.join(OUT_DIR, 'customer-tab-provision.png'), fullPage: true}); |
| 70 | |
| 71 | // 3rd Party Integrations tab |
| 72 | await clickTab(/3rd Party Integrations/i); |
| 73 | await page.screenshot({path: path.join(OUT_DIR, 'customer-tab-3rd-party-integrations.png'), fullPage: true}); |
| 74 | |
| 75 | // Network Connectors tab |
| 76 | await clickTab(/Network Connectors/i); |
| 77 | await page.screenshot({path: path.join(OUT_DIR, 'customer-tab-network-connectors.png'), fullPage: true}); |
| 78 | |
| 79 | await browser.close(); |
| 80 | console.log('Done: wrote customer tab screenshots to', OUT_DIR); |
| 81 | } |
| 82 | |
| 83 | main().catch((e) => { |
| 84 | console.error(e?.stack || String(e)); |
| 85 | process.exit(1); |
| 86 | }); |