browser.spec.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import * as fs from 'fs';
  2. import * as path from 'path';
  3. import * as playwright from '@playwright/test';
  4. import * as url from 'url';
  5. playwright.test.setTimeout(120000);
  6. playwright.test('browser', async ({ page }) => {
  7. const self = url.fileURLToPath(import.meta.url);
  8. const dir = path.dirname(self);
  9. const file = path.resolve(dir, '../third_party/test/onnx/candy.onnx');
  10. playwright.expect(fs.existsSync(file)).toBeTruthy();
  11. // Navigate to the application
  12. await page.goto('/');
  13. playwright.expect(page).toBeDefined();
  14. await page.waitForLoadState('domcontentloaded');
  15. // Wait for the welcome screen to be ready
  16. await page.waitForSelector('body.welcome', { timeout: 25000 });
  17. await page.waitForTimeout(1000);
  18. const consent = await page.locator('#message-button');
  19. if (await consent.isVisible({ timeout: 25000 })) {
  20. await consent.click();
  21. }
  22. // Set up file chooser promise before clicking
  23. const fileChooserPromise = page.waitForEvent('filechooser');
  24. const openButton = await page.locator('.open-file-button, button:has-text("Open Model")');
  25. await openButton.click();
  26. const fileChooser = await fileChooserPromise;
  27. await fileChooser.setFiles(file);
  28. // Wait for the graph to render
  29. await page.waitForSelector('#canvas', { state: 'attached', timeout: 10000 });
  30. await page.waitForSelector('body.default', { timeout: 10000 });
  31. // Open find sidebar
  32. const menuButton = await page.locator('#menu-button');
  33. await menuButton.click();
  34. await page.waitForTimeout(200);
  35. const findMenuItem = await page.locator('button:has-text("Find...")');
  36. await findMenuItem.click();
  37. await page.waitForTimeout(500);
  38. const search = await page.waitForSelector('#search', { state: 'visible', timeout: 5000 });
  39. playwright.expect(search).toBeDefined();
  40. // Find and activate tensor
  41. await search.fill('convolution1_W');
  42. await page.waitForSelector('.sidebar-find-content li', { state: 'attached' });
  43. const item = await page.waitForSelector('.sidebar-find-content li:has-text("convolution1_W")');
  44. await item.dblclick();
  45. // Expand the 'value' field
  46. const valueEntry = await page.waitForSelector('#sidebar-content .sidebar-item:has(.sidebar-item-name input[value="value"])');
  47. const valueButton = await valueEntry.waitForSelector('.sidebar-item-value-button');
  48. await valueButton.click();
  49. // Check first number from tensor value
  50. const pre = await valueEntry.waitForSelector('pre');
  51. const text = (await pre.textContent()) || '';
  52. const match = text.match(/-?\d+(?:\.\d+)?(?:e[+-]?\d+)?/i);
  53. playwright.expect(match).not.toBeNull();
  54. const first = parseFloat(match[0]);
  55. playwright.expect(first).toBe(0.1353299617767334);
  56. });