Skip to content

Commit

Permalink
bump version for release
Browse files Browse the repository at this point in the history
  • Loading branch information
saikrishna321 committed May 21, 2022
2 parents 62d5a8e + 4891cbe commit 697e864
Show file tree
Hide file tree
Showing 11 changed files with 2,874 additions and 2,499 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ The plugin will not be active unless turned on when invoking the Appium server:
```
appium server -ka 800 --use-plugins=device-farm,appium-dashboard -pa /wd/hub --plugin-device-farm-platform=android
Arguments options:
Arguments options:
* Android - If you want to use only Android devices for parallel execution.
* iOS - If you want to use only iOS devices and simulator for parallel execution.
* both - If you want to use both android and iOS devices for parallel execution.
* Execute script on specific device then set UDIDS in environment variables as UDIDS='device1UDID, device2UDID'
```

## Capabilities
Expand All @@ -54,6 +55,7 @@ Arguments options:
| appium:iPadOnly | Allocate only iPad simulators for execution when to true. Default value is `false`. |
| appium:deviceAvailabilityTimeout | When create session requests are more than available connected devices, plugin waits for a certain interval for device availability before it timeout. Default value is `180000` milliseconds. |
| appium:deviceRetryInterval | When create session requests are more than available connected devices, plugin polls for device availability in certain intervals. Default value is `10000` milliseconds. |
| appium:udids | Comma separated list of device udid's to execute tests only on specific devices `appium:udids: device1UDID,device2UDID` |

## Example

Expand Down
3,562 changes: 2,284 additions & 1,278 deletions package-lock.json

Large diffs are not rendered by default.

