Skip to content

Commit

Permalink
support for pCloudy (#593)
Browse files Browse the repository at this point in the history
* support for pCloudy

* bump version

* fix azure yaml

* fix pCloudy run
  • Loading branch information
saikrishna321 authored Dec 24, 2022
1 parent d750877 commit bf270eb
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 10 deletions.
17 changes: 17 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ jobs:
npm run test-e2e-browserstack
displayName: 'E2E Test'
- job: E2EPluginPCloudy
pool:
vmImage: 'macOS-latest'

steps:
- task: [email protected]
inputs:
versionSpec: '16.x'

- script: |
npm ci
export APPIUM_HOME=/tmp/device-farm
./node_modules/.bin/appium plugin install --source=local .
nohup ./node_modules/.bin/appium server -ka 800 --use-plugins=device-farm -pa /wd/hub --config=./serverConfig/pcloudy-config.json &
npm run test-e2e-pCloudy
displayName: 'E2E Test'
- job: BrowserStack
pool:
vmImage: 'macOS-latest'
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.

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": "3.8.0",
"version": "3.9.0",
"description": "An appium 2.0 plugin that manages and create driver session on available devices",
"main": "./lib/index.js",
"scripts": {
Expand All @@ -11,6 +11,7 @@
"test-parallel-ios": "wait-on http://localhost:4723/device-farm/ && mocha --require ts-node/register -p ./test/e2e/ios/*.spec.js --timeout 260000",
"test-e2e": "wait-on http://localhost:31337/device-farm/ && mocha --require ts-node/register ./test/e2e/plugin.spec.js --timeout 999999",
"test-e2e-browserstack": "wait-on http://localhost:31337/device-farm/ && mocha --require ts-node/register ./test/e2e/browserstack.spec.js --timeout 999999",
"test-e2e-pCloudy": "wait-on http://localhost:31337/device-farm/ && mocha --require ts-node/register ./test/e2e/pcloudy.spec.js --timeout 999999",
"integration-android": "mocha -r ts-node/register ./test/integration/androidDevices.spec.js --timeout 90000 --exit",
"integration-ios": "mocha -r ts-node/register ./test/integration/iOS*.spec.js --timeout 260000 --exit",
"build": "npx tsc && npm run copy-files",
Expand Down
28 changes: 28 additions & 0 deletions serverConfig/pcloudy-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"server": {
"port": 31337,
"plugin": {
"device-farm": {
"platform": "both",
"remote": [
{
"cloudName": "pCloudy",
"url": "https://device.pcloudy.com/appiumcloud/wd/hub",
"devices": [
{
"pCloudy_DeviceManufacturer": "GOOGLE",
"pCloudy_DeviceVersion": "11.0",
"platform": "android"
},
{
"pCloudy_DeviceManufacturer": "APPLE",
"pCloudy_DeviceVersion": "15.1",
"platform": "ios"
}
]
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-prototype-builtins */
import { IDevice } from '../../../interfaces/IDevice';
import { CloudArgs } from '../../../types/CloudArgs';
import Cloud from '../../enums/Cloud';
import { IDevice } from '../../interfaces/IDevice';
import { CloudArgs } from '../../types/CloudArgs';
export default class Devices {
private host: any;
private deviceState: any;
Expand All @@ -16,13 +17,20 @@ export default class Devices {
const devicesByPlatform = devices.filter((value: any) => value.platform === this.platform);
let cloudDeviceProperties: any;
const result = devicesByPlatform.map((d: any) => {
if (this.host.cloudName.toLowerCase() === 'browserstack') {
if (this.host.cloudName.toLowerCase() === Cloud.BROWSERSTACK) {
cloudDeviceProperties = {
name: d.deviceName,
sdk: d['os_version'],
udid: d.deviceName,
};
}
if (this.host.cloudName.toLowerCase() === Cloud.PCLOUDY) {
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.host.url,
busy: false,
Expand Down
4 changes: 2 additions & 2 deletions src/device-managers/factory/DeviceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { isObject } from 'lodash';
import Cloud from '../../enums/Cloud';
import { CloudArgs } from '../../types/CloudArgs';
import DevicePlatform from '../../enums/Platform';
import Devices from '../cloud/browserstack/Devices';
import Devices from '../cloud/Devices';

export class DeviceFactory {
public static deviceInstance(host: CloudArgs, deviceState: IDevice[], platform: string) {
if (isObject(host) && host.cloudName === Cloud.BROWSERSTACK) {
if (isObject(host) && host.cloudName) {
return new Devices(host, deviceState, platform);
} else if (platform == DevicePlatform.ANDROID) {
return new RemoteAndroidDeviceManager(host, deviceState);
Expand Down
1 change: 1 addition & 0 deletions src/enums/Cloud.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
enum Cloud {
BROWSERSTACK = 'browserstack',
PCLOUDY = 'pcloudy',
}

export default Cloud;
2 changes: 2 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export async function getFreePort() {
export function hubUrl(device: IDevice) {
if (device.hasOwnProperty('cloud') && device.cloud === 'browserstack') {
return `https://${process.env.BS_USERNAME}:${process.env.BS_PASSWORD}@hub.browserstack.com/wd/hub/session`;
} else if (device.hasOwnProperty('cloud') && device.cloud === 'pCloudy') {
return 'https://device.pcloudy.com/appiumcloud/wd/hub/session';
}
return `${device.host}/wd/hub/session`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class DevicePlugin extends BasePlugin {
(v: any) => typeof v === 'object'
);
if (cloudExists.length > 0)
cloudExists[0].cloudName === Cloud.BROWSERSTACK ? (deviceTypes = 'real') : true;
cloudExists[0].hasOwnProperty('cloudName') ? (deviceTypes = 'real') : true;
if (deviceTypes === 'real') logger.info('ℹ️ Skipping Simulators as per the configuration ℹ️');
return deviceTypes;
}
Expand Down
1 change: 0 additions & 1 deletion test/e2e/browserstack.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ describe('Browserstack Devices', () => {
.data;
delete androidDevices[0].meta;
delete androidDevices[0]['$loki'];
console.log(androidDevices[0])
expect(androidDevices[0]).to.deep.equal({
deviceName: 'Google Pixel 3',
os_version: '9.0',
Expand Down
59 changes: 59 additions & 0 deletions test/e2e/pcloudy.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
import axios from 'axios';
import { expect } from 'chai';

describe('Browserstack Devices', () => {
it('Should be able to run the android with Browerstack config', async () => {
let androidDevices = (await axios.get('http://localhost:31337/device-farm/api/devices/android'))
.data;
delete androidDevices[0].meta;
delete androidDevices[0]['$loki'];
expect(androidDevices[0]).to.deep.equal({
platform: 'android',
host: 'https://device.pcloudy.com/appiumcloud/wd/hub',
busy: false,
deviceType: 'real',
capability: {
pCloudy_DeviceManufacturer: 'GOOGLE',
pCloudy_DeviceVersion: '11.0',
platform: 'android',
},
cloud: 'pCloudy',
pCloudy_DeviceManufacturer: 'GOOGLE',
pCloudy_DeviceVersion: '11.0',
name: 'GOOGLE',
sdk: '11.0',
udid: 'GOOGLE',
offline: false,
});
});

it('Should be able to run the plugin with Browerstack config', async () => {
const status = (await axios.get('http://localhost:31337/device-farm/api/devices')).status;
expect(status).to.be.eql(200);
});

it('Should be able to get iOS devices from Browerstack config', async () => {
let iosDevics = (await axios.get('http://localhost:31337/device-farm/api/devices/ios')).data;
delete iosDevics[0].meta;
delete iosDevics[0]['$loki'];
expect(iosDevics[0]).to.deep.equal({
platform: 'ios',
host: 'https://device.pcloudy.com/appiumcloud/wd/hub',
busy: false,
deviceType: 'real',
capability: {
pCloudy_DeviceManufacturer: 'APPLE',
pCloudy_DeviceVersion: '15.1',
platform: 'ios',
},
cloud: 'pCloudy',
pCloudy_DeviceManufacturer: 'APPLE',
pCloudy_DeviceVersion: '15.1',
name: 'APPLE',
sdk: '15.1',
udid: 'APPLE',
offline: false,
});
});
});

0 comments on commit bf270eb

Please sign in to comment.