2020-01-09 14:49:22 -08: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as types from '../types';
|
2020-02-26 15:13:31 -08:00
|
|
|
import * as api from '../api';
|
|
|
|
import { helper } from '../helper';
|
2020-01-09 14:49:22 -08:00
|
|
|
import { TimeoutError } from '../errors';
|
2020-01-24 14:49:47 -08:00
|
|
|
import { DeviceDescriptors } from '../deviceDescriptors';
|
|
|
|
import { Chromium } from './chromium';
|
|
|
|
import { WebKit } from './webkit';
|
|
|
|
import { Firefox } from './firefox';
|
2020-03-25 14:08:46 -07:00
|
|
|
import { selectors } from '../selectors';
|
2020-01-09 14:49:22 -08:00
|
|
|
|
2020-02-26 15:13:31 -08:00
|
|
|
for (const className in api) {
|
|
|
|
if (typeof (api as any)[className] === 'function')
|
|
|
|
helper.installApiHooks(className[0].toLowerCase() + className.substring(1), (api as any)[className]);
|
|
|
|
}
|
|
|
|
|
2020-03-02 13:45:10 -08:00
|
|
|
type PlaywrightOptions = {
|
|
|
|
browsers: Array<('firefox'|'webkit'|'chromium')>,
|
|
|
|
};
|
|
|
|
|
2020-01-24 14:49:47 -08:00
|
|
|
export class Playwright {
|
2020-03-25 14:08:46 -07:00
|
|
|
readonly selectors = selectors;
|
2020-01-24 14:49:47 -08:00
|
|
|
readonly devices: types.Devices;
|
|
|
|
readonly errors: { TimeoutError: typeof TimeoutError };
|
2020-02-26 15:13:31 -08:00
|
|
|
readonly chromium: (Chromium|undefined);
|
|
|
|
readonly firefox: (Firefox|undefined);
|
|
|
|
readonly webkit: (WebKit|undefined);
|
2020-01-24 14:49:47 -08:00
|
|
|
|
2020-03-02 13:45:10 -08:00
|
|
|
constructor(options: PlaywrightOptions) {
|
2020-02-26 15:13:31 -08:00
|
|
|
const {
|
|
|
|
browsers,
|
|
|
|
} = options;
|
2020-01-24 14:49:47 -08:00
|
|
|
this.devices = DeviceDescriptors;
|
|
|
|
this.errors = { TimeoutError };
|
2020-02-26 15:13:31 -08:00
|
|
|
if (browsers.includes('chromium'))
|
2020-03-19 11:43:35 -07:00
|
|
|
this.chromium = new Chromium();
|
2020-02-26 15:13:31 -08:00
|
|
|
if (browsers.includes('webkit'))
|
2020-03-19 11:43:35 -07:00
|
|
|
this.webkit = new WebKit();
|
2020-02-26 15:13:31 -08:00
|
|
|
if (browsers.includes('firefox'))
|
2020-03-19 11:43:35 -07:00
|
|
|
this.firefox = new Firefox();
|
2020-01-24 14:49:47 -08:00
|
|
|
}
|
2020-01-09 14:49:22 -08:00
|
|
|
}
|