From 13a16095d7b2488dfb3e49e4248381106a68a7b0 Mon Sep 17 00:00:00 2001 From: SvetoslavTsenov Date: Wed, 22 Nov 2017 14:30:07 +0200 Subject: [PATCH] feat: provide storage by platform --- lib/appium-driver.d.ts | 3 ++- lib/appium-driver.ts | 26 ++++++++++++++++++++------ lib/device-controller.d.ts | 2 +- lib/utils.d.ts | 3 ++- lib/utils.ts | 27 ++++++++++++++++++++++++++- 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/lib/appium-driver.d.ts b/lib/appium-driver.d.ts index d7246fc..8f3d318 100644 --- a/lib/appium-driver.d.ts +++ b/lib/appium-driver.d.ts @@ -21,7 +21,8 @@ export declare class AppiumDriver { private _isAlive; private _locators; private _logPath; - private _storage; + private _storageByDeviceName; + private _storageByPlatform; private constructor(); readonly imageHelper: ImageHelper; defaultWaitTime: number; diff --git a/lib/appium-driver.ts b/lib/appium-driver.ts index 7095b80..26d95a9 100644 --- a/lib/appium-driver.ts +++ b/lib/appium-driver.ts @@ -12,7 +12,8 @@ import { Direction } from "./direction"; import { Locator } from "./locators"; import { log, - getStorage, + getStorageByPlatform, + getStorageByDeviceName, resolve, fileExists, getAppPath, @@ -37,7 +38,8 @@ export class AppiumDriver { private _isAlive: boolean = false; private _locators: Locator; private _logPath: string; - private _storage: string; + private _storageByDeviceName: string; + private _storageByPlatform: string; private constructor(private _driver: any, private _wd, private _webio: any, private _driverConfig, private _args: INsCapabilities) { this._elementHelper = new ElementHelper(this._args); @@ -271,19 +273,31 @@ export class AppiumDriver { imageName = imageName.concat(AppiumDriver.pngFileExt); } - if (!this._storage) { - this._storage = getStorage(this._args); + if (!this._storageByDeviceName) { + this._storageByDeviceName = getStorageByDeviceName(this._args); } + let expectedImage = resolve(this._storageByDeviceName, imageName); + if (!fileExists(expectedImage)) { + if (!this._storageByPlatform) { + this._storageByPlatform = getStorageByPlatform(this._args); + } + expectedImage = resolve(this._storageByPlatform, imageName); + } + + if (!fileExists(expectedImage)) { + expectedImage = resolve(this._storageByDeviceName, imageName); + } + if (!this._logPath) { this._logPath = getReportPath(this._args); } - let expectedImage = resolve(this._storage, imageName); + expectedImage = resolve(this._storageByDeviceName, imageName); // Firts capture of screen when the expected image is not available if (!fileExists(expectedImage)) { - await this.takeScreenshot(resolve(this._storage, imageName.replace(".", "_actual."))); + await this.takeScreenshot(resolve(this._storageByDeviceName, imageName.replace(".", "_actual."))); console.log("Remove the 'actual' suffix to continue using the image as expected one ", expectedImage); let eventStartTime = Date.now().valueOf(); let counter = 1; diff --git a/lib/device-controller.d.ts b/lib/device-controller.d.ts index f546cf7..41a9201 100644 --- a/lib/device-controller.d.ts +++ b/lib/device-controller.d.ts @@ -2,7 +2,7 @@ import { INsCapabilities } from "./interfaces/ns-capabilities"; import { IDevice } from "mobile-devices-controller"; export declare class DeviceManger { private static _emulators; - static startDevice(args: INsCapabilities): Promise; + static startDevice(args: INsCapabilities): Promise; static stop(args: INsCapabilities): Promise; static kill(device: IDevice): Promise; private static getDefaultDevice(args); diff --git a/lib/utils.d.ts b/lib/utils.d.ts index fe6b084..7ed8dad 100644 --- a/lib/utils.d.ts +++ b/lib/utils.d.ts @@ -17,7 +17,8 @@ export declare function killPid(pid: any, verbose: any): void; export declare function waitForOutput(process: any, matcher: any, errorMatcher: any, timeout: any, verbose: any): Promise; export declare function executeCommand(args: any, cwd?: string): string; export declare function isWin(): boolean; -export declare function getStorage(args: INsCapabilities): string; +export declare function getStorageByDeviceName(args: INsCapabilities): string; +export declare function getStorageByPlatform(args: INsCapabilities): string; export declare function getReportPath(args: INsCapabilities): string; export declare function getAppPath(platform: any, runType: any): any; export declare function calculateOffset(direction: any, y: number, yOffset: number, x: number, xOffset: number, isIOS: boolean, verbose: any): { diff --git a/lib/utils.ts b/lib/utils.ts index a398cea..ffd3691 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -233,12 +233,37 @@ export function isWin() { return /^win/.test(process.platform); } -export function getStorage(args: INsCapabilities) { + +export function getStorageByDeviceName(args: INsCapabilities) { + let storage = getStorage(args); + const appName = getAppName(args); + storage = createStorageFolder(storage, appName); + storage = createStorageFolder(storage, args.appiumCaps.deviceName); + + return storage; +} + +export function getStorageByPlatform(args: INsCapabilities) { let storage = args.storage; if (!storage) { storage = createStorageFolder(resolve(args.projectDir, args.testFolder), "resources"); storage = createStorageFolder(storage, "images"); } + + const appName = getAppName(args); + storage = createStorageFolder(storage, appName); + storage = createStorageFolder(storage, args.appiumCaps.platformName.toLowerCase()); + + return storage; +} + +function getStorage(args: INsCapabilities) { + let storage = args.storage; + if (!storage) { + storage = createStorageFolder(resolve(args.projectDir, args.testFolder), "resources"); + storage = createStorageFolder(storage, "images"); + } + const appName = getAppName(args); storage = createStorageFolder(storage, appName); storage = createStorageFolder(storage, args.appiumCaps.deviceName);