Skip to content

Commit 424b95c

Browse files
feat: provide storage by platform (#68)
1 parent 780e827 commit 424b95c

File tree

4 files changed

+50
-9
lines changed

4 files changed

+50
-9
lines changed

lib/appium-driver.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export declare class AppiumDriver {
2121
private _isAlive;
2222
private _locators;
2323
private _logPath;
24-
private _storage;
24+
private _storageByDeviceName;
25+
private _storageByPlatform;
2526
private constructor();
2627
readonly imageHelper: ImageHelper;
2728
defaultWaitTime: number;

lib/appium-driver.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { Direction } from "./direction";
1212
import { Locator } from "./locators";
1313
import {
1414
log,
15-
getStorage,
15+
getStorageByPlatform,
16+
getStorageByDeviceName,
1617
resolve,
1718
fileExists,
1819
getAppPath,
@@ -37,7 +38,8 @@ export class AppiumDriver {
3738
private _isAlive: boolean = false;
3839
private _locators: Locator;
3940
private _logPath: string;
40-
private _storage: string;
41+
private _storageByDeviceName: string;
42+
private _storageByPlatform: string;
4143

4244
private constructor(private _driver: any, private _wd, private _webio: any, private _driverConfig, private _args: INsCapabilities) {
4345
this._elementHelper = new ElementHelper(this._args);
@@ -271,19 +273,31 @@ export class AppiumDriver {
271273
imageName = imageName.concat(AppiumDriver.pngFileExt);
272274
}
273275

274-
if (!this._storage) {
275-
this._storage = getStorage(this._args);
276+
if (!this._storageByDeviceName) {
277+
this._storageByDeviceName = getStorageByDeviceName(this._args);
276278
}
277279

280+
let expectedImage = resolve(this._storageByDeviceName, imageName);
281+
if (!fileExists(expectedImage)) {
282+
if (!this._storageByPlatform) {
283+
this._storageByPlatform = getStorageByPlatform(this._args);
284+
}
285+
expectedImage = resolve(this._storageByPlatform, imageName);
286+
}
287+
288+
if (!fileExists(expectedImage)) {
289+
expectedImage = resolve(this._storageByDeviceName, imageName);
290+
}
291+
278292
if (!this._logPath) {
279293
this._logPath = getReportPath(this._args);
280294
}
281295

282-
let expectedImage = resolve(this._storage, imageName);
296+
expectedImage = resolve(this._storageByDeviceName, imageName);
283297

284298
// Firts capture of screen when the expected image is not available
285299
if (!fileExists(expectedImage)) {
286-
await this.takeScreenshot(resolve(this._storage, imageName.replace(".", "_actual.")));
300+
await this.takeScreenshot(resolve(this._storageByDeviceName, imageName.replace(".", "_actual.")));
287301
console.log("Remove the 'actual' suffix to continue using the image as expected one ", expectedImage);
288302
let eventStartTime = Date.now().valueOf();
289303
let counter = 1;

lib/utils.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export declare function killPid(pid: any, verbose: any): void;
1717
export declare function waitForOutput(process: any, matcher: any, errorMatcher: any, timeout: any, verbose: any): Promise<boolean>;
1818
export declare function executeCommand(args: any, cwd?: string): string;
1919
export declare function isWin(): boolean;
20-
export declare function getStorage(args: INsCapabilities): string;
20+
export declare function getStorageByDeviceName(args: INsCapabilities): string;
21+
export declare function getStorageByPlatform(args: INsCapabilities): string;
2122
export declare function getReportPath(args: INsCapabilities): string;
2223
export declare function getAppPath(platform: any, runType: any): any;
2324
export declare function calculateOffset(direction: any, y: number, yOffset: number, x: number, xOffset: number, isIOS: boolean, verbose: any): {

lib/utils.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,37 @@ export function isWin() {
233233
return /^win/.test(process.platform);
234234
}
235235

236-
export function getStorage(args: INsCapabilities) {
236+
237+
export function getStorageByDeviceName(args: INsCapabilities) {
238+
let storage = getStorage(args);
239+
const appName = getAppName(args);
240+
storage = createStorageFolder(storage, appName);
241+
storage = createStorageFolder(storage, args.appiumCaps.deviceName);
242+
243+
return storage;
244+
}
245+
246+
export function getStorageByPlatform(args: INsCapabilities) {
237247
let storage = args.storage;
238248
if (!storage) {
239249
storage = createStorageFolder(resolve(args.projectDir, args.testFolder), "resources");
240250
storage = createStorageFolder(storage, "images");
241251
}
252+
253+
const appName = getAppName(args);
254+
storage = createStorageFolder(storage, appName);
255+
storage = createStorageFolder(storage, args.appiumCaps.platformName.toLowerCase());
256+
257+
return storage;
258+
}
259+
260+
function getStorage(args: INsCapabilities) {
261+
let storage = args.storage;
262+
if (!storage) {
263+
storage = createStorageFolder(resolve(args.projectDir, args.testFolder), "resources");
264+
storage = createStorageFolder(storage, "images");
265+
}
266+
242267
const appName = getAppName(args);
243268
storage = createStorageFolder(storage, appName);
244269
storage = createStorageFolder(storage, args.appiumCaps.deviceName);

0 commit comments

Comments
 (0)