|
1 | 1 | import { test as base, expect } from '@playwright/test'; |
2 | 2 | import * as RmaHelpers from './util/RmaHelpers.mjs'; |
| 3 | +import { |
| 4 | + NeuralLink_ConnectionService, |
| 5 | + NeuralLink_InstanceService, |
| 6 | + NeuralLink_DataService, |
| 7 | + NeuralLink_RuntimeService |
| 8 | +} from '../../ai/services.mjs'; |
3 | 9 |
|
4 | 10 | export const test = base.extend({ |
5 | 11 | neo: async ({ page }, use) => { |
@@ -59,6 +65,65 @@ export const test = base.extend({ |
59 | 65 | }; |
60 | 66 |
|
61 | 67 | await use(neo); |
| 68 | + }, |
| 69 | + |
| 70 | + neuralLink: async ({ page }, use) => { |
| 71 | + // 1. Ensure Bridge connects |
| 72 | + await NeuralLink_ConnectionService.manageConnection({action: 'start'}); |
| 73 | + |
| 74 | + // 2. Define the Neural Link Fixture object |
| 75 | + const nl = { |
| 76 | + /** |
| 77 | + * Waits for the Test's specific App Worker to connect to the Bridge and returns an SDK wrapper. |
| 78 | + * @param {String} [appName] Optional explicitly named app to wait for. Mostly we wait for this specific page's workerId. |
| 79 | + */ |
| 80 | + async connectToApp(appName) { |
| 81 | + let inferredAppName = null; |
| 82 | + |
| 83 | + try { |
| 84 | + // Give the page a moment to initialize Neo |
| 85 | + await page.waitForFunction(() => window.Neo && window.Neo.config, { timeout: 2000 }).catch(() => {}); |
| 86 | + inferredAppName = await page.evaluate(() => { |
| 87 | + const path = window.Neo?.config?.appPath; |
| 88 | + return path ? path.split('/').slice(-2, -1)[0] : null; |
| 89 | + }); |
| 90 | + } catch (e) { |
| 91 | + // Ignore, page might not exist or be blank |
| 92 | + } |
| 93 | + |
| 94 | + // If user passed 'Portal', prefer that, otherwise use the inferred appName like 'portal' |
| 95 | + const targetId = appName || inferredAppName; |
| 96 | + if (!targetId) { |
| 97 | + throw new Error('neuralLink.connectToApp requires either an initialized Neo environment or an explicit appName to wait for.'); |
| 98 | + } |
| 99 | + |
| 100 | + // Lowercase for the connection service match |
| 101 | + const sessionId = await NeuralLink_ConnectionService.waitForSession(targetId.toLowerCase()); |
| 102 | + |
| 103 | + return { |
| 104 | + sessionId, |
| 105 | + |
| 106 | + async getComponent(id) { |
| 107 | + const response = await NeuralLink_InstanceService.getInstanceProperties({ sessionId, id, properties: ['ntype', 'windowId', 'cls', 'className', 'vnode'] }); |
| 108 | + return response.properties; |
| 109 | + }, |
| 110 | + |
| 111 | + async getStore(storeId) { |
| 112 | + return NeuralLink_DataService.inspectStore({ sessionId, storeId }); |
| 113 | + }, |
| 114 | + |
| 115 | + async callMethod(id, method, args = []) { |
| 116 | + return NeuralLink_RuntimeService.callMethod({ sessionId, id, method, args }); |
| 117 | + }, |
| 118 | + |
| 119 | + async setProperties(id, properties) { |
| 120 | + return NeuralLink_InstanceService.setInstanceProperties({ sessionId, id, properties }); |
| 121 | + } |
| 122 | + }; |
| 123 | + } |
| 124 | + }; |
| 125 | + |
| 126 | + await use(nl); |
62 | 127 | } |
63 | 128 | }); |
64 | 129 |
|
|
0 commit comments