Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
fix(protractor): detect the browser name and version, as well as the …
…platform name and version re #455
- Loading branch information
Showing
with
202 additions
and 15 deletions.
- +7 −2 packages/core/src/model/tags/BrowserTag.ts
- +24 −2 packages/core/src/model/tags/PlatformTag.ts
- +4 −1 packages/core/src/model/tags/Tag.ts
- +91 −0 packages/protractor/spec/adapter/browser-detector/StandardisedCapabilities.spec.ts
- +3 −3 packages/protractor/src/adapter/ProtractorFrameworkAdapter.ts
- +16 −7 packages/protractor/src/adapter/browser-detector/BrowserDetector.ts
- +56 −0 packages/protractor/src/adapter/browser-detector/StandardisedCapabilities.ts
- +1 −0 packages/protractor/src/adapter/browser-detector/index.ts
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,91 @@ | ||
import 'mocha'; | ||
|
||
import { expect } from '@integration/testing-tools'; | ||
import { given } from 'mocha-testdata'; | ||
import { Capabilities, ProtractorBrowser } from 'protractor'; | ||
import * as sinon from 'sinon'; | ||
|
||
import { StandardisedCapabilities } from '../../../src/adapter/browser-detector'; | ||
|
||
describe('StandardisedCapabilities', () => { | ||
|
||
given([ | ||
{ | ||
actual: { browserName: 'MicrosoftEdge', browserVersion: '42.17134.1.0', platformName: 'windows', platform: 'WINDOWS', platformVersion: '10' }, | ||
expected: { browserName: 'MicrosoftEdge', browserVersion: '42.17134.1.0', platformName: 'windows', platformVersion: '10' }, | ||
}, { | ||
actual: { browserName: 'chrome', version: '79.0.3945.79', platform: 'WINDOWS' }, | ||
expected: { browserName: 'chrome', browserVersion: '79.0.3945.79', platformName: 'WINDOWS' }, | ||
}, { | ||
actual: { browserName: 'MicrosoftEdge', version: '79.0.309.18', platform: 'Mac OS X' }, | ||
expected: { browserName: 'MicrosoftEdge', browserVersion: '79.0.309.18', platformName: 'Mac OS X' }, | ||
}, { | ||
actual: { browserName: 'firefox', browserVersion: '72.0', platformName: 'windows', platformVersion: '6.1' }, | ||
expected: { browserName: 'firefox', browserVersion: '72.0', platformName: 'windows', platformVersion: '6.1' }, | ||
}, { | ||
actual: { browserName: 'internet explorer', version: '10', platform: 'WINDOWS' }, | ||
expected: { browserName: 'internet explorer', browserVersion: '10', platformName: 'WINDOWS' }, | ||
}, { | ||
actual: { browserName: 'chrome', version: '79.0.3945.79', platform: 'MAC' }, | ||
expected: { browserName: 'chrome', browserVersion: '79.0.3945.79', platformName: 'MAC' }, | ||
}, { | ||
actual: { browserName: 'chrome', deviceManufacturer: 'samsung', deviceModel: 'SM-G950F', platformName: 'Android', platform: 'LINUX', platformVersion: '7.0' }, | ||
expected: { browserName: 'chrome', browserVersion: 'samsung SM-G950F', platformName: 'Android', platformVersion: '7.0' }, | ||
}, { | ||
actual: { browserName: 'opera', version: '12.16', platformName: 'ANY', platform: 'WINDOWS' }, | ||
expected: { browserName: 'opera', browserVersion: '12.16', platformName: 'WINDOWS' }, | ||
}, { | ||
actual: { browserName: 'firefox', browserVersion: '72.0', platformName: 'mac', platformVersion: '13.4.0' }, | ||
expected: { browserName: 'firefox', browserVersion: '72.0', platformName: 'mac', platformVersion: '13.4.0' }, | ||
}, { | ||
actual: { | ||
browserName: 'safari', | ||
version: '', | ||
mobile: { browser: 'mobile', version: 'iPhone 7-10.3' }, | ||
platformName: 'iOS', | ||
platform: 'MAC', | ||
platformVersion: '11.0', | ||
}, | ||
expected: { browserName: 'safari', browserVersion: 'iPhone 7-10.3', platformName: 'iOS', platformVersion: '11.0' }, | ||
}, { | ||
actual: { browserName: 'safari', version: '6.0.5', platform: 'MAC' }, | ||
expected: { browserName: 'safari', browserVersion: '6.0.5', platformName: 'MAC' }, | ||
}, { | ||
actual: { browserName: 'opera', version: '12.15', platformName: 'ANY', platform: 'MAC' }, | ||
expected: { browserName: 'opera', browserVersion: '12.15', platformName: 'MAC' }, | ||
}, { | ||
actual: { browserName: 'chrome', deviceManufacturer: 'motorola', deviceModel: 'XT1092', platformName: 'Android', platform: 'LINUX', platformVersion: '6.0' }, | ||
expected: { browserName: 'chrome', browserVersion: 'motorola XT1092', platformName: 'Android', platformVersion: '6.0' }, | ||
}, { | ||
actual: { | ||
browserName: 'safari', | ||
version: '', | ||
mobile: { browser: 'mobile', version: 'iPhone 8 Plus-11.0' }, | ||
platformName: 'iOS', | ||
platform: 'MAC', | ||
platformVersion: '11.0', | ||
}, | ||
expected: { browserName: 'safari', browserVersion: 'iPhone 8 Plus-11.0', platformName: 'iOS', platformVersion: '11.0' }, | ||
}, { | ||
actual: { browserName: 'safari', version: '7.1.8', platform: 'MAC' }, | ||
expected: { browserName: 'safari', browserVersion: '7.1.8', platformName: 'MAC' }, | ||
}, { | ||
actual: { browserName: 'internet explorer', version: '6', platform: 'WINDOWS' }, | ||
expected: { browserName: 'internet explorer', browserVersion: '6', platformName: 'WINDOWS' }, | ||
}, | ||
]). | ||
it(`works`, ({ actual, expected }) => { | ||
const fakeBrowser = { | ||
getCapabilities: () => Promise.resolve(new Capabilities(actual)), | ||
}; | ||
|
||
const capabilities = StandardisedCapabilities.of(() => fakeBrowser as unknown as ProtractorBrowser); | ||
|
||
return Promise.all([ | ||
expect(capabilities.browserName()).to.eventually.equal(expected.browserName), | ||
expect(capabilities.browserVersion()).to.eventually.equal(expected.browserVersion), | ||
expect(capabilities.platformName()).to.eventually.equal(expected.platformName), | ||
expect(capabilities.platformVersion()).to.eventually.equal(expected.platformVersion), | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,56 @@ | ||
import { Capabilities, ProtractorBrowser } from 'protractor'; | ||
|
||
/** | ||
* @private | ||
*/ | ||
export class StandardisedCapabilities { | ||
static of(currentBrowser: () => ProtractorBrowser) { | ||
return new StandardisedCapabilities(currentBrowser); | ||
} | ||
|
||
constructor(private currentBrowser: () => ProtractorBrowser) { | ||
} | ||
|
||
browserName(): PromiseLike<string> { | ||
return this.get( | ||
caps => caps.get('browserName'), | ||
); | ||
} | ||
|
||
browserVersion(): PromiseLike<string> { | ||
return 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, | ||
); | ||
} | ||
|
||
platformName(): PromiseLike<string> { | ||
return this.get( | ||
caps => (caps.has('platformName') && ! /any/i.test(caps.get('platformName'))) | ||
? caps.get('platformName') | ||
: caps.get('platform'), | ||
); | ||
} | ||
|
||
platformVersion(): PromiseLike<string> { | ||
return this.get( | ||
caps => caps.get('platformVersion'), | ||
); | ||
} | ||
|
||
private get(...fetchers: Array<(capabilities: Capabilities) => string>): PromiseLike<string> { | ||
return this.currentBrowser().getCapabilities().then(caps => { | ||
for (const fetcher of fetchers) { | ||
const result = fetcher(caps); | ||
if (!! result) { | ||
return result; | ||
} | ||
} | ||
return undefined; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -1 +1,2 @@ | ||
export * from './BrowserDetector'; | ||
export * from './StandardisedCapabilities'; |