gpt-driver-node 1.0.4 → 1.0.5
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 +37 -8
- package/dist/index.mjs +37 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1436,14 +1436,43 @@ ${"=".repeat(50)}`);
|
|
|
1436
1436
|
}
|
|
1437
1437
|
async getScreenshot(appiumSessionConfig, shouldScale = true) {
|
|
1438
1438
|
globalLogger.debug("Capturing screenshot...");
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1439
|
+
let screenshot;
|
|
1440
|
+
if (appiumSessionConfig.platform === "Android") {
|
|
1441
|
+
try {
|
|
1442
|
+
const { execSync } = await import('node:child_process');
|
|
1443
|
+
let udid;
|
|
1444
|
+
if (this.driver) {
|
|
1445
|
+
if (this.driver.sessionId != null) {
|
|
1446
|
+
const caps = this.driver.capabilities;
|
|
1447
|
+
udid = caps["appium:udid"] || caps["udid"];
|
|
1448
|
+
} else {
|
|
1449
|
+
const driver = this.driver;
|
|
1450
|
+
const capabilities = await driver.getCapabilities();
|
|
1451
|
+
udid = capabilities.get("appium:udid") || capabilities.get("udid");
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
const deviceArg = udid ? `-s ${udid}` : "";
|
|
1455
|
+
const buffer = execSync(`adb ${deviceArg} exec-out screencap -p`, {
|
|
1456
|
+
encoding: "buffer",
|
|
1457
|
+
maxBuffer: 50 * 1024 * 1024
|
|
1458
|
+
});
|
|
1459
|
+
screenshot = buffer.toString("base64");
|
|
1460
|
+
} catch (e) {
|
|
1461
|
+
globalLogger.warn("ADB screenshot failed, falling back to Appium screenshot");
|
|
1462
|
+
const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
|
|
1463
|
+
const screenshotResponse = await axios.get(url);
|
|
1464
|
+
screenshot = screenshotResponse.data.value;
|
|
1465
|
+
}
|
|
1466
|
+
} else {
|
|
1467
|
+
const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
|
|
1468
|
+
const screenshotResponse = await axios.get(url);
|
|
1469
|
+
screenshot = screenshotResponse.data.value;
|
|
1470
|
+
if (shouldScale) {
|
|
1471
|
+
globalLogger.debug(`Resizing iOS screenshot to ${appiumSessionConfig.size.width}x${appiumSessionConfig.size.height}`);
|
|
1472
|
+
const imageBuffer = Buffer.from(screenshot, "base64");
|
|
1473
|
+
const transformedImage = await sharp(imageBuffer).resize(appiumSessionConfig.size.width, appiumSessionConfig.size.height).toBuffer();
|
|
1474
|
+
screenshot = transformedImage.toString("base64");
|
|
1475
|
+
}
|
|
1447
1476
|
}
|
|
1448
1477
|
return screenshot;
|
|
1449
1478
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1434,14 +1434,43 @@ ${"=".repeat(50)}`);
|
|
|
1434
1434
|
}
|
|
1435
1435
|
async getScreenshot(appiumSessionConfig, shouldScale = true) {
|
|
1436
1436
|
globalLogger.debug("Capturing screenshot...");
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1437
|
+
let screenshot;
|
|
1438
|
+
if (appiumSessionConfig.platform === "Android") {
|
|
1439
|
+
try {
|
|
1440
|
+
const { execSync } = await import('node:child_process');
|
|
1441
|
+
let udid;
|
|
1442
|
+
if (this.driver) {
|
|
1443
|
+
if (this.driver.sessionId != null) {
|
|
1444
|
+
const caps = this.driver.capabilities;
|
|
1445
|
+
udid = caps["appium:udid"] || caps["udid"];
|
|
1446
|
+
} else {
|
|
1447
|
+
const driver = this.driver;
|
|
1448
|
+
const capabilities = await driver.getCapabilities();
|
|
1449
|
+
udid = capabilities.get("appium:udid") || capabilities.get("udid");
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
const deviceArg = udid ? `-s ${udid}` : "";
|
|
1453
|
+
const buffer = execSync(`adb ${deviceArg} exec-out screencap -p`, {
|
|
1454
|
+
encoding: "buffer",
|
|
1455
|
+
maxBuffer: 50 * 1024 * 1024
|
|
1456
|
+
});
|
|
1457
|
+
screenshot = buffer.toString("base64");
|
|
1458
|
+
} catch (e) {
|
|
1459
|
+
globalLogger.warn("ADB screenshot failed, falling back to Appium screenshot");
|
|
1460
|
+
const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
|
|
1461
|
+
const screenshotResponse = await axios.get(url);
|
|
1462
|
+
screenshot = screenshotResponse.data.value;
|
|
1463
|
+
}
|
|
1464
|
+
} else {
|
|
1465
|
+
const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
|
|
1466
|
+
const screenshotResponse = await axios.get(url);
|
|
1467
|
+
screenshot = screenshotResponse.data.value;
|
|
1468
|
+
if (shouldScale) {
|
|
1469
|
+
globalLogger.debug(`Resizing iOS screenshot to ${appiumSessionConfig.size.width}x${appiumSessionConfig.size.height}`);
|
|
1470
|
+
const imageBuffer = Buffer.from(screenshot, "base64");
|
|
1471
|
+
const transformedImage = await sharp(imageBuffer).resize(appiumSessionConfig.size.width, appiumSessionConfig.size.height).toBuffer();
|
|
1472
|
+
screenshot = transformedImage.toString("base64");
|
|
1473
|
+
}
|
|
1445
1474
|
}
|
|
1446
1475
|
return screenshot;
|
|
1447
1476
|
}
|