Skip to content

Commit

Permalink
Support platformVersion capability when filtering devices (#576)
Browse files Browse the repository at this point in the history
* Support platformVersion capability when filtering devices

* Bump minor version to 3.4.0

* Update README.md
  • Loading branch information
kandji-joel authored Dec 8, 2022
1 parent b633765 commit 15f6633
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ These arguments are set when you launch the Appium server, with this plugin inst
| 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` |
| appium:platformVersion | This capability is used to filter devices/simulators based on SDK. Only devices/simulators that are an exact match with the platformVerson would be considered for test run. `appium:platformVersion` is optional argument. ex: `'appium:platformVersion': 16.1.1` |
| appium:minSDK | This capability is used to filter devices/simulators based on SDK. Devices/Simulators with SDK greater then or equal to minSDK would only be considered for test run. `appium:minSDK` is optional argument. ex: `'appium:minSDK': 15` |

# Custom chrome binary url
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": "3.3.0",
"version": "3.4.0",
"description": "An appium 2.0 plugin that manages and create driver session on available devices",
"main": "./lib/index.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/data-service/device-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export function getDevice(filterOptions: IDeviceFilterOptions): IDevice {
busy: filterOptions.busy,
} as any;

if (filterOptions.platformVersion) {
filter.sdk = filterOptions.platformVersion;
}

if (filterOptions.udid) {
filter.udid = { $in: filterOptions.udid };
}
Expand Down
1 change: 1 addition & 0 deletions src/device-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export function getDeviceFiltersFromCapability(capability: any): IDeviceFilterOp
}
return {
platform,
platformVersion: capability['appium:platformVersion'] ? capability['appium:platformVersion'] : undefined,
name,
deviceType,
udid: udids?.length ? udids : undefined,
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/IDeviceFilterOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DeviceType } from '../types/DeviceType';

export interface IDeviceFilterOptions {
platform?: Platform;
platformVersion?: string;
name?: string;
busy?: boolean;
offline?: boolean;
Expand Down
36 changes: 36 additions & 0 deletions test/unit/device-service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,40 @@ describe('Get device', () => {
const device = getDevice(filterOptions);
expect(parseFloat(device.sdk)).to.be.gte(14.1);
});

it('Get android device based on filter with platformVersion', () => {
const filterOptions = {
platform: 'android',
name: '',
busy: false,
offline: false,
platformVersion: "10",
};
const device = getDevice(filterOptions);
expect(device.sdk).to.be.eql('10');
});

it('Get ios simulator based on filter with platformVersion', () => {
const filterOptions = { platform: 'ios', name: '', busy: false, offline: false, platformVersion: "14.0" };
const device = getDevice(filterOptions);
expect(device.sdk).to.be.eql('14.0');
});

it('Get android device returns undefined based on filter with platformVersion', () => {
const filterOptions = {
platform: 'android',
name: '',
busy: false,
offline: false,
platformVersion: "9",
};
const device = getDevice(filterOptions);
expect(device).to.be.undefined;
});

it('Get ios simulator returns undefined based on filter with platformVersion', () => {
const filterOptions = { platform: 'ios', name: '', busy: false, offline: false, platformVersion: "16.0" };
const device = getDevice(filterOptions);
expect(device).to.be.undefined;
});
});
5 changes: 5 additions & 0 deletions test/unit/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ describe('Device filter tests', () => {
platformName: 'iOS',
'appium:app': '/Downloads/VodQA.ipa',
'appium:iPhoneOnly': true,
'appium:platformVersion': '14.0'
},
firstMatch: [{}],
};
const firstMatch = Object.assign({}, capabilities.firstMatch[0], capabilities.alwaysMatch);
const filter = getDeviceFiltersFromCapability(firstMatch);
expect(filter).to.deep.equal({
platform: 'ios',
platformVersion: '14.0',
name: 'iPhone',
deviceType: 'real',
udid: undefined,
Expand All @@ -29,13 +31,15 @@ describe('Device filter tests', () => {
platformName: 'iOS',
'appium:app': '/Downloads/VodQA.app',
'appium:iPhoneOnly': true,
'appium:platformVersion': '14.0'
},
firstMatch: [{}],
};
const firstMatch = Object.assign({}, capabilities.firstMatch[0], capabilities.alwaysMatch);
const filter = getDeviceFiltersFromCapability(firstMatch);
expect(filter).to.deep.equal({
platform: 'ios',
platformVersion: '14.0',
name: 'iPhone',
deviceType: 'simulator',
udid: undefined,
Expand All @@ -58,6 +62,7 @@ describe('Device filter tests', () => {
const filter = getDeviceFiltersFromCapability(firstMatch);
expect(filter).to.deep.equal({
platform: 'ios',
platformVersion: undefined,
name: 'iPhone',
deviceType: 'simulator',
udid: undefined,
Expand Down

0 comments on commit 15f6633

Please sign in to comment.