Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c3f1366

Browse files
author
Vasil Chimev
authored
feat(android): properly exclude status bar from image comparison (#42)
#23
1 parent d57241a commit c3f1366

11 files changed

+47
-14
lines changed

‎lib/appium-driver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class AppiumDriver {
4242

4343
private constructor(private _driver: any, private _wd, private _webio: any, private _driverConfig, private _args: INsCapabilities) {
4444
this._elementHelper = new ElementHelper(this._args.appiumCaps.platformName.toLowerCase(), this._args.appiumCaps.platformVersion.toLowerCase());
45-
this._imageHelper = new ImageHelper();
45+
this._imageHelper = new ImageHelper(this._args);
4646
this._isAlive = true;
4747
this._locators = new Locator(this._args.appiumCaps.platformName, this._args.appiumCaps.platformVersion);
4848
this._webio.requestHandler.sessionID = this._driver.sessionID;

‎lib/appium-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ export class AppiumServer {
4545
}
4646

4747
public async start() {
48-
const device = await DeviceController.startDevice(this._args)
48+
const device = await DeviceController.startDevice(this._args);
4949
log("Starting server...", this._args.verbose);
50-
this._args.appiumCaps["udid"] = device.token;
50+
this._args.device = device;
5151
const logLevel = this._args.verbose === true ? "debug" : "info";
5252
this._server = child_process.spawn(this._appium, ["-p", this.port.toString(), "--log-level", logLevel], {
5353
shell: true,

‎lib/device-controller.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { INsCapabilities } from "./ins-capabilities";
22
import { IDevice } from "mobile-devices-controller";
33
export declare class DeviceController {
44
private static _emulators;
5-
static startDevice(args: INsCapabilities): Promise<IDevice>;
5+
static startDevice(args: INsCapabilities): Promise<any>;
66
static stop(args: INsCapabilities): Promise<void>;
77
static kill(device: IDevice): Promise<void>;
88
private static device(runType);

‎lib/device-controller.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class DeviceController {
2828
device = DeviceController.getDevicesByStatus(devices, Status.SHUTDOWN);
2929
}
3030

31-
// If there is no shutdown device
31+
// If there is no shutdown device
3232
if (!device || device === null) {
3333
device = DeviceController.getDevicesByStatus(devices, Status.BOOTED);
3434
}
@@ -42,7 +42,7 @@ export class DeviceController {
4242
if (!device || device === null && args.reuseDevice) {
4343
device = DeviceController.getDevicesByStatus(devices, Status.SHUTDOWN);
4444
}
45-
45+
4646
if (device.status === Status.SHUTDOWN) {
4747
await DeviceManager.startDevice(device);
4848
console.log("Started device: ", device);
@@ -54,6 +54,15 @@ export class DeviceController {
5454
}
5555
}
5656

57+
if (device.token && args.appiumCaps.platformName.toLowerCase() === Platform.ANDROID) {
58+
const density = AndroidManager.getPhysicalDensity(device.token);
59+
const offsetPixels = AndroidManager.getPixelsOffset(device.token);
60+
device.config = {
61+
density: density,
62+
offsetPixels: offsetPixels,
63+
};
64+
}
65+
5766
DeviceController._emulators.set(args.runType, device);
5867

5968
return device;

‎lib/image-helper.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import { ImageOptions } from "./image-options";
2+
import { INsCapabilities } from "./ins-capabilities";
23
export declare class ImageHelper {
4+
private _args;
5+
constructor(_args: INsCapabilities);
6+
private getOffsetPixels();
37
imageOutputLimit(): ImageOptions;
48
thresholdType(): ImageOptions;
59
threshold(): number;
610
delta(): number;
711
cropImageA(): {
812
x: number;
9-
y: number;
13+
y: any;
1014
};
1115
cropImageB(): {
1216
x: number;
13-
y: number;
17+
y: any;
1418
};
1519
verbose(): boolean;
1620
private runDiff(diffOptions, diffImage);

‎lib/image-helper.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import * as blinkDiff from "blink-diff";
2-
import { ImageOptions} from "./image-options";
2+
import { ImageOptions } from "./image-options";
3+
import { INsCapabilities } from "./ins-capabilities";
34

45
export class ImageHelper {
56

7+
constructor(private _args: INsCapabilities) {
8+
}
9+
10+
private getOffsetPixels() {
11+
return this._args.device.config ? this._args.device.config.offsetPixels : 40; // TODO: iOS = 40
12+
}
13+
614
public imageOutputLimit() {
715
return ImageOptions.outputAll;
816
}
@@ -20,11 +28,11 @@ export class ImageHelper {
2028
}
2129

2230
public cropImageA() {
23-
return { x: 0, y: 40 };// Android = 35, iOS = 40
31+
return { x: 0, y: this.getOffsetPixels() };
2432
}
2533

2634
public cropImageB() {
27-
return { x: 0, y: 40 };// Android = 35, iOS = 40
35+
return { x: 0, y: this.getOffsetPixels() };
2836
}
2937

3038
public verbose() {

‎lib/ins-capabilities.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { IDevice } from "mobile-devices-controller";
12
export interface INsCapabilities {
23
projectDir: string;
34
projectBinary: string;
@@ -15,4 +16,5 @@ export interface INsCapabilities {
1516
storage: string;
1617
testReports: string;
1718
reuseDevice: boolean;
19+
device: IDevice;
1820
}

‎lib/ins-capabilities.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { IDevice } from "mobile-devices-controller";
2+
13
export interface INsCapabilities {
24
projectDir: string;
35
projectBinary: string;
@@ -15,4 +17,5 @@ export interface INsCapabilities {
1517
storage: string;
1618
testReports: string;
1719
reuseDevice: boolean;
20+
device: IDevice;
1821
}

‎lib/ns-capabilities.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { INsCapabilities } from "./ins-capabilities";
2+
import { IDevice } from "mobile-devices-controller";
23
export declare class NsCapabilities implements INsCapabilities {
34
private _projectDir;
45
private _projectBinary;
@@ -16,6 +17,7 @@ export declare class NsCapabilities implements INsCapabilities {
1617
private _isSauceLab;
1718
private _appPath;
1819
private _emulatorOptions;
20+
private _device;
1921
private exceptions;
2022
constructor();
2123
readonly projectDir: any;
@@ -33,6 +35,7 @@ export declare class NsCapabilities implements INsCapabilities {
3335
readonly runType: any;
3436
readonly isSauceLab: any;
3537
appPath: string;
38+
device: IDevice;
3639
readonly emulatorOptions: string;
3740
private resolveAppPath();
3841
private checkMandatoryCapabiliies();

‎lib/ns-capabilities.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as parser from "./parser"
22
import { INsCapabilities } from "./ins-capabilities";
33
import { resolveCapabilities } from "./capabilities-helper";
44
import { getAppPath, fileExists, logErr } from "./utils";
5+
import { IDevice } from "mobile-devices-controller";
56

67
export class NsCapabilities implements INsCapabilities {
78
private _projectDir;
@@ -20,6 +21,7 @@ export class NsCapabilities implements INsCapabilities {
2021
private _isSauceLab;
2122
private _appPath: string;
2223
private _emulatorOptions: string;
24+
private _device: IDevice;
2325
private exceptions: Array<string> = new Array();
2426

2527
constructor() {
@@ -59,6 +61,8 @@ export class NsCapabilities implements INsCapabilities {
5961
get isSauceLab() { return this._isSauceLab; }
6062
get appPath() { return this._appPath; }
6163
set appPath(appPath: string) { this._appPath = appPath; }
64+
get device() { return this._device; }
65+
set device(device: IDevice) { this._device = device; }
6266
get emulatorOptions() { return (this._emulatorOptions || "-wipe-data -gpu on") }
6367

6468
private resolveAppPath() {
@@ -90,8 +94,8 @@ export class NsCapabilities implements INsCapabilities {
9094
this.exceptions.push("Platform version is missing! Please, check appium capabilities file!");
9195
}
9296

93-
if (!this._appiumCaps.deviceName && !this._appiumCaps.uidid) {
94-
this.exceptions.push("The device name or uidid are missing! Please, check appium capabilities file!");
97+
if (!this._appiumCaps.deviceName && !this._appiumCaps.udid) {
98+
this.exceptions.push("The device name or udid are missing! Please, check appium capabilities file!");
9599
}
96100
}
97101

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /