This commit is contained in:
Yury Semikhatsky 2019-11-22 14:04:04 -08:00 committed by Pavel Feldman
parent ac01262c88
commit 37a9c17d3e
3 changed files with 18 additions and 4 deletions

View File

@ -72,6 +72,19 @@ export class Browser extends EventEmitter {
this._screenshotTaskQueue = new TaskQueue(); this._screenshotTaskQueue = new TaskQueue();
} }
async userAgent(): Promise<string> {
const context = await this.createIncognitoBrowserContext();
const page = await context.newPage();
const userAgent = await page.evaluate('navigator.userAgent');
context.close();
return userAgent;
}
async version(): Promise<string> {
const userAgent = await this.userAgent();
return userAgent.split(' ').pop();
}
process(): childProcess.ChildProcess | null { process(): childProcess.ChildProcess | null {
return this._process; return this._process;
} }

View File

@ -19,18 +19,20 @@ module.exports.addTests = function({testRunner, expect, headless, playwright, FF
const {it, fit, xit} = testRunner; const {it, fit, xit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe.skip(WEBKIT)('Browser.version', function() { describe('Browser.version', function() {
it('should return whether we are in headless', async({browser}) => { it('should return whether we are in headless', async({browser}) => {
const version = await browser.version(); const version = await browser.version();
expect(version.length).toBeGreaterThan(0); expect(version.length).toBeGreaterThan(0);
if (CHROME || WEBKIT) if (CHROME)
expect(version.startsWith('Headless')).toBe(headless); expect(version.startsWith('Headless')).toBe(headless);
else if (WEBKIT)
expect(version.startsWith('Safari/')).toBe(true);
else else
expect(version.startsWith('Firefox/')).toBe(true); expect(version.startsWith('Firefox/')).toBe(true);
}); });
}); });
describe.skip(WEBKIT)('Browser.userAgent', function() { describe('Browser.userAgent', function() {
it('should include WebKit', async({browser}) => { it('should include WebKit', async({browser}) => {
const userAgent = await browser.userAgent(); const userAgent = await browser.userAgent();
expect(userAgent.length).toBeGreaterThan(0); expect(userAgent.length).toBeGreaterThan(0);

View File

@ -18,7 +18,6 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
let {describe, xdescribe, fdescribe} = testRunner; let {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit} = testRunner; const {it, fit, xit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
describe = fdescribe;
const iPhone = playwright.devices['iPhone 6']; const iPhone = playwright.devices['iPhone 6'];
const iPhoneLandscape = playwright.devices['iPhone 6 landscape']; const iPhoneLandscape = playwright.devices['iPhone 6 landscape'];