import type { Capabilities, ProtractorBrowser } from 'protractor'; /** * @private */ export class StandardisedCapabilities { static of(currentBrowser: () => ProtractorBrowser): StandardisedCapabilities { return new StandardisedCapabilities(currentBrowser); } constructor(private currentBrowser: () => ProtractorBrowser) { } browserName(): Promise { return this.get( caps => caps.get('browserName'), ); } async browserVersion(): Promise { const version = await this.get( caps => caps.get('version'), caps => caps.get('browserVersion'), caps => caps.has('deviceManufacturer') && caps.has('deviceModel') ? `${ caps.get('deviceManufacturer') } ${ caps.get('deviceModel') }` : undefined, caps => caps.has('mobile') && caps.get('mobile').version, ); const suffix = await this.get( caps => !! caps.get('mobileEmulationEnabled') && '(mobile emulation)', ); return [ version, suffix, ].filter(_ => !!_).join(' '); } platformName(): Promise { return this.get( caps => (!! caps.get('platformName') && ! /any/i.test(caps.get('platformName'))) ? caps.get('platformName') : caps.get('platform'), ); } platformVersion(): Promise { return this.get( caps => caps.get('platformVersion'), ); } private async get(...fetchers: Array<(capabilities: Capabilities) => string>): Promise { const capabilities = await this.currentBrowser().getCapabilities(); for (const fetcher of fetchers) { const result = fetcher(capabilities); if (result) { return result; } } return undefined; } }