Skip to content

chore: move the default tolerance and toleranceType to ImageHelper #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/appium-driver.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export declare class AppiumDriver {
private _isAlive;
private _locators;
private _storageByPlatform;
private _defaultToleranceType;
private _defaultTolerance;
private constructor();
readonly imageHelper: ImageHelper;
defaultWaitTime: number;
Expand All @@ -38,8 +36,6 @@ export declare class AppiumDriver {
readonly isAndroid: boolean;
readonly isIOS: boolean;
readonly driver: any;
defaultToleranceType: ImageOptions;
defaultTolerance: number;
/**
* Get the storage where test results from image comparison is logged. The path should be reports/app nam/device name
*/
Expand Down
24 changes: 3 additions & 21 deletions lib/appium-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ export class AppiumDriver {
private _isAlive: boolean = false;
private _locators: Locator;
private _storageByPlatform: string;
private _defaultToleranceType: ImageOptions = ImageOptions.percent;
private _defaultTolerance: number = 0;

private constructor(private _driver: any, private _wd, private _webio: any, private _driverConfig, private _args: INsCapabilities) {
this._elementHelper = new ElementHelper(this._args);
Expand Down Expand Up @@ -120,22 +118,6 @@ export class AppiumDriver {
return this._driver;
}

get defaultToleranceType(): ImageOptions {
return this._defaultToleranceType;
}

set defaultToleranceType(toleranceType: ImageOptions) {
this._defaultToleranceType = toleranceType;
}

get defaultTolerance(): number {
return this._defaultTolerance;
}

set defaultTolerance(tolerance: number) {
this._defaultTolerance = tolerance;
}

/**
* Get the storage where test results from image comparison is logged. The path should be reports/app nam/device name
*/
Expand Down Expand Up @@ -619,11 +601,11 @@ export class AppiumDriver {
return await this.driver.getSessionId();
}

public async compareElement(element: UIElement, imageName?: string, tolerance: number = this._defaultTolerance, timeOutSeconds: number = 3, toleranceType: ImageOptions = this._defaultToleranceType) {
public async compareElement(element: UIElement, imageName?: string, tolerance: number = this.imageHelper.defaultTolerance, timeOutSeconds: number = 3, toleranceType: ImageOptions = this.imageHelper.defaultToleranceType) {
return await this.compareRectangle(await element.getActualRectangle(), imageName, timeOutSeconds, tolerance, toleranceType);
}

public async compareRectangle(rect: IRectangle, imageName?: string, timeOutSeconds: number = 3, tolerance: number = this._defaultTolerance, toleranceType: ImageOptions = this._defaultToleranceType) {
public async compareRectangle(rect: IRectangle, imageName?: string, timeOutSeconds: number = 3, tolerance: number = this.imageHelper.defaultTolerance, toleranceType: ImageOptions = this.imageHelper.defaultToleranceType) {
imageName = imageName || this.imageHelper.testName;
const options = this.imageHelper.extendOptions({
imageName: imageName,
Expand All @@ -637,7 +619,7 @@ export class AppiumDriver {
return await this.imageHelper.compare(options);
}

public async compareScreen(imageName?: string, timeOutSeconds: number = 3, tolerance: number = this._defaultTolerance, toleranceType: ImageOptions = this._defaultToleranceType) {
public async compareScreen(imageName?: string, timeOutSeconds: number = 3, tolerance: number = this.imageHelper.defaultTolerance, toleranceType: ImageOptions = this.imageHelper.defaultToleranceType) {
imageName = imageName || this.imageHelper.testName;
const options = this.imageHelper.extendOptions({
imageName: imageName,
Expand Down
4 changes: 4 additions & 0 deletions lib/image-helper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export declare class ImageHelper {
private _blockOutAreas;
private _imagesResults;
private _options;
private _defaultToleranceType;
private _defaultTolerance;
private _defaultOptions;
constructor(_args: INsCapabilities, _driver: AppiumDriver);
static readonly pngFileExt = ".png";
Expand All @@ -80,6 +82,8 @@ export declare class ImageHelper {
delta: number;
options: IImageCompareOptions;
blockOutAreas: IRectangle[];
defaultToleranceType: ImageOptions;
defaultTolerance: number;
compareScreen(options?: IImageCompareOptions): Promise<boolean>;
compareElement(element: UIElement, options?: IImageCompareOptions): Promise<boolean>;
compareRectangle(cropRectangle: IRectangle, options?: IImageCompareOptions): Promise<boolean>;
Expand Down
18 changes: 18 additions & 0 deletions lib/image-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export class ImageHelper {
private _blockOutAreas: IRectangle[];
private _imagesResults = new Map<string, boolean>();
private _options: IImageCompareOptions = {};
private _defaultToleranceType: ImageOptions = ImageOptions.percent;
private _defaultTolerance: number = 0;
private _defaultOptions: IImageCompareOptions = {
timeOutSeconds: 2,
tolerance: 0,
Expand Down Expand Up @@ -148,6 +150,22 @@ export class ImageHelper {
this._blockOutAreas = rectangles;
}

get defaultToleranceType(): ImageOptions {
return this._defaultToleranceType;
}

set defaultToleranceType(toleranceType: ImageOptions) {
this._defaultToleranceType = toleranceType;
}

get defaultTolerance(): number {
return this._defaultTolerance;
}

set defaultTolerance(tolerance: number) {
this._defaultTolerance = tolerance;
}

public async compareScreen(options?: IImageCompareOptions) {
options = this.extendOptions(options);
options.imageName = this.increaseImageName(options.imageName || this.testName, options);
Expand Down