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-21 18:46:11 -07:00
|
|
|
import { PlaywrightChannel, PlaywrightInitializer } from '../../protocol/channels';
|
2020-07-08 18:42:04 -07:00
|
|
|
import { BrowserType } from './browserType';
|
|
|
|
import { ChannelOwner } from './channelOwner';
|
2020-07-13 17:47:15 -07:00
|
|
|
import { Selectors } from './selectors';
|
2020-07-13 21:46:59 -07:00
|
|
|
import { Electron } from './electron';
|
2020-08-21 18:46:11 -07:00
|
|
|
import { TimeoutError } from '../../utils/errors';
|
2020-07-29 17:26:59 -07:00
|
|
|
import { Size } from './types';
|
|
|
|
|
|
|
|
type DeviceDescriptor = {
|
|
|
|
userAgent: string,
|
|
|
|
viewport: Size,
|
|
|
|
deviceScaleFactor: number,
|
|
|
|
isMobile: boolean,
|
|
|
|
hasTouch: boolean
|
|
|
|
};
|
|
|
|
type Devices = { [name: string]: DeviceDescriptor };
|
2020-07-08 18:42:04 -07:00
|
|
|
|
|
|
|
export class Playwright extends ChannelOwner<PlaywrightChannel, PlaywrightInitializer> {
|
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-07-10 18:00:10 -07:00
|
|
|
constructor(parent: ChannelOwner, type: string, guid: string, initializer: PlaywrightInitializer) {
|
|
|
|
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-07-13 21:46:59 -07:00
|
|
|
if (initializer.electron)
|
|
|
|
(this as any).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-07-13 17:47:15 -07:00
|
|
|
this.selectors = Selectors.from(initializer.selectors);
|
2020-07-16 22:38:52 -07:00
|
|
|
this.errors = { TimeoutError };
|
2020-07-08 18:42:04 -07:00
|
|
|
}
|
|
|
|
}
|