mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat: introduce BrowserType.name() (#732)
This helps a lot to produce nice logging: ```js const { chromium, webkit } = require('playwright'); (async () => { for (const launcher of [chromium, webkit]) { console.log(`Testing on ${launcher.name()}`); const browser = await launcher.launch(); // ... await browser.close(); } })(); ```
This commit is contained in:
parent
184b25ff7b
commit
ce7c8d74b5
@ -3402,6 +3402,7 @@ const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
|
||||
- [browserType.executablePath()](#browsertypeexecutablepath)
|
||||
- [browserType.launch([options])](#browsertypelaunchoptions)
|
||||
- [browserType.launchBrowserApp([options])](#browsertypelaunchbrowserappoptions)
|
||||
- [browserType.name()](#browsertypename)
|
||||
<!-- GEN:stop -->
|
||||
|
||||
#### browserType.connect(options)
|
||||
@ -3523,6 +3524,11 @@ const browser = await chromium.launch({ // Or 'firefox' or 'webkit'.
|
||||
- `devtools` <[boolean]> **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless` option will be set `false`.
|
||||
- returns: <[Promise]<[BrowserApp]>> Promise which resolves to the browser app instance.
|
||||
|
||||
#### browserType.name()
|
||||
- returns: <[string]>
|
||||
|
||||
Returns browser name. For example: `'chromium'`, `'webkit'` or `'firefox'`.
|
||||
|
||||
### class: ChromiumBrowser
|
||||
|
||||
* extends: [Browser]
|
||||
|
@ -41,6 +41,7 @@ export type LaunchOptions = BrowserArgOptions & {
|
||||
|
||||
export interface BrowserType {
|
||||
executablePath(): string;
|
||||
name(): string;
|
||||
launchBrowserApp(options?: LaunchOptions): Promise<BrowserApp>;
|
||||
launch(options?: LaunchOptions): Promise<Browser>;
|
||||
defaultArgs(options?: BrowserArgOptions): string[];
|
||||
|
@ -43,6 +43,10 @@ export class Chromium implements BrowserType {
|
||||
this._revision = preferredRevision;
|
||||
}
|
||||
|
||||
name() {
|
||||
return 'chromium';
|
||||
}
|
||||
|
||||
async launch(options?: LaunchOptions): Promise<CRBrowser> {
|
||||
const app = await this.launchBrowserApp(options);
|
||||
const browser = await CRBrowser.connect(app.connectOptions());
|
||||
|
@ -42,6 +42,10 @@ export class Firefox implements BrowserType {
|
||||
this._revision = preferredRevision;
|
||||
}
|
||||
|
||||
name() {
|
||||
return 'firefox';
|
||||
}
|
||||
|
||||
async launch(options?: LaunchOptions): Promise<FFBrowser> {
|
||||
const app = await this.launchBrowserApp(options);
|
||||
const browser = await FFBrowser.connect(app.connectOptions());
|
||||
|
@ -47,6 +47,10 @@ export class WebKit implements BrowserType {
|
||||
this._revision = preferredRevision;
|
||||
}
|
||||
|
||||
name() {
|
||||
return 'webkit';
|
||||
}
|
||||
|
||||
async launch(options?: LaunchOptions): Promise<WKBrowser> {
|
||||
const app = await this.launchBrowserApp(options);
|
||||
const browser = await WKBrowser.connect(app.connectOptions());
|
||||
|
@ -81,6 +81,19 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
|
||||
});
|
||||
});
|
||||
|
||||
describe('Playwright.name', function() {
|
||||
it('should work', async({server}) => {
|
||||
if (WEBKIT)
|
||||
expect(playwright.name()).toBe('webkit');
|
||||
else if (FFOX)
|
||||
expect(playwright.name()).toBe('firefox');
|
||||
else if (CHROMIUM)
|
||||
expect(playwright.name()).toBe('chromium');
|
||||
else
|
||||
throw new Error('Unknown browser');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Playwright.defaultArguments', () => {
|
||||
it('should return the default arguments', async() => {
|
||||
if (CHROMIUM)
|
||||
|
Loading…
x
Reference in New Issue
Block a user