@serenity-js/playwright 3.0.0-rc.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/LICENSE.md +201 -0
- package/NOTICE.md +1 -0
- package/README.md +145 -0
- package/lib/PlaywrightOptions.d.ts +40 -0
- package/lib/PlaywrightOptions.js +3 -0
- package/lib/PlaywrightOptions.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +1 -0
- package/lib/screenplay/abilities/BrowseTheWebWithPlaywright.d.ts +71 -0
- package/lib/screenplay/abilities/BrowseTheWebWithPlaywright.js +86 -0
- package/lib/screenplay/abilities/BrowseTheWebWithPlaywright.js.map +1 -0
- package/lib/screenplay/abilities/index.d.ts +1 -0
- package/lib/screenplay/abilities/index.js +18 -0
- package/lib/screenplay/abilities/index.js.map +1 -0
- package/lib/screenplay/index.d.ts +2 -0
- package/lib/screenplay/index.js +19 -0
- package/lib/screenplay/index.js.map +1 -0
- package/lib/screenplay/models/PlaywrightBrowsingSession.d.ts +25 -0
- package/lib/screenplay/models/PlaywrightBrowsingSession.js +67 -0
- package/lib/screenplay/models/PlaywrightBrowsingSession.js.map +1 -0
- package/lib/screenplay/models/PlaywrightCookie.d.ts +8 -0
- package/lib/screenplay/models/PlaywrightCookie.js +39 -0
- package/lib/screenplay/models/PlaywrightCookie.js.map +1 -0
- package/lib/screenplay/models/PlaywrightModalDialogHandler.d.ts +13 -0
- package/lib/screenplay/models/PlaywrightModalDialogHandler.js +45 -0
- package/lib/screenplay/models/PlaywrightModalDialogHandler.js.map +1 -0
- package/lib/screenplay/models/PlaywrightPage.d.ts +58 -0
- package/lib/screenplay/models/PlaywrightPage.js +177 -0
- package/lib/screenplay/models/PlaywrightPage.js.map +1 -0
- package/lib/screenplay/models/PlaywrightPageElement.d.ts +24 -0
- package/lib/screenplay/models/PlaywrightPageElement.js +194 -0
- package/lib/screenplay/models/PlaywrightPageElement.js.map +1 -0
- package/lib/screenplay/models/index.d.ts +5 -0
- package/lib/screenplay/models/index.js +22 -0
- package/lib/screenplay/models/index.js.map +1 -0
- package/lib/screenplay/models/locators/PlaywrightLocator.d.ts +13 -0
- package/lib/screenplay/models/locators/PlaywrightLocator.js +77 -0
- package/lib/screenplay/models/locators/PlaywrightLocator.js.map +1 -0
- package/lib/screenplay/models/locators/PlaywrightRootLocator.d.ts +11 -0
- package/lib/screenplay/models/locators/PlaywrightRootLocator.js +26 -0
- package/lib/screenplay/models/locators/PlaywrightRootLocator.js.map +1 -0
- package/lib/screenplay/models/locators/index.d.ts +2 -0
- package/lib/screenplay/models/locators/index.js +19 -0
- package/lib/screenplay/models/locators/index.js.map +1 -0
- package/package.json +68 -0
- package/src/PlaywrightOptions.ts +43 -0
- package/src/index.ts +2 -0
- package/src/screenplay/abilities/BrowseTheWebWithPlaywright.ts +89 -0
- package/src/screenplay/abilities/index.ts +1 -0
- package/src/screenplay/index.ts +2 -0
- package/src/screenplay/models/PlaywrightBrowsingSession.ts +88 -0
- package/src/screenplay/models/PlaywrightCookie.ts +46 -0
- package/src/screenplay/models/PlaywrightModalDialogHandler.ts +53 -0
- package/src/screenplay/models/PlaywrightPage.ts +258 -0
- package/src/screenplay/models/PlaywrightPageElement.ts +235 -0
- package/src/screenplay/models/index.ts +5 -0
- package/src/screenplay/models/locators/PlaywrightLocator.ts +113 -0
- package/src/screenplay/models/locators/PlaywrightRootLocator.ts +29 -0
- package/src/screenplay/models/locators/index.ts +2 -0
- package/tsconfig.eslint.json +10 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { f, LogicError } from '@serenity-js/core';
|
|
2
|
+
import { ByCss, ByCssContainingText, ByDeepCss, ById, ByTagName, ByXPath, Locator, PageElement, RootLocator, Selector } from '@serenity-js/web';
|
|
3
|
+
import * as playwright from 'playwright';
|
|
4
|
+
|
|
5
|
+
import { PlaywrightPageElement } from '../PlaywrightPageElement';
|
|
6
|
+
import { PlaywrightRootLocator } from './PlaywrightRootLocator';
|
|
7
|
+
|
|
8
|
+
export class PlaywrightLocator extends Locator<playwright.ElementHandle, string> {
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
parent: RootLocator<playwright.ElementHandle>,
|
|
12
|
+
selector: Selector,
|
|
13
|
+
) {
|
|
14
|
+
super(parent, selector);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// todo: refactor; replace with a map and some more generic lookup mechanism
|
|
18
|
+
protected nativeSelector(): string {
|
|
19
|
+
if (this.selector instanceof ByCss) {
|
|
20
|
+
return `:light(${ this.selector.value })`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (this.selector instanceof ByDeepCss) {
|
|
24
|
+
return this.selector.value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (this.selector instanceof ByCssContainingText) {
|
|
28
|
+
return `:light(${ this.selector.value }):has-text("${ this.selector.text }")`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (this.selector instanceof ById) {
|
|
32
|
+
return `id=${ this.selector.value }`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (this.selector instanceof ByTagName) {
|
|
36
|
+
return `:light(${ this.selector.value })`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (this.selector instanceof ByXPath) {
|
|
40
|
+
return `xpath=${ this.selector.value }`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
throw new LogicError(f`${ this.selector } is not supported by ${ this.constructor.name }`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async nativeElement(): Promise<playwright.ElementHandle> {
|
|
47
|
+
|
|
48
|
+
const parent = await this.parent.nativeElement();
|
|
49
|
+
|
|
50
|
+
if (! parent) {
|
|
51
|
+
throw new LogicError(`Couldn't find parent element ${ this.parent } of ${ this }`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return parent.waitForSelector(this.nativeSelector(), { state: 'attached' });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async allNativeElements(): Promise<Array<playwright.ElementHandle>> {
|
|
58
|
+
const parent = await this.parent.nativeElement();
|
|
59
|
+
|
|
60
|
+
if (! parent) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return parent.$$(this.nativeSelector());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
of(parent: PlaywrightRootLocator): Locator<playwright.ElementHandle, string> {
|
|
68
|
+
return new PlaywrightLocator(parent, this.selector);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
locate(child: PlaywrightLocator): Locator<playwright.ElementHandle, string> {
|
|
72
|
+
return new PlaywrightLocator(this, child.selector);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
element(): PageElement<playwright.ElementHandle> {
|
|
76
|
+
return new PlaywrightPageElement(this);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async allElements(): Promise<Array<PageElement<playwright.ElementHandle>>> {
|
|
80
|
+
const elements = await this.allNativeElements();
|
|
81
|
+
|
|
82
|
+
return elements.map(childElement =>
|
|
83
|
+
new PlaywrightPageElement(
|
|
84
|
+
new ExistingElementLocator(
|
|
85
|
+
this.parent as PlaywrightRootLocator,
|
|
86
|
+
this.selector,
|
|
87
|
+
childElement,
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @private
|
|
96
|
+
*/
|
|
97
|
+
class ExistingElementLocator extends PlaywrightLocator {
|
|
98
|
+
constructor(
|
|
99
|
+
parent: RootLocator<playwright.ElementHandle>,
|
|
100
|
+
selector: Selector,
|
|
101
|
+
private readonly existingNativeElement: playwright.ElementHandle,
|
|
102
|
+
) {
|
|
103
|
+
super(parent, selector);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async nativeElement(): Promise<playwright.ElementHandle> {
|
|
107
|
+
return this.existingNativeElement;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async allNativeElements(): Promise<Array<playwright.ElementHandle>> {
|
|
111
|
+
return [ this.existingNativeElement ];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { RootLocator } from '@serenity-js/web';
|
|
2
|
+
import * as playwright from 'playwright';
|
|
3
|
+
import { ensure, isDefined } from 'tiny-types';
|
|
4
|
+
|
|
5
|
+
export class PlaywrightRootLocator extends RootLocator<playwright.ElementHandle> {
|
|
6
|
+
|
|
7
|
+
private currentFrame: playwright.Frame;
|
|
8
|
+
|
|
9
|
+
constructor(private readonly page: playwright.Page) {
|
|
10
|
+
super();
|
|
11
|
+
this.currentFrame = this.page.mainFrame();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async nativeElement(): Promise<Pick<playwright.ElementHandle, '$' | '$$' | 'waitForSelector'>> {
|
|
15
|
+
return this.currentFrame;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async switchToFrame(frame: playwright.ElementHandle): Promise<void> {
|
|
19
|
+
this.currentFrame = ensure('frame', await frame.contentFrame(), isDefined());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async switchToParentFrame(): Promise<void> {
|
|
23
|
+
this.currentFrame = ensure('parent frame', this.currentFrame.parentFrame(), isDefined());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async switchToMainFrame(): Promise<void> {
|
|
27
|
+
this.currentFrame = this.page.mainFrame();
|
|
28
|
+
}
|
|
29
|
+
}
|