2020-07-08 18:42:04 -07:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-08-24 17:05:16 -07:00
|
|
|
import * as channels from '../protocol/channels';
|
2020-07-08 18:42:04 -07:00
|
|
|
import { BrowserType } from './browserType';
|
|
|
|
import { ChannelOwner } from './channelOwner';
|
2020-09-02 16:15:43 -07:00
|
|
|
import { Selectors, SelectorsOwner, sharedSelectors } from './selectors';
|
2020-07-13 21:46:59 -07:00
|
|
|
import { Electron } from './electron';
|
2020-08-22 15:13:51 -07:00
|
|
|
import { TimeoutError } from '../utils/errors';
|
2020-07-29 17:26:59 -07:00
|
|
|
import { Size } from './types';
|
2020-12-09 15:06:57 -08:00
|
|
|
import { Android } from './android';
|
2020-07-29 17:26:59 -07:00
|
|
|
|
|
|
|
type DeviceDescriptor = {
|
|
|
|
userAgent: string,
|
|
|
|
viewport: Size,
|
|
|
|
deviceScaleFactor: number,
|
|
|
|
isMobile: boolean,
|
2020-09-03 22:12:43 +02:00
|
|
|
hasTouch: boolean,
|
|
|
|
defaultBrowserType: 'chromium' | 'firefox' | 'webkit'
|
2020-07-29 17:26:59 -07:00
|
|
|
};
|
|
|
|
type Devices = { [name: string]: DeviceDescriptor };
|
2020-07-08 18:42:04 -07:00
|
|
|
|
2020-08-24 17:05:16 -07:00
|
|
|
export class Playwright extends ChannelOwner<channels.PlaywrightChannel, channels.PlaywrightInitializer> {
|
2020-12-09 15:06:57 -08:00
|
|
|
readonly _android: Android;
|
|
|
|
readonly _electron: Electron;
|
2020-07-16 22:38:52 -07:00
|
|
|
readonly chromium: BrowserType;
|
|
|
|
readonly firefox: BrowserType;
|
|
|
|
readonly webkit: BrowserType;
|
2020-07-29 17:26:59 -07:00
|
|
|
readonly devices: Devices;
|
2020-07-16 22:38:52 -07:00
|
|
|
readonly selectors: Selectors;
|
|
|
|
readonly errors: { TimeoutError: typeof TimeoutError };
|
2020-07-08 18:42:04 -07:00
|
|
|
|
2020-08-24 17:05:16 -07:00
|
|
|
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.PlaywrightInitializer) {
|
2020-07-10 18:00:10 -07:00
|
|
|
super(parent, type, guid, initializer);
|
2020-07-08 18:42:04 -07:00
|
|
|
this.chromium = BrowserType.from(initializer.chromium);
|
|
|
|
this.firefox = BrowserType.from(initializer.firefox);
|
|
|
|
this.webkit = BrowserType.from(initializer.webkit);
|
2020-12-09 15:06:57 -08:00
|
|
|
this._android = Android.from(initializer.android);
|
|
|
|
this._electron = Electron.from(initializer.electron);
|
2020-07-16 13:18:54 -07:00
|
|
|
this.devices = {};
|
|
|
|
for (const { name, descriptor } of initializer.deviceDescriptors)
|
|
|
|
this.devices[name] = descriptor;
|
2020-09-02 16:15:43 -07:00
|
|
|
this.selectors = sharedSelectors;
|
2020-07-16 22:38:52 -07:00
|
|
|
this.errors = { TimeoutError };
|
2020-09-02 16:15:43 -07:00
|
|
|
this.selectors._addChannel(SelectorsOwner.from(initializer.selectors));
|
2020-07-08 18:42:04 -07:00
|
|
|
}
|
|
|
|
}
|