| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import * as fs from 'fs';
- import * as path from 'path';
- import * as playwright from '@playwright/test';
- import * as url from 'url';
- playwright.test.setTimeout(120_000);
- playwright.test('browser', async ({ page }) => {
- const self = url.fileURLToPath(import.meta.url);
- const dir = path.dirname(self);
- const file = path.resolve(dir, '../third_party/test/onnx/candy.onnx');
- playwright.expect(fs.existsSync(file)).toBeTruthy();
- // Navigate to the application
- await page.goto('/');
- playwright.expect(page).toBeDefined();
- await page.waitForLoadState('domcontentloaded');
- // Wait for the welcome screen to be ready
- await page.waitForSelector('body.welcome', { timeout: 5000 });
- await page.waitForTimeout(1000);
- const consent = await page.locator('#message-button');
- if (await consent.isVisible({ timeout: 2000 })) {
- await consent.click();
- }
- // Set up file chooser promise before clicking
- const fileChooserPromise = page.waitForEvent('filechooser');
- const openButton = await page.locator('.open-file-button, button:has-text("Open Model")');
- await openButton.click();
- const fileChooser = await fileChooserPromise;
- await fileChooser.setFiles(file);
- // Wait for the graph to render
- await page.waitForSelector('#canvas', { state: 'attached', timeout: 10000 });
- await page.waitForSelector('body.default', { timeout: 10000 });
- // Open find sidebar
- const menuButton = await page.locator('#menu-button');
- await menuButton.click();
- await page.waitForTimeout(200);
- const findMenuItem = await page.locator('button:has-text("Find...")');
- await findMenuItem.click();
- await page.waitForTimeout(500);
- const search = await page.waitForSelector('#search', { state: 'visible', timeout: 5000 });
- playwright.expect(search).toBeDefined();
- // Find and activate tensor
- await search.fill('convolution1_W');
- await page.waitForSelector('.sidebar-find-content li', { state: 'attached' });
- const item = await page.waitForSelector('.sidebar-find-content li:has-text("convolution1_W")');
- await item.dblclick();
- // Expand the 'value' field
- const valueEntry = await page.waitForSelector('#sidebar-content .sidebar-item:has(.sidebar-item-name input[value="value"])');
- const valueButton = await valueEntry.waitForSelector('.sidebar-item-value-button');
- await valueButton.click();
- // Check first number from tensor value
- const pre = await valueEntry.waitForSelector('pre');
- const text = (await pre.textContent()) || '';
- const match = text.match(/-?\d+(?:\.\d+)?(?:e[+-]?\d+)?/i);
- playwright.expect(match).not.toBeNull();
- const first = parseFloat(match[0]);
- playwright.expect(first).toBe(0.1353299617767334);
- });
|