@samsara-dev/appwright 0.9.6 → 0.9.7
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/CHANGELOG.md +15 -0
- package/README.md +34 -0
- package/dist/device/index.d.ts +24 -0
- package/dist/device/index.d.ts.map +1 -1
- package/dist/device/index.js +40 -0
- package/dist/gptDriver/index.d.ts +38 -0
- package/dist/gptDriver/index.d.ts.map +1 -0
- package/dist/gptDriver/index.js +187 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# appwright
|
|
2
2
|
|
|
3
|
+
## 0.9.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- dbd26ca: feat(gptDriver): integrate GPT Driver SDK for AI-powered test automation
|
|
8
|
+
|
|
9
|
+
Add GPT Driver SDK integration enabling natural language test automation via `device.gptDriver.*` methods:
|
|
10
|
+
- `aiExecute(instruction)` - execute AI-powered actions
|
|
11
|
+
- `assert(condition)` - verify screen state with natural language
|
|
12
|
+
- `assertBulk(conditions)` - verify multiple conditions at once
|
|
13
|
+
- `checkBulk(conditions)` - check conditions without failing test
|
|
14
|
+
- `extract(extractions)` - extract data from screen
|
|
15
|
+
|
|
16
|
+
Requires `GPT_DRIVER_API_KEY` environment variable. Tests gracefully skip when not configured.
|
|
17
|
+
|
|
3
18
|
## 0.9.6
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -234,6 +234,40 @@ npm run extract:app
|
|
|
234
234
|
npx appwright test --project ios
|
|
235
235
|
```
|
|
236
236
|
|
|
237
|
+
## GPT Driver Integration
|
|
238
|
+
|
|
239
|
+
Appwright supports [GPT Driver](https://docs.mobileboost.io/gpt-driver-sdk) for AI-powered test automation. This enables natural language commands and AI assertions.
|
|
240
|
+
|
|
241
|
+
### Setup
|
|
242
|
+
|
|
243
|
+
Set the `GPT_DRIVER_API_KEY` environment variable:
|
|
244
|
+
|
|
245
|
+
```sh
|
|
246
|
+
export GPT_DRIVER_API_KEY=your-api-key
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Usage
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
import { test } from "@samsara-dev/appwright";
|
|
253
|
+
|
|
254
|
+
test("User can add item to cart", async ({ device }) => {
|
|
255
|
+
// Natural language commands
|
|
256
|
+
await device.gptDriver.aiExecute("tap on the login button");
|
|
257
|
+
await device.gptDriver.aiExecute("enter 'admin' in the username field");
|
|
258
|
+
|
|
259
|
+
// AI-powered assertions
|
|
260
|
+
await device.gptDriver.assert("welcome message is visible");
|
|
261
|
+
await device.gptDriver.assert("cart shows 1 item");
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Data Privacy Notice
|
|
266
|
+
|
|
267
|
+
GPT Driver sends screenshots to Mobileboost's external API for AI processing. Do not use GPT Driver in tests that handle sensitive data displayed on screen.
|
|
268
|
+
|
|
269
|
+
Tests skip automatically when `GPT_DRIVER_API_KEY` is not set.
|
|
270
|
+
|
|
237
271
|
## Docs
|
|
238
272
|
|
|
239
273
|
- [Basics](docs/basics.md)
|
package/dist/device/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare class Device {
|
|
|
16
16
|
private persistentSyncEnabled;
|
|
17
17
|
private activePersistentKey?;
|
|
18
18
|
private cleanupCallback?;
|
|
19
|
+
private _gptDriverProvider;
|
|
19
20
|
constructor(webDriverClient: WebDriverClient, bundleId: string | undefined, timeoutOpts: TimeoutOptions, provider: string, deviceProvider?: DeviceProvider, cleanupCallback?: () => Promise<void>);
|
|
20
21
|
attachDeviceProvider(provider: DeviceProvider): void;
|
|
21
22
|
enablePersistentStatusSync(): void;
|
|
@@ -60,6 +61,29 @@ export declare class Device {
|
|
|
60
61
|
};
|
|
61
62
|
}) => Promise<ExtractType<T>>;
|
|
62
63
|
};
|
|
64
|
+
private gptDriverProvider;
|
|
65
|
+
/**
|
|
66
|
+
* GPT Driver AI-powered test automation.
|
|
67
|
+
* Requires GPT_DRIVER_API_KEY environment variable.
|
|
68
|
+
*
|
|
69
|
+
* Note: Screenshots are sent to GPT Driver's external API for AI processing.
|
|
70
|
+
*
|
|
71
|
+
* **Usage:**
|
|
72
|
+
* ```js
|
|
73
|
+
* await device.gptDriver.aiExecute("tap on the login button");
|
|
74
|
+
* await device.gptDriver.assert("welcome message is visible");
|
|
75
|
+
* await device.gptDriver.assertBulk(["button is visible", "text shows 'Hello'"]);
|
|
76
|
+
* const results = await device.gptDriver.checkBulk(["logged in", "menu open"]);
|
|
77
|
+
* const data = await device.gptDriver.extract(["total price", "item count"]);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
gptDriver: {
|
|
81
|
+
aiExecute: (instruction: string) => Promise<void>;
|
|
82
|
+
assert: (condition: string) => Promise<void>;
|
|
83
|
+
assertBulk: (conditions: string[]) => Promise<void>;
|
|
84
|
+
checkBulk: (conditions: string[]) => Promise<Record<string, boolean>>;
|
|
85
|
+
extract: (extractions: string[]) => Promise<Record<string, any>>;
|
|
86
|
+
};
|
|
63
87
|
/**
|
|
64
88
|
* Closes the automation session. This is called automatically after each test.
|
|
65
89
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/device/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AAE3D,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,QAAQ,EACR,cAAc,EACd,iBAAiB,EAClB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/device/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AAE3D,OAAO,EACL,gBAAgB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M,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBnD,KAAK;IAkBL,cAAc,CAAC,OAAO,EAAE,MAAM;IAIpC;;OAEG;IAEG,WAAW,IAAI,OAAO,CAAC,cAAc,CAAC;IAI5C;;OAEG;IAEG,aAAa,IAAI,OAAO,CAAC;QAC7B,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;IAIF;;OAEG;IAEG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC;;;;;;;;;;OAUG;IAEG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAU7B;;;OAGG;IAEG,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBlD;;;;;;;;;;;;;;;;;OAiBG;IAEU,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAYnE;;;;;;;;;;;;;OAaG;IAEU,wBAAwB,CACnC,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,IAAI,CAAC;IAIhB;;;OAGG;IACH,OAAO,CAAC,qBAAqB;CAe9B"}
|
package/dist/device/index.js
CHANGED
|
@@ -38,6 +38,7 @@ exports.Device = void 0;
|
|
|
38
38
|
const locator_1 = require("../locator");
|
|
39
39
|
const types_1 = require("../types");
|
|
40
40
|
const vision_1 = require("../vision");
|
|
41
|
+
const gptDriver_1 = require("../gptDriver");
|
|
41
42
|
const utils_1 = require("../utils");
|
|
42
43
|
const utils_2 = require("../providers/browserstack/utils");
|
|
43
44
|
const utils_3 = require("../providers/lambdatest/utils");
|
|
@@ -104,6 +105,7 @@ let Device = (() => {
|
|
|
104
105
|
persistentSyncEnabled = false;
|
|
105
106
|
activePersistentKey;
|
|
106
107
|
cleanupCallback;
|
|
108
|
+
_gptDriverProvider = null;
|
|
107
109
|
constructor(webDriverClient, bundleId, timeoutOpts, provider, deviceProvider, cleanupCallback) {
|
|
108
110
|
this.webDriverClient = webDriverClient;
|
|
109
111
|
this.bundleId = bundleId;
|
|
@@ -219,6 +221,44 @@ let Device = (() => {
|
|
|
219
221
|
return await this.vision().query(prompt, options);
|
|
220
222
|
},
|
|
221
223
|
};
|
|
224
|
+
gptDriverProvider() {
|
|
225
|
+
if (!this._gptDriverProvider) {
|
|
226
|
+
this._gptDriverProvider = new gptDriver_1.GptDriverProvider(this.webDriverClient);
|
|
227
|
+
}
|
|
228
|
+
return this._gptDriverProvider;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* GPT Driver AI-powered test automation.
|
|
232
|
+
* Requires GPT_DRIVER_API_KEY environment variable.
|
|
233
|
+
*
|
|
234
|
+
* Note: Screenshots are sent to GPT Driver's external API for AI processing.
|
|
235
|
+
*
|
|
236
|
+
* **Usage:**
|
|
237
|
+
* ```js
|
|
238
|
+
* await device.gptDriver.aiExecute("tap on the login button");
|
|
239
|
+
* await device.gptDriver.assert("welcome message is visible");
|
|
240
|
+
* await device.gptDriver.assertBulk(["button is visible", "text shows 'Hello'"]);
|
|
241
|
+
* const results = await device.gptDriver.checkBulk(["logged in", "menu open"]);
|
|
242
|
+
* const data = await device.gptDriver.extract(["total price", "item count"]);
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
gptDriver = {
|
|
246
|
+
aiExecute: async (instruction) => {
|
|
247
|
+
return await this.gptDriverProvider().aiExecute(instruction);
|
|
248
|
+
},
|
|
249
|
+
assert: async (condition) => {
|
|
250
|
+
return await this.gptDriverProvider().assert(condition);
|
|
251
|
+
},
|
|
252
|
+
assertBulk: async (conditions) => {
|
|
253
|
+
return await this.gptDriverProvider().assertBulk(conditions);
|
|
254
|
+
},
|
|
255
|
+
checkBulk: async (conditions) => {
|
|
256
|
+
return await this.gptDriverProvider().checkBulk(conditions);
|
|
257
|
+
},
|
|
258
|
+
extract: async (extractions) => {
|
|
259
|
+
return await this.gptDriverProvider().extract(extractions);
|
|
260
|
+
},
|
|
261
|
+
};
|
|
222
262
|
/**
|
|
223
263
|
* Closes the automation session. This is called automatically after each test.
|
|
224
264
|
*
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Client as WebDriverClient } from "webdriver";
|
|
2
|
+
/**
|
|
3
|
+
* GptDriverApi defines the public interface for AI-powered test automation.
|
|
4
|
+
*/
|
|
5
|
+
export interface GptDriverApi {
|
|
6
|
+
aiExecute(instruction: string): Promise<void>;
|
|
7
|
+
assert(condition: string): Promise<void>;
|
|
8
|
+
assertBulk(conditions: string[]): Promise<void>;
|
|
9
|
+
checkBulk(conditions: string[]): Promise<Record<string, boolean>>;
|
|
10
|
+
extract(extractions: string[]): Promise<Record<string, any>>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* GptDriverProvider wraps the gpt-driver-node SDK for AI-powered test automation.
|
|
14
|
+
*
|
|
15
|
+
* Pattern: Lazy-initialized singleton per Device instance.
|
|
16
|
+
* - Driver is created on first use (not in constructor)
|
|
17
|
+
* - Cached for subsequent calls
|
|
18
|
+
* - Gracefully skips tests when API key is not configured
|
|
19
|
+
*
|
|
20
|
+
* Similar to: VisionProvider
|
|
21
|
+
*/
|
|
22
|
+
export declare class GptDriverProvider implements GptDriverApi {
|
|
23
|
+
private webDriverClient;
|
|
24
|
+
private driver;
|
|
25
|
+
constructor(webDriverClient: WebDriverClient);
|
|
26
|
+
private getAppiumUrl;
|
|
27
|
+
private getDriver;
|
|
28
|
+
private requireDriver;
|
|
29
|
+
private validateInstruction;
|
|
30
|
+
private validateConditions;
|
|
31
|
+
private sanitizeError;
|
|
32
|
+
aiExecute(instruction: string): Promise<void>;
|
|
33
|
+
assert(condition: string): Promise<void>;
|
|
34
|
+
assertBulk(conditions: string[]): Promise<void>;
|
|
35
|
+
checkBulk(conditions: string[]): Promise<Record<string, boolean>>;
|
|
36
|
+
extract(extractions: string[]): Promise<Record<string, any>>;
|
|
37
|
+
}
|
|
38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AAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAajE,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAWnE"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
+
var useValue = arguments.length > 2;
|
|
4
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
+
}
|
|
7
|
+
return useValue ? value : void 0;
|
|
8
|
+
};
|
|
9
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
+
var _, done = false;
|
|
15
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
+
var context = {};
|
|
17
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
+
if (kind === "accessor") {
|
|
22
|
+
if (result === void 0) continue;
|
|
23
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
+
}
|
|
28
|
+
else if (_ = accept(result)) {
|
|
29
|
+
if (kind === "field") initializers.unshift(_);
|
|
30
|
+
else descriptor[key] = _;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
+
done = true;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.GptDriverProvider = void 0;
|
|
41
|
+
const gpt_driver_node_1 = __importDefault(require("gpt-driver-node"));
|
|
42
|
+
const utils_1 = require("../utils");
|
|
43
|
+
const test_1 = __importDefault(require("@playwright/test"));
|
|
44
|
+
const MAX_INSTRUCTION_LENGTH = 10000;
|
|
45
|
+
/**
|
|
46
|
+
* GptDriverProvider wraps the gpt-driver-node SDK for AI-powered test automation.
|
|
47
|
+
*
|
|
48
|
+
* Pattern: Lazy-initialized singleton per Device instance.
|
|
49
|
+
* - Driver is created on first use (not in constructor)
|
|
50
|
+
* - Cached for subsequent calls
|
|
51
|
+
* - Gracefully skips tests when API key is not configured
|
|
52
|
+
*
|
|
53
|
+
* Similar to: VisionProvider
|
|
54
|
+
*/
|
|
55
|
+
let GptDriverProvider = (() => {
|
|
56
|
+
let _instanceExtraInitializers = [];
|
|
57
|
+
let _aiExecute_decorators;
|
|
58
|
+
let _assert_decorators;
|
|
59
|
+
let _assertBulk_decorators;
|
|
60
|
+
let _checkBulk_decorators;
|
|
61
|
+
let _extract_decorators;
|
|
62
|
+
return class GptDriverProvider {
|
|
63
|
+
static {
|
|
64
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
65
|
+
_aiExecute_decorators = [utils_1.boxedStep];
|
|
66
|
+
_assert_decorators = [utils_1.boxedStep];
|
|
67
|
+
_assertBulk_decorators = [utils_1.boxedStep];
|
|
68
|
+
_checkBulk_decorators = [utils_1.boxedStep];
|
|
69
|
+
_extract_decorators = [utils_1.boxedStep];
|
|
70
|
+
__esDecorate(this, null, _aiExecute_decorators, { kind: "method", name: "aiExecute", static: false, private: false, access: { has: obj => "aiExecute" in obj, get: obj => obj.aiExecute }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
71
|
+
__esDecorate(this, null, _assert_decorators, { kind: "method", name: "assert", static: false, private: false, access: { has: obj => "assert" in obj, get: obj => obj.assert }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
72
|
+
__esDecorate(this, null, _assertBulk_decorators, { kind: "method", name: "assertBulk", static: false, private: false, access: { has: obj => "assertBulk" in obj, get: obj => obj.assertBulk }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
73
|
+
__esDecorate(this, null, _checkBulk_decorators, { kind: "method", name: "checkBulk", static: false, private: false, access: { has: obj => "checkBulk" in obj, get: obj => obj.checkBulk }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
74
|
+
__esDecorate(this, null, _extract_decorators, { kind: "method", name: "extract", static: false, private: false, access: { has: obj => "extract" in obj, get: obj => obj.extract }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
75
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
76
|
+
}
|
|
77
|
+
webDriverClient = __runInitializers(this, _instanceExtraInitializers);
|
|
78
|
+
driver = null;
|
|
79
|
+
constructor(webDriverClient) {
|
|
80
|
+
this.webDriverClient = webDriverClient;
|
|
81
|
+
}
|
|
82
|
+
getAppiumUrl() {
|
|
83
|
+
const { protocol, hostname, port, path, user, key } = this.webDriverClient.options;
|
|
84
|
+
// Include basic auth for cloud providers (BrowserStack, LambdaTest)
|
|
85
|
+
const auth = user && key ? `${user}:${key}@` : "";
|
|
86
|
+
return `${protocol}://${auth}${hostname}:${port}${path}`;
|
|
87
|
+
}
|
|
88
|
+
getDriver() {
|
|
89
|
+
if (this.driver)
|
|
90
|
+
return this.driver;
|
|
91
|
+
const apiKey = process.env.GPT_DRIVER_API_KEY;
|
|
92
|
+
if (!apiKey) {
|
|
93
|
+
console.debug("[GptDriver] GPT_DRIVER_API_KEY not set, GPT Driver features disabled");
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
this.driver = new gpt_driver_node_1.default({
|
|
97
|
+
apiKey,
|
|
98
|
+
// gpt-driver-node expects webdriverio Browser type but webdriver Client is API-compatible at runtime
|
|
99
|
+
driver: this.webDriverClient,
|
|
100
|
+
serverConfig: { url: this.getAppiumUrl() },
|
|
101
|
+
cachingMode: "FULL_SCREEN",
|
|
102
|
+
testId: test_1.default.info()?.testId ?? `test-${Date.now()}`,
|
|
103
|
+
});
|
|
104
|
+
console.debug("[GptDriver] Initialized successfully");
|
|
105
|
+
return this.driver;
|
|
106
|
+
}
|
|
107
|
+
requireDriver() {
|
|
108
|
+
const driver = this.getDriver();
|
|
109
|
+
if (!driver) {
|
|
110
|
+
test_1.default.skip(true, "GPT Driver not configured. Set GPT_DRIVER_API_KEY environment variable.");
|
|
111
|
+
throw new Error("GPT Driver not configured");
|
|
112
|
+
}
|
|
113
|
+
return driver;
|
|
114
|
+
}
|
|
115
|
+
validateInstruction(instruction, methodName) {
|
|
116
|
+
if (!instruction || typeof instruction !== "string") {
|
|
117
|
+
throw new Error(`${methodName} requires a non-empty instruction string`);
|
|
118
|
+
}
|
|
119
|
+
if (instruction.length > MAX_INSTRUCTION_LENGTH) {
|
|
120
|
+
throw new Error(`${methodName} instruction exceeds maximum length of ${MAX_INSTRUCTION_LENGTH}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
validateConditions(conditions, methodName) {
|
|
124
|
+
if (!Array.isArray(conditions) || conditions.length === 0) {
|
|
125
|
+
throw new Error(`${methodName} requires a non-empty array of conditions`);
|
|
126
|
+
}
|
|
127
|
+
for (const condition of conditions) {
|
|
128
|
+
this.validateInstruction(condition, methodName);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
sanitizeError(error) {
|
|
132
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
133
|
+
return message.replace(/[a-zA-Z0-9]{32,}/g, "[REDACTED]");
|
|
134
|
+
}
|
|
135
|
+
async aiExecute(instruction) {
|
|
136
|
+
this.validateInstruction(instruction, "aiExecute");
|
|
137
|
+
const driver = this.requireDriver();
|
|
138
|
+
try {
|
|
139
|
+
await driver.aiExecute(instruction);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
throw new Error(`GPT Driver aiExecute failed: ${this.sanitizeError(error)}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async assert(condition) {
|
|
146
|
+
this.validateInstruction(condition, "assert");
|
|
147
|
+
const driver = this.requireDriver();
|
|
148
|
+
try {
|
|
149
|
+
await driver.assert(condition, {});
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
throw new Error(`GPT Driver assertion failed: ${this.sanitizeError(error)}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async assertBulk(conditions) {
|
|
156
|
+
this.validateConditions(conditions, "assertBulk");
|
|
157
|
+
const driver = this.requireDriver();
|
|
158
|
+
try {
|
|
159
|
+
await driver.assertBulk(conditions, {});
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
throw new Error(`GPT Driver assertBulk failed: ${this.sanitizeError(error)}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async checkBulk(conditions) {
|
|
166
|
+
this.validateConditions(conditions, "checkBulk");
|
|
167
|
+
const driver = this.requireDriver();
|
|
168
|
+
try {
|
|
169
|
+
return await driver.checkBulk(conditions);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
throw new Error(`GPT Driver checkBulk failed: ${this.sanitizeError(error)}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async extract(extractions) {
|
|
176
|
+
this.validateConditions(extractions, "extract");
|
|
177
|
+
const driver = this.requireDriver();
|
|
178
|
+
try {
|
|
179
|
+
return await driver.extract(extractions);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
throw new Error(`GPT Driver extract failed: ${this.sanitizeError(error)}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
})();
|
|
187
|
+
exports.GptDriverProvider = GptDriverProvider;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samsara-dev/appwright",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -50,7 +50,8 @@
|
|
|
50
50
|
"form-data": "4.0.5",
|
|
51
51
|
"node-fetch": "^3.3.2",
|
|
52
52
|
"picocolors": "^1.1.0",
|
|
53
|
-
"webdriver": "^8.36.1"
|
|
53
|
+
"webdriver": "^8.36.1",
|
|
54
|
+
"gpt-driver-node": "^1.0.4"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
57
|
"@changesets/cli": "^2.29.8",
|