46 changes: 24 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appium-device-farm",
"version": "1.0.0-beta.10",
"version": "1.0.0-beta.14",
"description": "An appium 2.0 plugin that manages and create driver session on available devices",
"main": "./lib/index.js",
"scripts": {
Expand All @@ -13,7 +13,7 @@
"build": "npx tsc && npm run copy-files",
"copy-files": "cp -R src/public lib",
"buildAndCopyWeb": "sh buildAndCopyWeb.sh",
"prepublish": "npx tsc",
"prepublish": "npx tsc && npm run copy-files",
"lint": "eslint . --ext .ts,.tsx --fix",
"prettier": "prettier 'src/**/*.ts' 'web-v2/**/*.ts' 'web-v2/**/*.tsx' --write --single-quote",
"install-plugin": "npm run build && appium plugin install --source=local $(pwd)",
Expand Down Expand Up @@ -44,7 +44,7 @@
"appium-ios-device": "^2.4.1",
"async-lock": "^1.2.8",
"async-wait-until": "^2.0.5",
"axios": "^0.24.0",
"axios": "^0.26.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"get-port": "^5.1.1",
Expand All @@ -53,41 +53,43 @@
"node-cache": "^5.1.2",
"node-schedule": "^2.0.0",
"node-simctl": "^6.4.1",
"ramda": "^0.27.1",
"ramda": "^0.28.0",
"reflect-metadata": "^0.1.13",
"tcp-port-used": "^1.0.2",
"typedi": "^0.10.0",
"uuid": "^8.3.2",
"yargs": "^17.2.1"
},
"devDependencies": {
"@babel/core": "7.16.0",
"@babel/plugin-proposal-class-properties": "7.16.0",
"@types/appium-adb": "^9.4.0",
"@types/async-lock": "1.1.3",
"@types/chai": "4.2.22",
"ramda": "^0.28.0",
"@babel/core": "7.17.10",
"@babel/plugin-proposal-class-properties": "7.16.7",
"@types/async-lock": "1.1.5",
"@types/chai": "4.3.1",
"@types/express": "4.17.13",
"@types/lodash": "4.14.177",
"@types/lodash": "4.14.182",
"@types/lokijs": "1.5.7",
"@types/mocha": "9.0.0",
"@types/mocha": "9.1.1",
"@types/node-schedule": "1.3.2",
"@types/uuid": "8.3.3",
"@types/tcp-port-used": "1.0.1",
"@types/uuid": "8.3.4",
"@typescript-eslint/eslint-plugin": "4.33.0",
"@typescript-eslint/parser": "4.33.0",
"babel-eslint": "10.1.0",
"chai": "4.3.4",
"chai": "4.3.6",
"eslint": "7.32.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.25.3",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-prettier": "3.4.1",
"husky": "7.0.4",
"jest": "27.3.1",
"lint-staged": "12.0.3",
"mocha": "9.1.3",
"prettier": "2.4.1",
"jest": "27.5.1",
"lint-staged": "12.3.7",
"mocha": "9.2.2",
"prettier": "2.5.1",
"sinon": "12.0.1",
"ts-node": "10.4.0",
"typescript": "4.5.2",
"webdriverio": "7.16.8"
"ts-node": "10.7.0",
"typescript": "4.6.4",
"webdriverio": "7.17.4"
},
"appium": {
"pluginName": "device-farm",
Expand Down
22 changes: 17 additions & 5 deletions src/CapabilityManager.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
import getPort from 'get-port';
import { isPortBusy } from './helpers';

export async function androidCapabilities(
caps: { firstMatch: { [x: string]: number }[] },
freeDevice: { udid: any }
caps: { firstMatch: { [x: string]: number | string }[] },
freeDevice: { udid: any; name: string }
) {
caps.firstMatch[0]['appium:udid'] = freeDevice.udid;
caps.firstMatch[0]['appium:deviceName'] = freeDevice.udid;
caps.firstMatch[0]['appium:systemPort'] = await getPort();
caps.firstMatch[0]['appium:chromeDriverPort'] = await getPort();
caps.firstMatch[0]['appium:mjpegServerPort'] = await getPort();
}

export async function iOSCapabilities(
caps: { firstMatch: { [x: string]: number }[] },
freeDevice: { udid: any }
caps: { firstMatch: { [x: string]: number | string }[] },
freeDevice: { udid: any; name: string; realDevice: boolean; mjpegServerPort?: number }
) {
caps.firstMatch[0]['appium:udid'] = freeDevice.udid;
caps.firstMatch[0]['appium:deviceName'] = freeDevice.udid;
caps.firstMatch[0]['appium:deviceName'] = freeDevice.name;
caps.firstMatch[0]['appium:wdaLocalPort'] = await getPort();
if (freeDevice.realDevice) {
caps.firstMatch[0]['appium:mjpegServerPort'] = await getPort();
} else {
/* In simulator, port forwarding won't happen for each session. So mjpegServerPort will be used only for 1st time.
* So set the port for the first time and resuse the same port for subsequent sessions.
*/
let existingPort = freeDevice.mjpegServerPort;
caps.firstMatch[0]['appium:mjpegServerPort'] =
existingPort && (await isPortBusy(existingPort)) ? existingPort : await getPort();
}
}
4 changes: 4 additions & 0 deletions src/device-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { isMac, checkIfPathIsAbsolute } from './helpers';
import { ServerCLI } from './types/CLIArgs';

export const getDeviceTypeFromApp = (app: string) => {
/* If the test is targeting safarim, then app capability will be empty */
if (!app) {
return;
}
return app.endsWith('app') || app.endsWith('zip') ? 'simulator' : 'real';
};

Expand Down
12 changes: 12 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os from 'os';
import path from 'path';
import tcpPortUsed from 'tcp-port-used';

export async function asyncForEach(
array: string | any[],
Expand All @@ -21,3 +22,14 @@ export function isMac() {
export function checkIfPathIsAbsolute(configPath: string) {
return path.isAbsolute(configPath);
}

export async function isPortBusy(port: number) {
try {
if (!port) {
return false;
}
return await tcpPortUsed.check(port);
} catch (err) {
return false;
}
}
1 change: 1 addition & 0 deletions src/interfaces/IDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface IDevice {
realDevice: boolean;
session_id?: string;
offline?: boolean;
mjpegServerPort?: number;
}
16 changes: 14 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const customCapability = {
deviceQueryInteval: 'appium:deviceRetryInterval',
iphoneOnly: 'appium:iPhoneOnly',
ipadOnly: 'appium:iPadOnly',
udids: 'appium:udids',
};

let timer: any;
Expand All @@ -49,12 +50,18 @@ export class DevicePlugin extends BasePlugin {
Platform: {
isString: true,
},
UDIDS: {
isString: true,
required: true,
},
};
}

onUnexpectedShutdown(driver: any, cause: any) {
unblockDevice(driver.sessionId);
log.info(`Unblocking device mapped with sessionId ${driver.sessionId} onUnexpectedShutdown from server`);
log.info(
`Unblocking device mapped with sessionId ${driver.sessionId} onUnexpectedShutdown from server`
);
}

public static async updateServer(expressApp: any): Promise<void> {
Expand Down Expand Up @@ -156,6 +163,9 @@ export class DevicePlugin extends BasePlugin {
private static async updateCapabilityForDevice(capability: any, device: IDevice) {
if (device.platform.toLowerCase() == 'ios') {
await iOSCapabilities(capability, device);
await updateDevice(device, {
mjpegServerPort: capability.firstMatch[0]['appium:mjpegServerPort'],
});
} else {
await androidCapabilities(capability, device);
}
Expand All @@ -169,7 +179,9 @@ export class DevicePlugin extends BasePlugin {
*/
static getDeviceFiltersFromCapability(capability: any): IDeviceFilterOptions {
const platform: Platform = capability['platformName'].toLowerCase();
const udids = process.env.UDIDS?.split(',');
const udids = capability[customCapability.udids]
? capability[customCapability.udids].split(',')
: process.env.UDIDS?.split(',');
/* Based on the app file extension, we will decide whether to run the
* test on real device or simulator.
*
Expand Down
Loading

0 comments on commit 697e864

Please sign in to comment.