desktop.spec.js 2.8 KB

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