desktop.spec.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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(120_000);
  6. playwright.test('desktop', async () => {
  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. // Launch app
  12. const electron = await playwright._electron;
  13. const args = ['.', '--no-sandbox'];
  14. const app = await electron.launch({ args });
  15. const window = await app.firstWindow();
  16. playwright.expect(window).toBeDefined();
  17. await window.waitForLoadState('domcontentloaded');
  18. const consent = await window.locator('#message-button');
  19. if (await consent.isVisible({ timeout: 2000 }).catch(() => false)) {
  20. await consent.click();
  21. }
  22. // Open the model
  23. await app.evaluate(async (electron, location) => {
  24. const windows = electron.BrowserWindow.getAllWindows();
  25. if (windows.length > 0) {
  26. const [window] = windows;
  27. window.webContents.send('open', { path: location });
  28. }
  29. }, file);
  30. // Wait for the graph to render
  31. await window.waitForSelector('#canvas', { state: 'attached', timeout: 10000 });
  32. await window.waitForSelector('body.default', { timeout: 10000 });
  33. // Open find sidebar
  34. await app.evaluate(async (electron) => {
  35. const windows = electron.BrowserWindow.getAllWindows();
  36. if (windows.length > 0) {
  37. const [window] = windows;
  38. window.webContents.send('find', {});
  39. }
  40. });
  41. await window.waitForTimeout(500);
  42. const search = await window.waitForSelector('#search', { state: 'visible', timeout: 5000 });
  43. playwright.expect(search).toBeDefined();
  44. // Find and activate tensor
  45. await search.fill('convolution1_W');
  46. await window.waitForSelector('.sidebar-find-content li', { state: 'attached' });
  47. const item = await window.waitForSelector('.sidebar-find-content li:has-text("convolution1_W")');
  48. await item.dblclick();
  49. // Expand the 'value' field
  50. const valueEntry = await window.waitForSelector('#sidebar-content .sidebar-item:has(.sidebar-item-name input[value="value"])');
  51. const valueButton = await valueEntry.waitForSelector('.sidebar-item-value-button');
  52. await valueButton.click();
  53. // Check first number from tensor value
  54. const pre = await valueEntry.waitForSelector('pre');
  55. const text = (await pre.textContent()) || '';
  56. const match = text.match(/-?\d+(?:\.\d+)?(?:e[+-]?\d+)?/i);
  57. playwright.expect(match).not.toBeNull();
  58. const first = parseFloat(match[0]);
  59. playwright.expect(first).toBe(0.1353299617767334);
  60. await app.close();
  61. });