@serenity-js/playwright
Advanced tools
Comparing version 3.22.2 to 3.22.3
@@ -6,2 +6,13 @@ # Change Log | ||
## [3.22.3](https://github.com/serenity-js/serenity-js/compare/v3.22.2...v3.22.3) (2024-05-01) | ||
### Bug Fixes | ||
* **playwright:** ensure ExecuteScript runs in the context of the currently active iframe ([3592ca0](https://github.com/serenity-js/serenity-js/commit/3592ca067a942e428d337515644233be003e6e36)) | ||
## [3.22.2](https://github.com/serenity-js/serenity-js/compare/v3.22.1...v3.22.2) (2024-04-20) | ||
@@ -8,0 +19,0 @@ |
import { RootLocator } from '@serenity-js/web'; | ||
import type * as playwright from 'playwright-core'; | ||
import { type PageFunction } from 'playwright-core/types/structs'; | ||
/** | ||
@@ -14,6 +15,25 @@ * Playwright-specific implementation of {@apilink RootLocator}. | ||
nativeElement(): Promise<Pick<playwright.Locator, 'locator'>>; | ||
/** | ||
* Evaluates the given `pageFunction` in the context of the current frame. | ||
* See [`playwright.Frame.evaluate`](https://playwright.dev/docs/api/class-frame#frame-evaluate). | ||
* | ||
* @param pageFunction | ||
* @param arg | ||
*/ | ||
evaluate<R, Arguments>(pageFunction: PageFunction<Arguments, R>, arg: Arguments): Promise<R>; | ||
/** | ||
* Switches the current context to the frame identified by the given locator. | ||
* | ||
* @param frame | ||
*/ | ||
switchToFrame(frame: playwright.Locator): Promise<void>; | ||
/** | ||
* Switches the current context to the parent frame of the current frame. | ||
*/ | ||
switchToParentFrame(): Promise<void>; | ||
/** | ||
* Switches the context to the top-level frame. | ||
*/ | ||
switchToMainFrame(): Promise<void>; | ||
} | ||
//# sourceMappingURL=PlaywrightRootLocator.d.ts.map |
@@ -26,2 +26,10 @@ "use strict"; | ||
} | ||
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) { | ||
@@ -31,5 +39,11 @@ const element = await frame.elementHandle(); | ||
} | ||
/** | ||
* 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() { | ||
@@ -36,0 +50,0 @@ this.currentFrame = this.page.mainFrame(); |
@@ -70,3 +70,3 @@ "use strict"; | ||
: String(`function script() { ${script} }`); | ||
const result = await this.page.evaluate(new Function(` | ||
const result = await this.rootLocator.evaluate(new Function(` | ||
const parameters = arguments[0]; | ||
@@ -85,3 +85,3 @@ return (${serialisedScript}).apply(null, parameters); | ||
: String(`function script() { ${script} }`); | ||
const result = await this.page.evaluate(new Function(` | ||
const result = await this.rootLocator.evaluate(new Function(` | ||
const parameters = arguments[0]; | ||
@@ -88,0 +88,0 @@ |
{ | ||
"name": "@serenity-js/playwright", | ||
"version": "3.22.2", | ||
"version": "3.22.3", | ||
"description": "Serenity/JS Screenplay Pattern library for Playwright", | ||
@@ -47,4 +47,4 @@ "author": { | ||
"dependencies": { | ||
"@serenity-js/core": "3.22.2", | ||
"@serenity-js/web": "3.22.2", | ||
"@serenity-js/core": "3.22.3", | ||
"@serenity-js/web": "3.22.3", | ||
"playwright-core": "1.43.1", | ||
@@ -63,3 +63,3 @@ "tiny-types": "1.22.0" | ||
}, | ||
"gitHead": "8850a46de7b2fa66f17f35f8dcb9c4863c14a14e" | ||
"gitHead": "cf6dca18893e1087c1ff95c419a422c73c7f47ce" | ||
} |
import { RootLocator } from '@serenity-js/web'; | ||
import type * as playwright from 'playwright-core'; | ||
import { type PageFunction } from 'playwright-core/types/structs'; | ||
import { ensure, isDefined } from 'tiny-types'; | ||
@@ -29,2 +30,19 @@ | ||
/** | ||
* Evaluates the given `pageFunction` in the context of the current frame. | ||
* See [`playwright.Frame.evaluate`](https://playwright.dev/docs/api/class-frame#frame-evaluate). | ||
* | ||
* @param pageFunction | ||
* @param arg | ||
*/ | ||
evaluate<R, Arguments>(pageFunction: PageFunction<Arguments, R>, arg: Arguments): Promise<R>; | ||
evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any): Promise<R> { // eslint-disable-line @typescript-eslint/explicit-module-boundary-types | ||
return this.currentFrame.evaluate(pageFunction, arg); | ||
} | ||
/** | ||
* Switches the current context to the frame identified by the given locator. | ||
* | ||
* @param frame | ||
*/ | ||
async switchToFrame(frame: playwright.Locator): Promise<void> { | ||
@@ -35,2 +53,5 @@ const element = await frame.elementHandle(); | ||
/** | ||
* Switches the current context to the parent frame of the current frame. | ||
*/ | ||
async switchToParentFrame(): Promise<void> { | ||
@@ -40,2 +61,5 @@ this.currentFrame = ensure('parent frame', this.currentFrame.parentFrame(), isDefined()); | ||
/** | ||
* Switches the context to the top-level frame. | ||
*/ | ||
async switchToMainFrame(): Promise<void> { | ||
@@ -42,0 +66,0 @@ this.currentFrame = this.page.mainFrame(); |
@@ -119,7 +119,7 @@ import { List, LogicError, type QuestionAdapter } from '@serenity-js/core'; | ||
const result = await this.page.evaluate<Result, typeof nativeArguments>( | ||
const result = await (this.rootLocator as PlaywrightRootLocator).evaluate<Result, typeof nativeArguments>( | ||
new Function(` | ||
const parameters = arguments[0]; | ||
return (${ serialisedScript }).apply(null, parameters); | ||
`) as Parameters<typeof this.page.evaluate>[1], | ||
`) as Parameters<playwright.Frame['evaluate']>[1], | ||
nativeArguments, | ||
@@ -147,3 +147,3 @@ ); | ||
const result = await this.page.evaluate<Result, typeof nativeArguments>( | ||
const result = await (this.rootLocator as PlaywrightRootLocator).evaluate<Result, typeof nativeArguments>( | ||
new Function(` | ||
@@ -159,3 +159,3 @@ const parameters = arguments[0]; | ||
}) | ||
`) as Parameters<typeof this.page.evaluate>[1], | ||
`) as Parameters<playwright.Frame['evaluate']>[1], | ||
nativeArguments | ||
@@ -162,0 +162,0 @@ ); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
206535
2806
+ Added@serenity-js/assertions@3.22.3(transitive)
+ Added@serenity-js/core@3.22.3(transitive)
+ Added@serenity-js/web@3.22.3(transitive)
- Removed@serenity-js/assertions@3.22.2(transitive)
- Removed@serenity-js/core@3.22.2(transitive)
- Removed@serenity-js/web@3.22.2(transitive)
Updated@serenity-js/core@3.22.3
Updated@serenity-js/web@3.22.3