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

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
@@ -24,6 +24,9 @@ class GptDriver {
24
24
  appiumSessionConfig;
25
25
  driver;
26
26
  appiumSessionStarted;
27
+ useGptDriverCloud;
28
+ gptDriverCloudPlatform;
29
+ buildId;
27
30
  /**
28
31
  * Creates an instance of the GptDriver class.
29
32
  *
@@ -44,9 +47,18 @@ class GptDriver {
44
47
  */
45
48
  constructor(config) {
46
49
  this.apiKey = config.apiKey;
50
+ this.buildId = config.buildId;
51
+ this.useGptDriverCloud = config.useGptDriverCloud;
47
52
  this.gptDriverBaseUrl = "https://api.mobileboost.io";
48
- this.initializeDriver(config);
49
- this.initializeAppiumConfig(config);
53
+ if (config.useGptDriverCloud) {
54
+ if (config.serverConfig?.device?.platform == null) {
55
+ throw new Error("Platform is missing. Please specify the platform when using GPTDriver Cloud.");
56
+ }
57
+ this.gptDriverCloudPlatform = config.serverConfig.device?.platform;
58
+ } else {
59
+ this.initializeDriver(config);
60
+ this.initializeAppiumConfig(config);
61
+ }
50
62
  }
51
63
  initializeDriver(config) {
52
64
  if (config.driver) {
@@ -78,46 +90,48 @@ class GptDriver {
78
90
  */
79
91
  async startSession() {
80
92
  console.log(">> Starting session...");
81
- if (this.driver) {
82
- let platform;
83
- let platformVersion;
84
- let deviceName;
85
- let sessionId;
86
- if (this.driver.sessionId == null) {
87
- const driver = this.driver;
88
- const capabilities = await driver.getCapabilities();
89
- platform = capabilities.get("platformName");
90
- platformVersion = capabilities.get("platformVersion") ?? this.appiumSessionConfig?.platformVersion;
91
- deviceName = this.appiumSessionConfig?.deviceName ?? capabilities.get("deviceName");
92
- const session = await driver.getSession();
93
- sessionId = session.getId();
93
+ if (!this.useGptDriverCloud) {
94
+ if (this.driver) {
95
+ let platform;
96
+ let platformVersion;
97
+ let deviceName;
98
+ let sessionId;
99
+ if (this.driver.sessionId == null) {
100
+ const driver = this.driver;
101
+ const capabilities = await driver.getCapabilities();
102
+ platform = capabilities.get("platformName");
103
+ platformVersion = capabilities.get("platformVersion") ?? this.appiumSessionConfig?.platformVersion;
104
+ deviceName = this.appiumSessionConfig?.deviceName ?? capabilities.get("deviceName");
105
+ const session = await driver.getSession();
106
+ sessionId = session.getId();
107
+ } else {
108
+ const driver = this.driver;
109
+ platform = driver.capabilities["appium:platformName"] ?? driver.capabilities["platformName"];
110
+ platformVersion = driver.capabilities["appium:platformVersion"] ?? driver.capabilities["platformVersion"];
111
+ deviceName = this.appiumSessionConfig?.deviceName ?? driver.capabilities["appium:deviceName"] ?? driver.capabilities["deviceName"];
112
+ sessionId = driver.sessionId;
113
+ }
114
+ this.appiumSessionConfig = {
115
+ ...this.appiumSessionConfig,
116
+ id: sessionId,
117
+ platform,
118
+ platformVersion,
119
+ deviceName
120
+ };
94
121
  } else {
95
- const driver = this.driver;
96
- platform = driver.capabilities["appium:platformName"] ?? driver.capabilities["platformName"];
97
- platformVersion = driver.capabilities["appium:platformVersion"] ?? driver.capabilities["platformVersion"];
98
- deviceName = this.appiumSessionConfig?.deviceName ?? driver.capabilities["appium:deviceName"] ?? driver.capabilities["deviceName"];
99
- sessionId = driver.sessionId;
122
+ this.appiumSessionConfig.id = await this.createSession();
100
123
  }
101
- this.appiumSessionConfig = {
102
- ...this.appiumSessionConfig,
103
- id: sessionId,
104
- platform,
105
- platformVersion,
106
- deviceName
124
+ const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/window/rect`);
125
+ const rectResponse = await axios.get(
126
+ url
127
+ );
128
+ this.appiumSessionConfig.size = {
129
+ width: rectResponse.data.value.width,
130
+ height: rectResponse.data.value.height
107
131
  };
108
- } else {
109
- this.appiumSessionConfig.id = await this.createSession();
132
+ this.appiumSessionStarted = true;
110
133
  }
111
134
  await this.createGptDriverSession();
112
- const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/window/rect`);
113
- const rectResponse = await axios.get(
114
- url
115
- );
116
- this.appiumSessionConfig.size = {
117
- width: rectResponse.data.value.width,
118
- height: rectResponse.data.value.height
119
- };
120
- this.appiumSessionStarted = true;
121
135
  console.log(`>> Session created. Monitor execution at: ${this.getSessionLink()}`);
122
136
  }
123
137
  async createSession() {
@@ -143,12 +157,14 @@ class GptDriver {
143
157
  `${this.gptDriverBaseUrl}/sessions/create`,
144
158
  {
145
159
  api_key: this.apiKey,
146
- appium_session_id: this.appiumSessionConfig.id,
160
+ appium_session_id: this.appiumSessionConfig?.id,
147
161
  device_config: {
148
- platform: this.appiumSessionConfig.platform,
149
- device: this.appiumSessionConfig.deviceName,
150
- os: this.appiumSessionConfig.platformVersion
151
- }
162
+ platform: this.appiumSessionConfig?.platform ?? this.gptDriverCloudPlatform,
163
+ device: this.appiumSessionConfig?.deviceName,
164
+ os: this.appiumSessionConfig?.platformVersion
165
+ },
166
+ use_internal_virtual_device: this.useGptDriverCloud,
167
+ build_id: this.buildId
152
168
  }
153
169
  );
154
170
  this.gptDriverSessionId = response.data.sessionId;
@@ -168,17 +184,19 @@ class GptDriver {
168
184
  * @throws {Error} If the request to stop the session fails.
169
185
  */
170
186
  async setSessionStatus(status) {
171
- console.log(">> Stopping session...");
172
- await axios.post(
173
- `${this.gptDriverBaseUrl}/sessions/${this.gptDriverSessionId}/stop`,
174
- {
175
- api_key: this.apiKey,
176
- status
177
- }
178
- );
179
- console.log(">> Session stopped.");
180
- this.appiumSessionStarted = false;
181
- this.gptDriverSessionId = void 0;
187
+ if (this.gptDriverSessionId) {
188
+ console.log(">> Stopping session...");
189
+ await axios.post(
190
+ `${this.gptDriverBaseUrl}/sessions/${this.gptDriverSessionId}/stop`,
191
+ {
192
+ api_key: this.apiKey,
193
+ status
194
+ }
195
+ );
196
+ console.log(">> Session stopped.");
197
+ this.appiumSessionStarted = false;
198
+ this.gptDriverSessionId = void 0;
199
+ }
182
200
  }
183
201
  /**
184
202
  * Executes a specified command within the WebDriver session, optionally using an Appium handler.
@@ -228,10 +246,15 @@ class GptDriver {
228
246
  if (!this.appiumSessionStarted) {
229
247
  await this.startSession();
230
248
  }
231
- console.log(">> Asserting:", assertion);
232
- const results = await this.checkBulk([assertion]);
233
- if (!Object.values(results).at(0)) {
234
- throw new Error(`Failed assertion: ${assertion}`);
249
+ try {
250
+ const results = await this.checkBulk([assertion]);
251
+ if (!Object.values(results).at(0)) {
252
+ await this.setSessionStatus("failed");
253
+ throw new Error(`Failed assertion: ${assertion}`);
254
+ }
255
+ } catch (e) {
256
+ await this.setSessionStatus("failed");
257
+ throw e;
235
258
  }
236
259
  }
237
260
  /**
@@ -247,16 +270,21 @@ class GptDriver {
247
270
  if (!this.appiumSessionStarted) {
248
271
  await this.startSession();
249
272
  }
250
- console.log(">> Asserting:", assertions);
251
- const results = await this.checkBulk(assertions);
252
- const failedAssertions = Object.values(results).reduce((prev, current, currentIndex) => {
253
- if (!current) {
254
- return [...prev, assertions.at(currentIndex)];
273
+ try {
274
+ const results = await this.checkBulk(assertions);
275
+ const failedAssertions = Object.values(results).reduce((prev, current, currentIndex) => {
276
+ if (!current) {
277
+ return [...prev, assertions.at(currentIndex)];
278
+ }
279
+ return prev;
280
+ }, []);
281
+ if (failedAssertions.length > 0) {
282
+ await this.setSessionStatus("failed");
283
+ throw new Error(`Failed assertions: ${failedAssertions.join(", ")}`);
255
284
  }
256
- return prev;
257
- }, []);
258
- if (failedAssertions.length > 0) {
259
- throw new Error(`Failed assertions: ${failedAssertions.join(", ")}`);
285
+ } catch (e) {
286
+ await this.setSessionStatus("failed");
287
+ throw e;
260
288
  }
261
289
  }
262
290
  /**
@@ -273,17 +301,25 @@ class GptDriver {
273
301
  await this.startSession();
274
302
  }
275
303
  console.log(">> Checking:", conditions);
276
- const screenshot = await this.getScreenshot(this.appiumSessionConfig);
277
- const response = await axios.post(
278
- `${this.gptDriverBaseUrl}/sessions/${this.gptDriverSessionId}/assert`,
279
- {
280
- api_key: this.apiKey,
281
- base64_screenshot: screenshot,
282
- assertions: conditions,
283
- command: `Assert: ${JSON.stringify(conditions)}`
304
+ try {
305
+ let screenshot;
306
+ if (!this.useGptDriverCloud) {
307
+ screenshot = await this.getScreenshot(this.appiumSessionConfig);
284
308
  }
285
- );
286
- return response.data.results;
309
+ const response = await axios.post(
310
+ `${this.gptDriverBaseUrl}/sessions/${this.gptDriverSessionId}/assert`,
311
+ {
312
+ api_key: this.apiKey,
313
+ base64_screenshot: screenshot,
314
+ assertions: conditions,
315
+ command: `Assert: ${JSON.stringify(conditions)}`
316
+ }
317
+ );
318
+ return response.data.results;
319
+ } catch (e) {
320
+ await this.setSessionStatus("failed");
321
+ throw e;
322
+ }
287
323
  }
288
324
  /**
289
325
  * Extracts specified information using the GPTDriver.
@@ -302,7 +338,10 @@ class GptDriver {
302
338
  await this.startSession();
303
339
  }
304
340
  console.log(">> Extracting:", extractions);
305
- const screenshot = await this.getScreenshot(this.appiumSessionConfig);
341
+ let screenshot;
342
+ if (!this.useGptDriverCloud) {
343
+ screenshot = await this.getScreenshot(this.appiumSessionConfig);
344
+ }
306
345
  const response = await axios.post(
307
346
  `${this.gptDriverBaseUrl}/sessions/${this.gptDriverSessionId}/extract`,
308
347
  {
@@ -318,7 +357,10 @@ class GptDriver {
318
357
  try {
319
358
  let conditionSucceeded = false;
320
359
  while (!conditionSucceeded) {
321
- const screenshot = await this.getScreenshot(this.appiumSessionConfig);
360
+ let screenshot;
361
+ if (!this.useGptDriverCloud) {
362
+ screenshot = await this.getScreenshot(this.appiumSessionConfig);
363
+ }
322
364
  console.log(">> Asking GTP Driver for next action...");
323
365
  const response = await axios.request(
324
366
  {
@@ -351,10 +393,10 @@ class GptDriver {
351
393
  }
352
394
  }
353
395
  async executeCommand(command) {
354
- const firstAction = command.data.actions?.at(0);
396
+ const firstAction = command?.data?.actions?.at(0);
355
397
  if (firstAction?.type === "pause" && firstAction.duration != null) {
356
398
  await delay(firstAction * 1e3);
357
- } else {
399
+ } else if (!this.useGptDriverCloud) {
358
400
  const parsedUrl = new URL(command.url);
359
401
  parsedUrl.protocol = this.appiumSessionConfig.serverUrl.protocol;
360
402
  parsedUrl.host = this.appiumSessionConfig.serverUrl.host;
package/dist/index.d.cts CHANGED
@@ -17,6 +17,8 @@ interface GptDriverConfig {
17
17
  device?: ServerSessionInitConfig;
18
18
  url?: URL | string;
19
19
  };
20
+ useGptDriverCloud?: boolean;
21
+ buildId?: string;
20
22
  }
21
23
 
22
24
  declare class GptDriver {
@@ -26,6 +28,9 @@ declare class GptDriver {
26
28
  private appiumSessionConfig?;
27
29
  private driver?;
28
30
  private appiumSessionStarted?;
31
+ private useGptDriverCloud?;
32
+ private gptDriverCloudPlatform?;
33
+ private buildId?;
29
34
  /**
30
35
  * Creates an instance of the GptDriver class.
31
36
  *
package/dist/index.mjs CHANGED
@@ -22,6 +22,9 @@ class GptDriver {
22
22
  appiumSessionConfig;
23
23
  driver;
24
24
  appiumSessionStarted;
25
+ useGptDriverCloud;
26
+ gptDriverCloudPlatform;
27
+ buildId;
25
28
  /**
26
29
  * Creates an instance of the GptDriver class.
27
30
  *
@@ -42,9 +45,18 @@ class GptDriver {
42
45
  */
43
46
  constructor(config) {
44
47
  this.apiKey = config.apiKey;
48
+ this.buildId = config.buildId;
49
+ this.useGptDriverCloud = config.useGptDriverCloud;
45
50
  this.gptDriverBaseUrl = "https://api.mobileboost.io";
46
- this.initializeDriver(config);
47
- this.initializeAppiumConfig(config);
51
+ if (config.useGptDriverCloud) {
52
+ if (config.serverConfig?.device?.platform == null) {
53
+ throw new Error("Platform is missing. Please specify the platform when using GPTDriver Cloud.");
54
+ }
55
+ this.gptDriverCloudPlatform = config.serverConfig.device?.platform;
56
+ } else {
57
+ this.initializeDriver(config);
58
+ this.initializeAppiumConfig(config);
59
+ }
48
60
  }
49
61
  initializeDriver(config) {
50
62
  if (config.driver) {
@@ -76,46 +88,48 @@ class GptDriver {
76
88
  */
77
89
  async startSession() {
78
90
  console.log(">> Starting session...");
79
- if (this.driver) {
80
- let platform;
81
- let platformVersion;
82
- let deviceName;
83
- let sessionId;
84
- if (this.driver.sessionId == null) {
85
- const driver = this.driver;
86
- const capabilities = await driver.getCapabilities();
87
- platform = capabilities.get("platformName");
88
- platformVersion = capabilities.get("platformVersion") ?? this.appiumSessionConfig?.platformVersion;
89
- deviceName = this.appiumSessionConfig?.deviceName ?? capabilities.get("deviceName");
90
- const session = await driver.getSession();
91
- sessionId = session.getId();
91
+ if (!this.useGptDriverCloud) {
92
+ if (this.driver) {
93
+ let platform;
94
+ let platformVersion;
95
+ let deviceName;
96
+ let sessionId;
97
+ if (this.driver.sessionId == null) {
98
+ const driver = this.driver;
99
+ const capabilities = await driver.getCapabilities();
100
+ platform = capabilities.get("platformName");
101
+ platformVersion = capabilities.get("platformVersion") ?? this.appiumSessionConfig?.platformVersion;
102
+ deviceName = this.appiumSessionConfig?.deviceName ?? capabilities.get("deviceName");
103
+ const session = await driver.getSession();
104
+ sessionId = session.getId();
105
+ } else {
106
+ const driver = this.driver;
107
+ platform = driver.capabilities["appium:platformName"] ?? driver.capabilities["platformName"];
108
+ platformVersion = driver.capabilities["appium:platformVersion"] ?? driver.capabilities["platformVersion"];
109
+ deviceName = this.appiumSessionConfig?.deviceName ?? driver.capabilities["appium:deviceName"] ?? driver.capabilities["deviceName"];
110
+ sessionId = driver.sessionId;
111
+ }
112
+ this.appiumSessionConfig = {
113
+ ...this.appiumSessionConfig,
114
+ id: sessionId,
115
+ platform,
116
+ platformVersion,
117
+ deviceName
118
+ };
92
119
  } else {
93
- const driver = this.driver;
94
- platform = driver.capabilities["appium:platformName"] ?? driver.capabilities["platformName"];
95
- platformVersion = driver.capabilities["appium:platformVersion"] ?? driver.capabilities["platformVersion"];
96
- deviceName = this.appiumSessionConfig?.deviceName ?? driver.capabilities["appium:deviceName"] ?? driver.capabilities["deviceName"];
97
- sessionId = driver.sessionId;
120
+ this.appiumSessionConfig.id = await this.createSession();
98
121
  }
99
- this.appiumSessionConfig = {
100
- ...this.appiumSessionConfig,
101
- id: sessionId,
102
- platform,
103
- platformVersion,
104
- deviceName
122
+ const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/window/rect`);
123
+ const rectResponse = await axios.get(
124
+ url
125
+ );
126
+ this.appiumSessionConfig.size = {
127
+ width: rectResponse.data.value.width,
128
+ height: rectResponse.data.value.height
105
129
  };
106
- } else {
107
- this.appiumSessionConfig.id = await this.createSession();
130
+ this.appiumSessionStarted = true;
108
131
  }
109
132
  await this.createGptDriverSession();
110
- const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/window/rect`);
111
- const rectResponse = await axios.get(
112
- url
113
- );
114
- this.appiumSessionConfig.size = {
115
- width: rectResponse.data.value.width,
116
- height: rectResponse.data.value.height
117
- };
118
- this.appiumSessionStarted = true;
119
133
  console.log(`>> Session created. Monitor execution at: ${this.getSessionLink()}`);
120
134
  }
121
135
  async createSession() {
@@ -141,12 +155,14 @@ class GptDriver {
141
155
  `${this.gptDriverBaseUrl}/sessions/create`,
142
156
  {
143
157
  api_key: this.apiKey,
144
- appium_session_id: this.appiumSessionConfig.id,
158
+ appium_session_id: this.appiumSessionConfig?.id,
145
159
  device_config: {
146
- platform: this.appiumSessionConfig.platform,
147
- device: this.appiumSessionConfig.deviceName,
148
- os: this.appiumSessionConfig.platformVersion
149
- }
160
+ platform: this.appiumSessionConfig?.platform ?? this.gptDriverCloudPlatform,
161
+ device: this.appiumSessionConfig?.deviceName,
162
+ os: this.appiumSessionConfig?.platformVersion
163
+ },
164
+ use_internal_virtual_device: this.useGptDriverCloud,
165
+ build_id: this.buildId
150
166
  }
151
167
  );
152
168
  this.gptDriverSessionId = response.data.sessionId;
@@ -166,17 +182,19 @@ class GptDriver {
166
182
  * @throws {Error} If the request to stop the session fails.
167
183
  */
168
184
  async setSessionStatus(status) {
169
- console.log(">> Stopping session...");
170
- await axios.post(
171
- `${this.gptDriverBaseUrl}/sessions/${this.gptDriverSessionId}/stop`,
172
- {
173
- api_key: this.apiKey,
174
- status
175
- }
176
- );
177
- console.log(">> Session stopped.");
178
- this.appiumSessionStarted = false;
179
- this.gptDriverSessionId = void 0;
185
+ if (this.gptDriverSessionId) {
186
+ console.log(">> Stopping session...");
187
+ await axios.post(
188
+ `${this.gptDriverBaseUrl}/sessions/${this.gptDriverSessionId}/stop`,
189
+ {
190
+ api_key: this.apiKey,
191
+ status
192
+ }
193
+ );
194
+ console.log(">> Session stopped.");
195
+ this.appiumSessionStarted = false;
196
+ this.gptDriverSessionId = void 0;
197
+ }
180
198
  }
181
199
  /**
182
200
  * Executes a specified command within the WebDriver session, optionally using an Appium handler.
@@ -226,10 +244,15 @@ class GptDriver {
226
244
  if (!this.appiumSessionStarted) {
227
245
  await this.startSession();
228
246
  }
229
- console.log(">> Asserting:", assertion);
230
- const results = await this.checkBulk([assertion]);
231
- if (!Object.values(results).at(0)) {
232
- throw new Error(`Failed assertion: ${assertion}`);
247
+ try {
248
+ const results = await this.checkBulk([assertion]);
249
+ if (!Object.values(results).at(0)) {
250
+ await this.setSessionStatus("failed");
251
+ throw new Error(`Failed assertion: ${assertion}`);
252
+ }
253
+ } catch (e) {
254
+ await this.setSessionStatus("failed");
255
+ throw e;
233
256
  }
234
257
  }
235
258
  /**
@@ -245,16 +268,21 @@ class GptDriver {
245
268
  if (!this.appiumSessionStarted) {
246
269
  await this.startSession();
247
270
  }
248
- console.log(">> Asserting:", assertions);
249
- const results = await this.checkBulk(assertions);
250
- const failedAssertions = Object.values(results).reduce((prev, current, currentIndex) => {
251
- if (!current) {
252
- return [...prev, assertions.at(currentIndex)];
271
+ try {
272
+ const results = await this.checkBulk(assertions);
273
+ const failedAssertions = Object.values(results).reduce((prev, current, currentIndex) => {
274
+ if (!current) {
275
+ return [...prev, assertions.at(currentIndex)];
276
+ }
277
+ return prev;
278
+ }, []);
279
+ if (failedAssertions.length > 0) {
280
+ await this.setSessionStatus("failed");
281
+ throw new Error(`Failed assertions: ${failedAssertions.join(", ")}`);
253
282
  }
254
- return prev;
255
- }, []);
256
- if (failedAssertions.length > 0) {
257
- throw new Error(`Failed assertions: ${failedAssertions.join(", ")}`);
283
+ } catch (e) {
284
+ await this.setSessionStatus("failed");
285
+ throw e;
258
286
  }
259
287
  }
260
288
  /**
@@ -271,17 +299,25 @@ class GptDriver {
271
299
  await this.startSession();
272
300
  }
273
301
  console.log(">> Checking:", conditions);
274
- const screenshot = await this.getScreenshot(this.appiumSessionConfig);
275
- const response = await axios.post(
276
- `${this.gptDriverBaseUrl}/sessions/${this.gptDriverSessionId}/assert`,
277
- {
278
- api_key: this.apiKey,
279
- base64_screenshot: screenshot,
280
- assertions: conditions,
281
- command: `Assert: ${JSON.stringify(conditions)}`
302
+ try {
303
+ let screenshot;
304
+ if (!this.useGptDriverCloud) {
305
+ screenshot = await this.getScreenshot(this.appiumSessionConfig);
282
306
  }
283
- );
284
- return response.data.results;
307
+ const response = await axios.post(
308
+ `${this.gptDriverBaseUrl}/sessions/${this.gptDriverSessionId}/assert`,
309
+ {
310
+ api_key: this.apiKey,
311
+ base64_screenshot: screenshot,
312
+ assertions: conditions,
313
+ command: `Assert: ${JSON.stringify(conditions)}`
314
+ }
315
+ );
316
+ return response.data.results;
317
+ } catch (e) {
318
+ await this.setSessionStatus("failed");
319
+ throw e;
320
+ }
285
321
  }
286
322
  /**
287
323
  * Extracts specified information using the GPTDriver.
@@ -300,7 +336,10 @@ class GptDriver {
300
336
  await this.startSession();
301
337
  }
302
338
  console.log(">> Extracting:", extractions);
303
- const screenshot = await this.getScreenshot(this.appiumSessionConfig);
339
+ let screenshot;
340
+ if (!this.useGptDriverCloud) {
341
+ screenshot = await this.getScreenshot(this.appiumSessionConfig);
342
+ }
304
343
  const response = await axios.post(
305
344
  `${this.gptDriverBaseUrl}/sessions/${this.gptDriverSessionId}/extract`,
306
345
  {
@@ -316,7 +355,10 @@ class GptDriver {
316
355
  try {
317
356
  let conditionSucceeded = false;
318
357
  while (!conditionSucceeded) {
319
- const screenshot = await this.getScreenshot(this.appiumSessionConfig);
358
+ let screenshot;
359
+ if (!this.useGptDriverCloud) {
360
+ screenshot = await this.getScreenshot(this.appiumSessionConfig);
361
+ }
320
362
  console.log(">> Asking GTP Driver for next action...");
321
363
  const response = await axios.request(
322
364
  {
@@ -349,10 +391,10 @@ class GptDriver {
349
391
  }
350
392
  }
351
393
  async executeCommand(command) {
352
- const firstAction = command.data.actions?.at(0);
394
+ const firstAction = command?.data?.actions?.at(0);
353
395
  if (firstAction?.type === "pause" && firstAction.duration != null) {
354
396
  await delay(firstAction * 1e3);
355
- } else {
397
+ } else if (!this.useGptDriverCloud) {
356
398
  const parsedUrl = new URL(command.url);
357
399
  parsedUrl.protocol = this.appiumSessionConfig.serverUrl.protocol;
358
400
  parsedUrl.host = this.appiumSessionConfig.serverUrl.host;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gpt-driver-node",
3
- "version": "1.0.0-alpha.12",
3
+ "version": "1.0.0-alpha.13",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.cts",