Skip to content

Commit 6c2735c

Browse files
refactor(compare): add waitOnCreatingInitialSnapshot (#231)
1 parent 8fec7e2 commit 6c2735c

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/appium-driver.ts

+3
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,9 @@ export class AppiumDriver {
590590
// First time capture
591591
if (!existsSync(pathExpectedImage)) {
592592
const pathActualImage = resolvePath(this._storageByDeviceName, imageName.replace(".", "_actual."));
593+
if (this.imageHelper.waitOnCreatingInitialSnapshot > 0) {
594+
await this.driver.wait(this.imageHelper.waitOnCreatingInitialSnapshot);
595+
}
593596
await this.takeScreenshot(pathActualImage);
594597

595598
if (rect) {

lib/image-helper.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ export declare class ImageHelper {
55
private _args;
66
private _imageCropRect;
77
private _blockOutAreas;
8+
private _waitOnCreatingInitialSnapshot;
89
constructor(_args: INsCapabilities);
10+
waitOnCreatingInitialSnapshot: number;
911
imageCropRect: IRectangle;
1012
blockOutAreas: IRectangle[];
1113
imageOutputLimit(): ImageOptions;

lib/image-helper.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@ export class ImageHelper {
1010

1111
private _imageCropRect: IRectangle;
1212
private _blockOutAreas: IRectangle[];
13+
private _waitOnCreatingInitialSnapshot: number;
1314

1415
constructor(private _args: INsCapabilities) {
1516
}
1617

18+
get waitOnCreatingInitialSnapshot() {
19+
return this._waitOnCreatingInitialSnapshot;
20+
}
21+
22+
set waitOnCreatingInitialSnapshot(waitOnCreatingInitialSnapshot: number) {
23+
this._waitOnCreatingInitialSnapshot = waitOnCreatingInitialSnapshot;
24+
}
25+
1726
get imageCropRect(): IRectangle {
1827
return this._imageCropRect;
1928
}
@@ -103,9 +112,11 @@ export class ImageHelper {
103112

104113
if (typeThreshold == ImageOptions.percent) {
105114
valueThreshold = Math.floor(valueThreshold * 100);
115+
console.log(`Using ${valueThreshold}\ ${typeThreshold} tolerance`);
116+
} else {
117+
console.log(`Using ${valueThreshold} tolerance`);
106118
}
107119

108-
console.log(`Using ${valueThreshold}\ ${typeThreshold} tolerance`);
109120
const result = this.runDiff(diff, output);
110121
this._blockOutAreas = undefined;
111122
return result;

0 commit comments

Comments
 (0)