@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
48 lines • 1.46 kB
JavaScript
import { RootLocator } from '@serenity-js/web';
import { ensure, isDefined } from 'tiny-types';
import { promised } from '../../promised.js';
/**
* Playwright-specific implementation of [`RootLocator`](https://serenity-js.org/api/web/class/RootLocator/).
*
* @group Models
*/
export class PlaywrightRootLocator extends RootLocator {
page;
currentFrame;
constructor(page) {
super();
this.page = page;
this.currentFrame = this.page.mainFrame();
}
async isPresent() {
return true;
}
nativeElement() {
return 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 = ensure('frame', await element.contentFrame(), isDefined());
}
/**
* Switches the current context to the parent frame of the current frame.
*/
async switchToParentFrame() {
this.currentFrame = ensure('parent frame', this.currentFrame.parentFrame(), isDefined());
}
/**
* Switches the context to the top-level frame.
*/
async switchToMainFrame() {
this.currentFrame = this.page.mainFrame();
}
}
//# sourceMappingURL=PlaywrightRootLocator.js.map