Skip to content

Commit dda0eec

Browse files
Fix pcloudy (#594)
* support for pCloudy * send pCloudy key and username from env * updated readMe and bump version * bump version and update readMe
1 parent bf270eb commit dda0eec

File tree

7 files changed

+97
-28
lines changed

7 files changed

+97
-28
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ You can also pass all the arguments in a config file. Refer [here](https://githu
5858
appium server -ka 800 --use-plugins=device-farm --config ./server-config.json -pa /wd/hub
5959
```
6060

61+
## Cloud Execution
62+
63+
Plugin currently supports pCloudy and BrowserStack
64+
65+
### BrowserStack
66+
67+
```
68+
BS_USERNAME="username" BS_PASSWORD="password" appium server -ka 800 --use-plugins=device-farm --config ./serverConfig/bs-config.json -pa /wd/hub
69+
```
70+
Refer on BroswerStack config [here](https://github.com/AppiumTestDistribution/appium-device-farm/blob/main/serverConfig/bs-config.json)
71+
72+
### pCloudy
73+
74+
```
75+
PCLOUDY_APIKEY="apiKey" PCLOUDY_USERNAME="useremail" appium server -ka 800 --use-plugins=device-farm --config ./serverConfig/pcloudy-config.json -pa /wd/hub
76+
```
77+
Refer on pCloudy config [here](https://github.com/AppiumTestDistribution/appium-device-farm/blob/main/serverConfig/pcloudy-config.json)
78+
79+
6180
### Argument options
6281

6382
These arguments are set when you launch the Appium server, with this plugin installed.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "appium-device-farm",
3-
"version": "3.9.0",
3+
"version": "3.10.0",
44
"description": "An appium 2.0 plugin that manages and create driver session on available devices",
55
"main": "./lib/index.js",
66
"scripts": {
77
"test": "mocha -r ts-node/register ./test/unit/*.spec.js --plugin-device-farm-platform=both --exit --timeout=10000",
88
"test-jest": "NODE_OPTIONS=--experimental-vm-modules npx jest ./test/unit/AndroidDeviceManager.spec.js",
99
"test-parallel-android": "wait-on http://localhost:31337/device-farm/ && mocha --require ts-node/register -p ./test/e2e/android/*.spec.js --timeout 260000",
10-
"test-parallel-bs": "mocha --require ts-node/register -p ./test/e2e/android/cloud/*.spec.js --timeout 260000",
10+
"test-parallel-bs": "mocha --require ts-node/register -p ./test/e2e/android/cloud/conf.spec.js --timeout 260000",
11+
"test-parallel-pcloudy": "mocha --require ts-node/register -p ./test/e2e/android/cloud/pcloudy.spec.js --timeout 260000",
1112
"test-parallel-ios": "wait-on http://localhost:4723/device-farm/ && mocha --require ts-node/register -p ./test/e2e/ios/*.spec.js --timeout 260000",
1213
"test-e2e": "wait-on http://localhost:31337/device-farm/ && mocha --require ts-node/register ./test/e2e/plugin.spec.js --timeout 999999",
1314
"test-e2e-browserstack": "wait-on http://localhost:31337/device-farm/ && mocha --require ts-node/register ./test/e2e/browserstack.spec.js --timeout 999999",

src/device-managers/cloud/CapabilityManager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Cloud from '../../enums/Cloud';
12
import { IDevice } from '../../interfaces/IDevice';
23

34
export default class CapabilityManager {
@@ -13,6 +14,10 @@ export default class CapabilityManager {
1314
entries.map(([key, val]) => {
1415
this.capabilities.alwaysMatch[`appium:${key}`] = val;
1516
});
17+
if(this.freeDevice.cloud.toLowerCase() === Cloud.PCLOUDY) {
18+
this.capabilities.alwaysMatch['pCloudy_ApiKey'] = process.env.PCLOUDY_APIKEY;
19+
this.capabilities.alwaysMatch['pCloudy_Username'] = process.env.PCLOUDY_USERNAME;
20+
}
1621
return this.capabilities;
1722
}
1823
}

src/helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import getPort from 'get-port';
66
import { IDevice } from './interfaces/IDevice';
77
import _ from 'lodash';
88
import log from './logger';
9+
import Cloud from './enums/Cloud';
910

1011
const APPIUM_VENDOR_PREFIX = 'appium:';
1112
export async function asyncForEach(
@@ -36,7 +37,7 @@ export async function getFreePort() {
3637
export function hubUrl(device: IDevice) {
3738
if (device.hasOwnProperty('cloud') && device.cloud === 'browserstack') {
3839
return `https://${process.env.BS_USERNAME}:${process.env.BS_PASSWORD}@hub.browserstack.com/wd/hub/session`;
39-
} else if (device.hasOwnProperty('cloud') && device.cloud === 'pCloudy') {
40+
} else if (device.hasOwnProperty('cloud') && device.cloud.toLowerCase() === Cloud.PCLOUDY) {
4041
return 'https://device.pcloudy.com/appiumcloud/wd/hub/session';
4142
}
4243
return `${device.host}/wd/hub/session`;

src/plugin.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,29 +164,33 @@ class DevicePlugin extends BasePlugin {
164164
if (!device.host.includes('127.0.0.1')) {
165165
const remoteUrl = hubUrl(device);
166166
let sessionDetails: any;
167-
try {
168-
logger.info('Creating cloud session');
169-
sessionDetails = //change to give the entire URL
170-
(
171-
await axios.post(remoteUrl, {
172-
capabilities: caps,
173-
})
174-
).data;
175-
if (sessionDetails.value.error) throw new Error(`Failed ❌ ${sessionDetails.value.error}`);
176-
177-
session = {
178-
protocol: 'W3C',
179-
value: [sessionDetails.value.sessionId, sessionDetails.value.capabilities, 'W3C'],
180-
};
181-
} catch (err: any) {
182-
await updateDevice(device, { busy: false });
183-
logger.info(
184-
`📱 Device UDID ${device.udid} unblocked. Reason: Remote Session failed to create`
185-
);
186-
throw new Error(
187-
`${err}, Please check the remote appium server log to know the reason for failure`
188-
);
189-
}
167+
logger.info('Creating cloud session');
168+
var config = {
169+
method: 'post',
170+
url: remoteUrl,
171+
headers: {
172+
'Content-Type': 'application/json',
173+
},
174+
data: { capabilities: caps },
175+
};
176+
await axios(config)
177+
.then(function (response) {
178+
sessionDetails = response.data;
179+
})
180+
.catch(async function (error) {
181+
console.log('Inside Error', error);
182+
await updateDevice(device, { busy: false });
183+
logger.info(
184+
`📱 Device UDID ${device.udid} unblocked. Reason: Remote Session failed to create`
185+
);
186+
throw new Error(
187+
`${error.response.data.value.message}, Please check the remote appium server log to know the reason for failure`
188+
);
189+
});
190+
session = {
191+
protocol: 'W3C',
192+
value: [sessionDetails.value.sessionId, sessionDetails.value.capabilities, 'W3C'],
193+
};
190194
} else {
191195
session = await next();
192196
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { remote } from 'webdriverio';
2+
3+
const APPIUM_HOST = '127.0.0.1';
4+
const APPIUM_PORT = 31337;
5+
const WDIO_PARAMS = {
6+
connectionRetryCount: 0,
7+
hostname: APPIUM_HOST,
8+
port: APPIUM_PORT,
9+
path: '/wd/hub/',
10+
logLevel: 'info',
11+
};
12+
const capabilities = {
13+
automationName: 'UiAutomator2',
14+
newCommandTimeout: 600,
15+
launchTimeout: 90000,
16+
platformName: 'Android',
17+
autoGrantPermissions: true,
18+
pCloudy_DurationInMinutes: 10,
19+
pCloudy_WildNet: 'false',
20+
pCloudy_EnableVideo: 'true',
21+
pCloudy_EnablePerformanceData: 'true',
22+
pCloudy_EnableDeviceLogs: 'true',
23+
pCloudy_ApplicationName: 'pCloudy_Appium_Demo.apk',
24+
appPackage: 'com.pcloudy.appiumdemo',
25+
appActivity: 'com.ba.mobile.LaunchActivity'
26+
};
27+
let driver;
28+
describe('Plugin Test', () => {
29+
beforeEach(async () => {
30+
driver = await remote({ ...WDIO_PARAMS, capabilities });
31+
});
32+
33+
it('Vertical swipe test', async () => {
34+
console.log(await driver.capabilities.deviceUDID);
35+
await driver.$('~login').click();
36+
});
37+
38+
afterEach(async () => await driver.deleteSession());
39+
});

0 commit comments

Comments
 (0)