gpt-driver-node 1.0.0-alpha.13 → 1.0.0-alpha.15

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/dist/index.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var axios = require('axios');
4
+ var webdriverio = require('webdriverio');
4
5
  var sharp = require('sharp');
5
6
 
6
7
  const delay = async (milliseconds) => {
@@ -168,6 +169,17 @@ class GptDriver {
168
169
  }
169
170
  );
170
171
  this.gptDriverSessionId = response.data.sessionId;
172
+ if (this.useGptDriverCloud) {
173
+ const parsedUrl = new URL(response.data.appiumServerUrl);
174
+ this.driver = await webdriverio.attach({
175
+ options: {
176
+ hostname: parsedUrl.hostname,
177
+ path: parsedUrl.pathname
178
+ },
179
+ sessionId: response.data.appiumSessionId
180
+ });
181
+ this.appiumSessionStarted = true;
182
+ }
171
183
  }
172
184
  getSessionLink() {
173
185
  return `https://app.mobileboost.io/gpt-driver/sessions/${this.gptDriverSessionId}`;
@@ -392,6 +404,37 @@ class GptDriver {
392
404
  throw e;
393
405
  }
394
406
  }
407
+ /**
408
+ * Opens a deep link url in the Appium session.
409
+ *
410
+ * This method sends a request to the GPT Driver server to open a deep link url in the Appium session.
411
+ *
412
+ * @param {OpenDeepLinkUrlParams} params - The parameters for opening the deep link url.
413
+ * @returns {Promise<void>} A promise that resolves when the deep link url is opened.
414
+ */
415
+ async openDeepLinkUrl(params) {
416
+ if (!this.appiumSessionStarted) {
417
+ await this.startSession();
418
+ }
419
+ console.log("Opening deep link", params);
420
+ if (params.package == null && this.appiumSessionConfig?.platform === "Android") {
421
+ throw new Error("Package is required for Android platform");
422
+ }
423
+ await this.executeCommand(
424
+ {
425
+ url: `http://localhost:4723/session/${this.appiumSessionConfig?.id}/execute/sync`,
426
+ method: "POST",
427
+ data: {
428
+ "script": "mobile:deepLink",
429
+ "args": [{
430
+ url: params.url,
431
+ ...params.bundleId && { bundleId: params.bundleId },
432
+ ...params.package && { package: params.package }
433
+ }]
434
+ }
435
+ }
436
+ );
437
+ }
395
438
  async executeCommand(command) {
396
439
  const firstAction = command?.data?.actions?.at(0);
397
440
  if (firstAction?.type === "pause" && firstAction.duration != null) {
package/dist/index.d.cts CHANGED
@@ -20,6 +20,16 @@ interface GptDriverConfig {
20
20
  useGptDriverCloud?: boolean;
21
21
  buildId?: string;
22
22
  }
23
+ /**
24
+ * Parameters for opening a deep link url in the Appium session.
25
+ * Provide a package if the platform is Android.
26
+ * Provide a bundleId if the platform is iOS.
27
+ */
28
+ interface OpenDeepLinkUrlParams {
29
+ url: string;
30
+ package?: string;
31
+ bundleId?: string;
32
+ }
23
33
 
24
34
  declare class GptDriver {
25
35
  private apiKey;
@@ -132,6 +142,15 @@ declare class GptDriver {
132
142
  */
133
143
  extract(extractions: string[]): Promise<any>;
134
144
  private gptHandler;
145
+ /**
146
+ * Opens a deep link url in the Appium session.
147
+ *
148
+ * This method sends a request to the GPT Driver server to open a deep link url in the Appium session.
149
+ *
150
+ * @param {OpenDeepLinkUrlParams} params - The parameters for opening the deep link url.
151
+ * @returns {Promise<void>} A promise that resolves when the deep link url is opened.
152
+ */
153
+ openDeepLinkUrl(params: OpenDeepLinkUrlParams): Promise<void>;
135
154
  private executeCommand;
136
155
  private getScreenshot;
137
156
  }
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import axios from 'axios';
2
+ import { attach } from 'webdriverio';
2
3
  import sharp from 'sharp';
3
4
 
4
5
  const delay = async (milliseconds) => {
@@ -166,6 +167,17 @@ class GptDriver {
166
167
  }
167
168
  );
168
169
  this.gptDriverSessionId = response.data.sessionId;
170
+ if (this.useGptDriverCloud) {
171
+ const parsedUrl = new URL(response.data.appiumServerUrl);
172
+ this.driver = await attach({
173
+ options: {
174
+ hostname: parsedUrl.hostname,
175
+ path: parsedUrl.pathname
176
+ },
177
+ sessionId: response.data.appiumSessionId
178
+ });
179
+ this.appiumSessionStarted = true;
180
+ }
169
181
  }
170
182
  getSessionLink() {
171
183
  return `https://app.mobileboost.io/gpt-driver/sessions/${this.gptDriverSessionId}`;
@@ -390,6 +402,37 @@ class GptDriver {
390
402
  throw e;
391
403
  }
392
404
  }
405
+ /**
406
+ * Opens a deep link url in the Appium session.
407
+ *
408
+ * This method sends a request to the GPT Driver server to open a deep link url in the Appium session.
409
+ *
410
+ * @param {OpenDeepLinkUrlParams} params - The parameters for opening the deep link url.
411
+ * @returns {Promise<void>} A promise that resolves when the deep link url is opened.
412
+ */
413
+ async openDeepLinkUrl(params) {
414
+ if (!this.appiumSessionStarted) {
415
+ await this.startSession();
416
+ }
417
+ console.log("Opening deep link", params);
418
+ if (params.package == null && this.appiumSessionConfig?.platform === "Android") {
419
+ throw new Error("Package is required for Android platform");
420
+ }
421
+ await this.executeCommand(
422
+ {
423
+ url: `http://localhost:4723/session/${this.appiumSessionConfig?.id}/execute/sync`,
424
+ method: "POST",
425
+ data: {
426
+ "script": "mobile:deepLink",
427
+ "args": [{
428
+ url: params.url,
429
+ ...params.bundleId && { bundleId: params.bundleId },
430
+ ...params.package && { package: params.package }
431
+ }]
432
+ }
433
+ }
434
+ );
435
+ }
393
436
  async executeCommand(command) {
394
437
  const firstAction = command?.data?.actions?.at(0);
395
438
  if (firstAction?.type === "pause" && firstAction.duration != null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gpt-driver-node",
3
- "version": "1.0.0-alpha.13",
3
+ "version": "1.0.0-alpha.15",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.cts",