Skip to content

Commit c4b2182

Browse files
Support to run Test In Sauce (#598)
* Support for Sauce labs * pick host name from config file * bump version
1 parent a71c97d commit c4b2182

File tree

12 files changed

+100
-9
lines changed

12 files changed

+100
-9
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,17 @@ Refer on BroswerStack config [here](https://github.com/AppiumTestDistribution/ap
7272
### pCloudy
7373

7474
```
75-
PCLOUDY_APIKEY="apiKey" PCLOUDY_USERNAME="useremail" appium server -ka 800 --use-plugins=device-farm --config ./serverConfig/pcloudy-config.json -pa /wd/hub
75+
BS_USERNAME="username" BS_PASSWORD="password" appium server -ka 800 --use-plugins=device-farm --config ./serverConfig/bs-config.json -pa /wd/hub
7676
```
7777
Refer on pCloudy config [here](https://github.com/AppiumTestDistribution/appium-device-farm/blob/main/serverConfig/pcloudy-config.json)
7878

79+
### SauceLabs
80+
81+
```
82+
SAUCE_PASSWORD="apiKey" SAUCE_USERNAME="useremail" appium server -ka 800 --use-plugins=device-farm --config ./serverConfig/sauce-config.json -pa /wd/hub
83+
```
84+
Refer on pCloudy config [here](https://github.com/AppiumTestDistribution/appium-device-farm/blob/main/serverConfig/sauce-config.json)
85+
7986

8087
### Argument options
8188

azure-pipelines.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,20 @@ jobs:
138138
nohup ./node_modules/.bin/appium server -ka 800 --use-plugins=device-farm -pa /wd/hub --config=./serverConfig/bs-config.json &
139139
npm run test-parallel-bs
140140
displayName: 'E2E Test'
141+
142+
- job: Sauce
143+
pool:
144+
vmImage: 'macOS-latest'
145+
146+
steps:
147+
- task: NodeTool@0.200.0
148+
inputs:
149+
versionSpec: '16.x'
150+
151+
- script: |
152+
npm ci
153+
export APPIUM_HOME=/tmp/device-farm
154+
./node_modules/.bin/appium plugin install --source=local .
155+
nohup ./node_modules/.bin/appium server -ka 800 --use-plugins=device-farm -pa /wd/hub --config=./serverConfig/sauce-config.json &
156+
npm run test-parallel-sauce
157+
displayName: 'E2E Test'

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "appium-device-farm",
3-
"version": "3.11.0",
3+
"version": "3.12.0",
44
"description": "An appium 2.0 plugin that manages and create driver session on available devices",
55
"main": "./lib/index.js",
66
"scripts": {
@@ -9,6 +9,7 @@
99
"test-parallel-android": "wait-on http://localhost:31337/device-farm/ && mocha --require ts-node/register -p ./test/e2e/android/*.spec.js --timeout 260000",
1010
"test-parallel-bs": "mocha --require ts-node/register -p ./test/e2e/android/cloud/conf.spec.js --timeout 260000",
1111
"test-parallel-pcloudy": "mocha --require ts-node/register -p ./test/e2e/android/cloud/pcloudy.spec.js --timeout 260000",
12+
"test-parallel-sauce": "mocha --require ts-node/register -p ./test/e2e/android/cloud/sauce.spec.js --timeout 260000",
1213
"test-parallel-ios": "wait-on http://localhost:4723/device-farm/ && mocha --require ts-node/register -p ./test/e2e/ios/*.spec.js --timeout 260000",
1314
"test-e2e": "wait-on http://localhost:31337/device-farm/ && mocha --require ts-node/register ./test/e2e/plugin.spec.js --timeout 999999",
1415
"test-e2e-browserstack": "wait-on http://localhost:31337/device-farm/ && mocha --require ts-node/register ./test/e2e/browserstack.spec.js --timeout 999999",

serverConfig/sauce-config.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"server": {
3+
"port": 31337,
4+
"plugin": {
5+
"device-farm": {
6+
"platform": "android",
7+
"remote": [
8+
{
9+
"cloudName": "sauce",
10+
"url": "https://ondemand.eu-central-1.saucelabs.com/wd/hub",
11+
"devices": [
12+
{
13+
"platformVersion": "12.0",
14+
"deviceName": "Android GoogleAPI Emulator",
15+
"platform": "android"
16+
}
17+
]
18+
}
19+
]
20+
}
21+
}
22+
}
23+
}

src/device-managers/cloud/CapabilityManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class CapabilityManager {
1414
entries.map(([key, val]) => {
1515
this.capabilities.alwaysMatch[`appium:${key}`] = val;
1616
});
17-
if(this.freeDevice.cloud.toLowerCase() === Cloud.PCLOUDY) {
17+
if (this.freeDevice.cloud.toLowerCase() === Cloud.PCLOUDY) {
1818
this.capabilities.alwaysMatch['pCloudy_ApiKey'] = process.env.PCLOUDY_APIKEY;
1919
this.capabilities.alwaysMatch['pCloudy_Username'] = process.env.PCLOUDY_USERNAME;
2020
}

src/device-managers/cloud/Devices.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export default class Devices {
2424
udid: d.deviceName,
2525
};
2626
}
27+
if (this.host.cloudName.toLowerCase() === Cloud.SAUCELABS) {
28+
cloudDeviceProperties = {
29+
name: d.deviceName,
30+
sdk: d.platformVersion,
31+
udid: d.deviceName,
32+
};
33+
}
2734
if (this.host.cloudName.toLowerCase() === Cloud.PCLOUDY) {
2835
cloudDeviceProperties = {
2936
name: d?.pCloudy_DeviceFullName || d?.pCloudy_DeviceManufacturer,

src/device-managers/factory/DeviceFactory.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { IDevice } from '../../interfaces/IDevice';
22
import RemoteAndroidDeviceManager from '../RemoteAndroidDeviceManager';
33
import RemoteIOSDeviceManager from '../RemoteIOSDeviceManager';
44
import { isObject } from 'lodash';
5-
import Cloud from '../../enums/Cloud';
65
import { CloudArgs } from '../../types/CloudArgs';
76
import DevicePlatform from '../../enums/Platform';
87
import Devices from '../cloud/Devices';

src/enums/Cloud.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
enum Cloud {
22
BROWSERSTACK = 'browserstack',
33
PCLOUDY = 'pcloudy',
4+
SAUCELABS = 'sauce',
45
}
56

67
export default Cloud;

src/helpers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ export async function getFreePort() {
3636
}
3737

3838
export function hubUrl(device: IDevice) {
39-
const host = normalizeUrl(device.host, {removeTrailingSlash: false});
39+
const host = normalizeUrl(device.host, { removeTrailingSlash: false });
4040
if (device.hasOwnProperty('cloud') && device.cloud === 'browserstack') {
4141
return `https://${process.env.BS_USERNAME}:${process.env.BS_PASSWORD}@hub.browserstack.com/wd/hub/session`;
42+
} else if (device.hasOwnProperty('cloud') && device.cloud === 'sauce') {
43+
return `https://${process.env.SAUCE_USERNAME}:${process.env.SAUCE_PASSWORD}@${
44+
new URL(device.host).host
45+
}/wd/hub/session`;
4246
} else if (device.hasOwnProperty('cloud') && device.cloud.toLowerCase() === Cloud.PCLOUDY) {
4347
return `${host}/session`;
4448
}

0 commit comments

Comments
 (0)