elementus-ai 1.0.0 → 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
@@ -7,7 +7,7 @@ When a selector breaks, Elementus uses AI to find the element by natural-languag
7
7
  ## Installation
8
8
 
9
9
  ```bash
10
- npm install elementus
10
+ npm install elementus-ai
11
11
  ```
12
12
 
13
13
  ## One-Prompt Setup
@@ -18,7 +18,7 @@ Copy this prompt to your AI coding agent (Claude, Cursor, Copilot, etc.) and it
18
18
  <summary><strong>Click to copy the setup prompt</strong></summary>
19
19
 
20
20
  ```
21
- I just installed the npm package "elementus" — a self-healing element resolution library for test automation. Analyze my project and integrate it. Follow these steps:
21
+ I just installed the npm package "elementus-ai" — a self-healing element resolution library for test automation. Analyze my project and integrate it. Follow these steps:
22
22
 
23
23
  1. DETECT MY FRAMEWORK
24
24
  - Search for: playwright.config, wdio.conf, appium config files
@@ -39,7 +39,9 @@ I just installed the npm package "elementus" — a self-healing element resoluti
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
@@ -73,7 +75,7 @@ Rules:
73
75
  ## Quick Start
74
76
 
75
77
  ```javascript
76
- const { createElementus } = require('elementus')
78
+ const { createElementus } = require('elementus-ai')
77
79
 
78
80
  const el = createElementus({
79
81
  provider: 'gemini',
@@ -133,7 +135,7 @@ await p.locator('#email', { ai: 'Email input field' }).fill('test@test.com')
133
135
  ```javascript
134
136
  // fixtures.js
135
137
  const { test: base } = require('@playwright/test')
136
- const { createElementus } = require('elementus')
138
+ const { createElementus } = require('elementus-ai')
137
139
  const el = createElementus({ provider: 'gemini', geminiApiKey: '...' })
138
140
 
139
141
  module.exports = base.extend({
@@ -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.0",
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 {}