elementus-ai 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,7 +39,9 @@ I just installed the npm package "elementus-ai" — a self-healing element resol
39
39
  - Set actionTimeout: 10000 in playwright config (Elementus respects framework timeouts)
40
40
 
41
41
  For WebDriverIO:
42
- - Add el.wrapBrowser(browser) in the before hook in wdio.conf.js
42
+ - In wdio.conf.js before hook, wrap browser and override global $:
43
+ const wrapped = el.wrapBrowser(browser); globalThis.$ = wrapped.$.bind(wrapped)
44
+ - This way all page objects use plain $() with optional { ai } — zero changes needed
43
45
 
44
46
  For Appium:
45
47
  - Add el.wrapBrowser(driver) in the before hook
@@ -150,10 +152,25 @@ test('example', async ({ page }) => {
150
152
 
151
153
  ### WebDriverIO
152
154
 
155
+ Override the global `$` in your `wdio.conf.js` so all page objects work transparently:
156
+
153
157
  ```javascript
154
- const b = el.wrapBrowser(browser)
155
- await b.$('#btn', { ai: 'Submit order button' }).click()
156
- await b.$('#email', { ai: 'Email input field' }).setValue('test@test.com')
158
+ // wdio.conf.js
159
+ const { createElementus } = require('elementus-ai')
160
+ const el = createElementus({ provider: 'gemini', geminiApiKey: '...' })
161
+
162
+ exports.config = {
163
+ // ... other config
164
+ async before() {
165
+ const wrapped = el.wrapBrowser(browser)
166
+ globalThis.$ = wrapped.$.bind(wrapped)
167
+ }
168
+ }
169
+
170
+ // In tests / page objects — plain $() with optional { ai }:
171
+ await $('[data-testid="btn-send"]') // unchanged, zero overhead
172
+ await $('#btn', { ai: 'Submit order button' }).click() // self-healing
173
+ await $('#email', { ai: 'Email input field' }).setValue('test@test.com')
157
174
  ```
158
175
 
159
176
  ### Appium (Native Android / iOS / Flutter)
package/elementus.js CHANGED
@@ -328,7 +328,11 @@ function createElementus(userConfig = {}) {
328
328
  return args !== undefined ? ctx.evaluate(fn, args) : ctx.evaluate(fn)
329
329
  }
330
330
  if (typeof ctx.execute === 'function') {
331
- return args !== undefined ? ctx.execute(fn, args) : ctx.execute(fn)
331
+ const fnStr = fn.toString()
332
+ if (args !== undefined) {
333
+ return ctx.execute(`(${fnStr})(${JSON.stringify(args)})`)
334
+ }
335
+ return ctx.execute(`(${fnStr})()`)
332
336
  }
333
337
  throw new Error('Context must have evaluate() (Playwright) or execute() (WDIO)')
334
338
  }
@@ -375,7 +379,8 @@ function createElementus(userConfig = {}) {
375
379
  // Appium native: has getPageSource but no evaluate/execute for browser JS
376
380
  // (or execute exists but would fail — we detect via getPageSource presence + no DOM)
377
381
  return typeof ctx.getPageSource === 'function' &&
378
- typeof ctx.evaluate !== 'function'
382
+ typeof ctx.evaluate !== 'function' &&
383
+ typeof ctx.execute !== 'function'
379
384
  }
380
385
 
381
386
  // ── LLM helpers — multi-provider ─────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elementus-ai",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Self-healing element resolution for Playwright, WDIO & Appium. AI-powered fallback when selectors break.",
5
5
  "main": "elementus.js",
6
6
  "keywords": [
@@ -36,6 +36,7 @@
36
36
  },
37
37
  "files": [
38
38
  "elementus.js",
39
+ "wdio.d.ts",
39
40
  "README.md",
40
41
  "LICENSE"
41
42
  ]
package/wdio.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /// <reference types="webdriverio" />
2
+
3
+ declare global {
4
+ function $(selector: string, options?: { ai?: string }): WebdriverIO.Element
5
+ }
6
+
7
+ export {}