Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unique udid for cloud devices #972

Merged
merged 3 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 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.3",
"version": "8.4.7-rc.4",
"description": "An appium 2.0 plugin that manages and create driver session on available devices",
"main": "./lib/src/index.js",
"scripts": {
Expand Down Expand Up @@ -149,6 +149,7 @@
"babel-eslint": "10.1.0",
"chai": "4.3.10",
"chai-as-promised": "^7.1.1",
"chai-exclude": "^2.1.0",
"dotenv": "^16.3.1",
"eslint": "8.52.0",
"eslint-config-prettier": "9.0.0",
Expand Down
9 changes: 7 additions & 2 deletions serverConfig/bs-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
"url": "http://hub-cloud.browserstack.com/wd/hub",
"devices": [
{
"deviceName": "Google Pixel 3",
"os_version": "9.0",
"deviceName": "Samsung Galaxy S21",
"os_version": "12.0",
"platform": "android"
},
{
"deviceName": "Samsung Galaxy S21",
"os_version": "12.0",
"platform": "android"
},
{
Expand Down
5 changes: 2 additions & 3 deletions src/device-managers/cloud/Devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import logger from '../../logger';
import { Schema, Validator } from 'jsonschema';
import { CloudConfig, CloudDevice } from '../../interfaces/IPluginArgs';
import { v4 as uuidv4 } from 'uuid';

export default class Devices {
private devices: CloudDevice[];
Expand All @@ -33,28 +34,26 @@ export default class Devices {
cloudDeviceProperties = {
name: d.deviceName,
sdk: d['os_version'],
udid: d.deviceName,
};
}
if (this.isSauceLabs() || this.isLambdaTest() || this.isHeadSpin()) {
this.validateSchema(sauceOrLambdaSchema);
cloudDeviceProperties = {
name: d.deviceName,
sdk: d.platformVersion,
udid: d.deviceName,
};
}
if (this.isPCloudy()) {
this.validateSchema(pCloudySchema);
cloudDeviceProperties = {
name: d?.pCloudy_DeviceFullName || d?.pCloudy_DeviceManufacturer,
sdk: d?.pCloudy_DeviceVersion || d?.platformVersion,
udid: d?.pCloudy_DeviceFullName || d?.pCloudy_DeviceManufacturer,
};
}
return Object.assign({}, ...devicesByPlatform, {
host: this.cloud.url,
busy: false,
udid: uuidv4(),
userBlocked: false,
deviceType: 'real',
capability: d,
Expand Down
14 changes: 9 additions & 5 deletions test/e2e/android/cloud/bs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ describe('BrowserStack: Plugin Test', () => {

it('Vertical swipe test', async () => {
console.log(`Device UDID: ${await driver.capabilities.deviceUDID}`);
const currentBusyDevices = await busyDevices();
console.log(`currentBusyDevices: ${JSON.stringify(currentBusyDevices)}`);

// the same number of devices should be busy
expect(currentBusyDevices.length).to.equal(1);
await driver.performActions([
{
type: 'pointer',
Expand Down Expand Up @@ -90,7 +95,10 @@ describe('BrowserStack: Plugin Test', () => {
}
});
});

async function busyDevices() {
const res = await axios.get(`http://${APPIUM_HOST}:${HUB_APPIUM_PORT}/device-farm/api/device`);
return res.data.filter((device: any) => device.busy === true);
}
describe('Browser Stack: Quirks', () => {
// dump hub config into a file
const hub_config_file = path.join(__dirname, '../../../../serverConfig/bs-config.json');
Expand All @@ -116,10 +124,6 @@ describe('Browser Stack: Quirks', () => {
appiumHome: APPIUM_HOME!,
});

async function busyDevices() {
const res = await axios.get(`http://${APPIUM_HOST}:${HUB_APPIUM_PORT}/device-farm/api/device`);
return res.data.filter((device: any) => device.busy === true);
}
it('handles empty session id when app is invalid', async () => {
capabilities['appium:app'] = 'bs://invalid-app-id';
const initialBusyDevices = await busyDevices();
Expand Down
70 changes: 39 additions & 31 deletions test/e2e/browserstack.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
import ip from 'ip';
import path from 'path';
import { IDevice } from '../../src/interfaces/IDevice';
import * as chai from 'chai';
import chaiExclude from 'chai-exclude';

chai.use(chaiExclude);

describe('Browserstack Devices', () => {
// dump hub config into a file
Expand Down Expand Up @@ -45,21 +49,23 @@ describe('Browserstack Devices', () => {
androidDevices = androidDevices.filter((device: IDevice) => device.cloud === 'browserstack');
delete androidDevices[0].meta;
delete androidDevices[0]['$loki'];
expect(androidDevices[0]).to.deep.equal({
deviceName: 'Google Pixel 3',
os_version: '9.0',
platform: 'android',
host: 'http://hub-cloud.browserstack.com/wd/hub',
busy: false,
userBlocked: false,
deviceType: 'real',
capability: { deviceName: 'Google Pixel 3', os_version: '9.0', platform: 'android' },
cloud: 'browserstack',
name: 'Google Pixel 3',
sdk: '9.0',
udid: 'Google Pixel 3',
offline: false,
});
expect(androidDevices[0])
.excluding('udid')
.to.deep.equal({
deviceName: 'Samsung Galaxy S21',
os_version: '12.0',
platform: 'android',
host: 'http://hub-cloud.browserstack.com/wd/hub',
busy: false,
userBlocked: false,
deviceType: 'real',
capability: { deviceName: 'Samsung Galaxy S21', os_version: '12.0', platform: 'android' },
cloud: 'browserstack',
name: 'Samsung Galaxy S21',
sdk: '12.0',
udid: 'Google Pixel 3',
offline: false,
});
});

it('Should be able to run the plugin with Browerstack config', async () => {
Expand All @@ -72,24 +78,26 @@ describe('Browserstack Devices', () => {
iosDevices = iosDevices.filter((device: IDevice) => device.cloud === 'browserstack');
delete iosDevices[0].meta;
delete iosDevices[0]['$loki'];
expect(iosDevices[0]).to.deep.equal({
deviceName: 'iPhone XS',
os_version: '15',
platform: 'ios',
host: 'http://hub-cloud.browserstack.com/wd/hub',
busy: false,
userBlocked: false,
deviceType: 'real',
capability: {
expect(iosDevices[0])
.excluding('udid')
.to.deep.equal({
deviceName: 'iPhone XS',
os_version: '15',
platform: 'ios',
},
cloud: 'browserstack',
name: 'iPhone XS',
sdk: '15',
udid: 'iPhone XS',
offline: false,
});
host: 'http://hub-cloud.browserstack.com/wd/hub',
busy: false,
userBlocked: false,
deviceType: 'real',
capability: {
deviceName: 'iPhone XS',
os_version: '15',
platform: 'ios',
},
cloud: 'browserstack',
name: 'iPhone XS',
sdk: '15',
udid: 'iPhone XS',
offline: false,
});
});
});
Loading
Loading