Skip to content

Commit 3c76ea1

Browse files
author
Vasil Chimev
authored
fix(device-controller): start device in server scenario (#95)
* fix: throw if device's density is undefined * fix(device-controller): start device in server scenario
1 parent 21ecadc commit 3c76ea1

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lib/device-controller.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,19 @@ export class DeviceManger implements IDeviceManager {
3131
let device: IDevice = DeviceManger.getDefaultDevice(args);
3232
if (process.env["DEVICE_TOKEN"]) {
3333
device.token = process.env["DEVICE_TOKEN"];
34-
console.log("Device", device);
35-
return device;
34+
const allDevices = await DeviceController.getDevices({ platform: args.appiumCaps.platformName });
35+
const foundDevice = DeviceController.filter(allDevices, { token: device.token })[0];
36+
console.log("Device: ", foundDevice);
37+
return foundDevice;
3638
}
39+
3740
// When isSauceLab specified we simply do nothing;
3841
if (args.isSauceLab || args.ignoreDeviceController) {
3942
DeviceManger._emulators.set(args.runType, device);
40-
4143
return device;
4244
}
4345

44-
const allDevices = (await DeviceController.getDevices({ platform: args.appiumCaps.platformName }));
46+
const allDevices = await DeviceController.getDevices({ platform: args.appiumCaps.platformName });
4547
if (!allDevices || allDevices === null || allDevices.length === 0) {
4648
console.log("We couldn't find any devices. We will try to proceed to appium! Maybe avd manager is missing")
4749
console.log("Available devices:\n", allDevices);

lib/ui-element.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,14 @@ export class UIElement {
125125
const actRect = await this.getRectangle();
126126
if (this._args.isIOS) {
127127
const density = this._args.device.config.density;
128-
actRect.x *= density;
129-
actRect.y *= density;
130-
actRect.width *= density;
131-
actRect.height *= density;
128+
if (density) {
129+
actRect.x *= density;
130+
actRect.y *= density;
131+
actRect.width *= density;
132+
actRect.height *= density;
133+
} else {
134+
throw new Error("Device's density is undefined!");
135+
}
132136
}
133137
return actRect;
134138
}

0 commit comments

Comments
 (0)