@serenity-js/playwright
Version:
Adapter that integrates @serenity-js/web with Playwright, enabling Serenity/JS reporting and using the Screenplay Pattern to write component and end-to-end test scenarios
52 lines • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlaywrightRootLocator = void 0;
const web_1 = require("@serenity-js/web");
const tiny_types_1 = require("tiny-types");
const promised_1 = require("../../promised");
/**
* Playwright-specific implementation of [`RootLocator`](https://serenity-js.org/api/web/class/RootLocator/).
*
* @group Models
*/
class PlaywrightRootLocator extends web_1.RootLocator {
page;
currentFrame;
constructor(page) {
super();
this.page = page;
this.currentFrame = this.page.mainFrame();
}
async isPresent() {
return true;
}
nativeElement() {
return (0, promised_1.promised)(this.currentFrame);
}
evaluate(pageFunction, arg) {
return this.currentFrame.evaluate(pageFunction, arg);
}
/**
* Switches the current context to the frame identified by the given locator.
*
* @param frame
*/
async switchToFrame(frame) {
const element = await frame.elementHandle();
this.currentFrame = (0, tiny_types_1.ensure)('frame', await element.contentFrame(), (0, tiny_types_1.isDefined)());
}
/**
* Switches the current context to the parent frame of the current frame.
*/
async switchToParentFrame() {
this.currentFrame = (0, tiny_types_1.ensure)('parent frame', this.currentFrame.parentFrame(), (0, tiny_types_1.isDefined)());
}
/**
* Switches the context to the top-level frame.
*/
async switchToMainFrame() {
this.currentFrame = this.page.mainFrame();
}
}
exports.PlaywrightRootLocator = PlaywrightRootLocator;
//# sourceMappingURL=PlaywrightRootLocator.js.map