playwright-selector-finder
Version:
A tool for finding and interacting with elements using Playwright's vision locators
52 lines (51 loc) • 1.58 kB
JavaScript
;
/**
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Context = void 0;
class Context {
browser;
browserContext;
page;
options;
constructor(browser, options) {
this.browser = browser;
this.options = options;
}
async getPage() {
if (!this.page) {
if (!this.browserContext) {
this.browserContext = await this.browser.newContext({
baseURL: 'http://localhost',
viewport: { width: 1280, height: 720 }
});
}
this.page = await this.browserContext.newPage();
}
return this.page;
}
getOptions() {
return this.options;
}
async close() {
await this.page?.close();
await this.browserContext?.close();
await this.browser.close();
this.page = undefined;
this.browserContext = undefined;
}
}
exports.Context = Context;