Skip to content

Commit

Permalink
Allow appium inspector to work with hub/node setup (#1192)
Browse files Browse the repository at this point in the history
* Add liveVideo capability to allow inspector to work with hub/node

* Bump up version to 8.4.7-rc.43
  • Loading branch information
sudharsan-selvaraj authored Jun 21, 2024
1 parent d36fc8b commit 870d046
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ title: Capabilities
| Capability Name | Description |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| df:build | Allocate a build name in dashboard. Default value is `null`. |
| df:liveVideo | Enable live video for the session. Default value is `true`. |
| df:recordVideo | Enable video recording for the session. Default value is `false`. |
| df:videoTimeLimit | Maximum duration of the video recording in seconds. Default value is 1800 seconds (3 minutes). |
| df:iPhoneOnly | Allocate only iPhone simulators for execution when to true. Default value is `false`. |
Expand Down
1 change: 1 addition & 0 deletions documentation/docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ title: Capabilities
| Capability Name | Description |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| df:build | Allocate a build name in dashboard. Default value is `null`. |
| df:liveVideo | Enable live video for the session. Default value is `true`. |
| df:recordVideo | Enable video recording for the session. Default value is `false`. |
| df:videoTimeLimit | Maximum duration of the video recording in seconds. Default value is 1800 seconds (3 minutes). |
| df:iPhoneOnly | Allocate only iPhone simulators for execution when to true. Default value is `false`. |
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appium-device-farm",
"version": "8.4.7-rc.42",
"version": "8.4.7-rc.43",
"description": "An appium 2.0 plugin that manages and create driver session on available devices",
"main": "./lib/src/main.js",
"scripts": {
Expand Down
13 changes: 10 additions & 3 deletions src/CapabilityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ async function findAppPath(caps: any) {
return fileName;
}
}
export async function androidCapabilities(caps: ISessionCapability, freeDevice: IDevice) {
export async function androidCapabilities(
caps: ISessionCapability,
freeDevice: IDevice,
options: { liveVideo: boolean },
) {
caps.firstMatch[0]['appium:app'] = await findAppPath(caps);
caps.firstMatch[0]['appium:udid'] = freeDevice.udid;
caps.firstMatch[0]['appium:systemPort'] = await getPort();
Expand All @@ -56,7 +60,7 @@ export async function androidCapabilities(caps: ISessionCapability, freeDevice:
caps.firstMatch[0]['appium:adbPort'] = freeDevice.adbPort;
if (freeDevice.chromeDriverPath)
caps.firstMatch[0]['appium:chromedriverExecutable'] = freeDevice.chromeDriverPath;
if (!isCapabilityAlreadyPresent(caps, 'appium:mjpegServerPort')) {
if (!isCapabilityAlreadyPresent(caps, 'appium:mjpegServerPort') && !!options.liveVideo) {
caps.firstMatch[0]['appium:mjpegServerPort'] = await getPort();
}
deleteAlwaysMatch(caps, 'appium:udid');
Expand All @@ -79,13 +83,16 @@ export async function iOSCapabilities(
derivedDataPath?: string;
wdaBundleId?: string;
},
options: { liveVideo: boolean },
) {
caps.firstMatch[0]['appium:app'] = await findAppPath(caps);
caps.firstMatch[0]['appium:udid'] = freeDevice.udid;
caps.firstMatch[0]['appium:deviceName'] = freeDevice.name;
caps.firstMatch[0]['appium:platformVersion'] = freeDevice.sdk;
caps.firstMatch[0]['appium:wdaLocalPort'] = freeDevice.wdaLocalPort;
caps.firstMatch[0]['appium:mjpegServerPort'] = freeDevice.mjpegServerPort;
caps.firstMatch[0]['appium:mjpegServerPort'] = !!options.liveVideo
? freeDevice.mjpegServerPort
: undefined;
if (freeDevice.realDevice && !caps.firstMatch[0]['df:skipReport']) {
const wdaInfo = await prisma.appInformation.findFirst({
where: { fileName: 'wda-resign.ipa' },
Expand Down
13 changes: 9 additions & 4 deletions src/device-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export async function allocateDeviceForSession(
deviceFarmCapabilities[DEVICE_FARM_CAPABILITIES.DEVICE_TIMEOUT] || deviceTimeOutMs;
const intervalBetweenAttempts =
deviceFarmCapabilities[DEVICE_FARM_CAPABILITIES.DEVICE_QUERY_INTERVAL] || deviceQueryIntervalMs;
const liveVideo = deviceFarmCapabilities[DEVICE_FARM_CAPABILITIES.LIVE_VIDEO] || true;

try {
await waitUntil(
Expand Down Expand Up @@ -148,7 +149,7 @@ export async function allocateDeviceForSession(
log.info(`📱 Blocking device ${device.udid} at host ${device.host} for new session`);

// FIXME: convert this into a return value
await updateCapabilityForDevice(capability, device);
await updateCapabilityForDevice(capability, device, { liveVideo });

// update newCommandTimeout for the device.
// This is required so it won't get unblocked by prematurely.
Expand All @@ -170,12 +171,16 @@ export async function allocateDeviceForSession(
* @param device
* @returns
*/
export async function updateCapabilityForDevice(capability: any, device: IDevice) {
export async function updateCapabilityForDevice(
capability: any,
device: IDevice,
options: { liveVideo: boolean },
) {
if (!device.hasOwnProperty('cloud')) {
if (device.platform.toLowerCase() == DevicePlatform.ANDROID) {
await androidCapabilities(capability, device);
await androidCapabilities(capability, device, options);
} else {
await iOSCapabilities(capability, device);
await iOSCapabilities(capability, device, options);
}
} else {
log.info('Updating cloud capability for Device');
Expand Down

0 comments on commit 870d046

Please sign in to comment.