feat(browser): add Browser.BrowserType() method (#14468)

This commit is contained in:
Sébastien Règne 2022-06-06 18:46:08 +02:00 committed by GitHub
parent 7e130d0c3b
commit 4c2fc6b6eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 0 deletions

View file

@ -79,6 +79,11 @@ Emitted when Browser gets disconnected from the browser application. This might
* Browser application is closed or crashed.
* The [`method: Browser.close`] method was called.
## method: Browser.browserType
- returns: <[BrowserType]>
Get the browser type (chromium, firefox or webkit) that the browser belongs to.
## async method: Browser.close
In case this browser is obtained using [`method: BrowserType.launch`], closes the browser and all of its pages (if any

View file

@ -56,6 +56,10 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
context._setBrowserType(browserType);
}
browserType(): BrowserType {
return this._browserType;
}
async newContext(options: BrowserContextOptions = {}): Promise<BrowserContext> {
options = { ...this._browserType._defaultContextOptions, ...options };
const contextOptions = await prepareBrowserContextParams(options);

View file

@ -12746,6 +12746,11 @@ export interface Browser extends EventEmitter {
*/
off(event: 'disconnected', listener: (browser: Browser) => void): this;
/**
* Get the browser type (chromium, firefox or webkit) that the browser belongs to.
*/
browserType(): BrowserType;
/**
* In case this browser is obtained using
* [browserType.launch([options])](https://playwright.dev/docs/api/class-browsertype#browser-type-launch), closes the

View file

@ -16,6 +16,10 @@
import { browserTest as test, expect } from '../config/browserTest';
test('should return browserType', function({ browser, browserType }) {
expect(browser.browserType()).toBe(browserType);
});
test('should create new page @smoke', async function({ browser }) {
const page1 = await browser.newPage();
expect(browser.contexts().length).toBe(1);