@vitest/browser-playwright 4.0.0-beta.14
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/README.md +48 -0
- package/context.d.ts +1 -0
- package/dist/index.d.ts +110 -0
- package/dist/index.js +1099 -0
- package/dist/locators.js +114 -0
- package/package.json +58 -0
package/dist/locators.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { selectorEngine, getByTitleSelector, getByTextSelector, getByPlaceholderSelector, getByAltTextSelector, getByTestIdSelector, getByRoleSelector, getByLabelSelector, Locator, processTimeoutOptions, getIframeScale } from '@vitest/browser/locators';
|
|
2
|
+
import { page, server } from 'vitest/browser';
|
|
3
|
+
import { __INTERNAL } from 'vitest/internal/browser';
|
|
4
|
+
|
|
5
|
+
class PlaywrightLocator extends Locator {
|
|
6
|
+
constructor(selector, _container) {
|
|
7
|
+
super();
|
|
8
|
+
this.selector = selector;
|
|
9
|
+
this._container = _container;
|
|
10
|
+
}
|
|
11
|
+
click(options) {
|
|
12
|
+
return super.click(processTimeoutOptions(processClickOptions(options)));
|
|
13
|
+
}
|
|
14
|
+
dblClick(options) {
|
|
15
|
+
return super.dblClick(processTimeoutOptions(processClickOptions(options)));
|
|
16
|
+
}
|
|
17
|
+
tripleClick(options) {
|
|
18
|
+
return super.tripleClick(processTimeoutOptions(processClickOptions(options)));
|
|
19
|
+
}
|
|
20
|
+
selectOptions(value, options) {
|
|
21
|
+
return super.selectOptions(value, processTimeoutOptions(options));
|
|
22
|
+
}
|
|
23
|
+
clear(options) {
|
|
24
|
+
return super.clear(processTimeoutOptions(options));
|
|
25
|
+
}
|
|
26
|
+
hover(options) {
|
|
27
|
+
return super.hover(processTimeoutOptions(processHoverOptions(options)));
|
|
28
|
+
}
|
|
29
|
+
upload(files, options) {
|
|
30
|
+
return super.upload(files, processTimeoutOptions(options));
|
|
31
|
+
}
|
|
32
|
+
fill(text, options) {
|
|
33
|
+
return super.fill(text, processTimeoutOptions(options));
|
|
34
|
+
}
|
|
35
|
+
dropTo(target, options) {
|
|
36
|
+
return super.dropTo(target, processTimeoutOptions(processDragAndDropOptions(options)));
|
|
37
|
+
}
|
|
38
|
+
locator(selector) {
|
|
39
|
+
return new PlaywrightLocator(`${this.selector} >> ${selector}`, this._container);
|
|
40
|
+
}
|
|
41
|
+
elementLocator(element) {
|
|
42
|
+
return new PlaywrightLocator(selectorEngine.generateSelectorSimple(element), element);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
page.extend({
|
|
46
|
+
getByLabelText(text, options) {
|
|
47
|
+
return new PlaywrightLocator(getByLabelSelector(text, options));
|
|
48
|
+
},
|
|
49
|
+
getByRole(role, options) {
|
|
50
|
+
return new PlaywrightLocator(getByRoleSelector(role, options));
|
|
51
|
+
},
|
|
52
|
+
getByTestId(testId) {
|
|
53
|
+
return new PlaywrightLocator(getByTestIdSelector(server.config.browser.locators.testIdAttribute, testId));
|
|
54
|
+
},
|
|
55
|
+
getByAltText(text, options) {
|
|
56
|
+
return new PlaywrightLocator(getByAltTextSelector(text, options));
|
|
57
|
+
},
|
|
58
|
+
getByPlaceholder(text, options) {
|
|
59
|
+
return new PlaywrightLocator(getByPlaceholderSelector(text, options));
|
|
60
|
+
},
|
|
61
|
+
getByText(text, options) {
|
|
62
|
+
return new PlaywrightLocator(getByTextSelector(text, options));
|
|
63
|
+
},
|
|
64
|
+
getByTitle(title, options) {
|
|
65
|
+
return new PlaywrightLocator(getByTitleSelector(title, options));
|
|
66
|
+
},
|
|
67
|
+
elementLocator(element) {
|
|
68
|
+
return new PlaywrightLocator(selectorEngine.generateSelectorSimple(element), element);
|
|
69
|
+
},
|
|
70
|
+
frameLocator(locator) {
|
|
71
|
+
return new PlaywrightLocator(`${locator.selector} >> internal:control=enter-frame`);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
__INTERNAL._createLocator = (selector) => new PlaywrightLocator(selector);
|
|
75
|
+
function processDragAndDropOptions(options) {
|
|
76
|
+
if (!options) {
|
|
77
|
+
return options;
|
|
78
|
+
}
|
|
79
|
+
if (options.sourcePosition) {
|
|
80
|
+
options.sourcePosition = processPlaywrightPosition(options.sourcePosition);
|
|
81
|
+
}
|
|
82
|
+
if (options.targetPosition) {
|
|
83
|
+
options.targetPosition = processPlaywrightPosition(options.targetPosition);
|
|
84
|
+
}
|
|
85
|
+
return options;
|
|
86
|
+
}
|
|
87
|
+
function processHoverOptions(options) {
|
|
88
|
+
if (!options) {
|
|
89
|
+
return options;
|
|
90
|
+
}
|
|
91
|
+
if (options.position) {
|
|
92
|
+
options.position = processPlaywrightPosition(options.position);
|
|
93
|
+
}
|
|
94
|
+
return options;
|
|
95
|
+
}
|
|
96
|
+
function processClickOptions(options) {
|
|
97
|
+
if (!options) {
|
|
98
|
+
return options;
|
|
99
|
+
}
|
|
100
|
+
if (options.position) {
|
|
101
|
+
options.position = processPlaywrightPosition(options.position);
|
|
102
|
+
}
|
|
103
|
+
return options;
|
|
104
|
+
}
|
|
105
|
+
function processPlaywrightPosition(position) {
|
|
106
|
+
const scale = getIframeScale();
|
|
107
|
+
if (position.x != null) {
|
|
108
|
+
position.x *= scale;
|
|
109
|
+
}
|
|
110
|
+
if (position.y != null) {
|
|
111
|
+
position.y *= scale;
|
|
112
|
+
}
|
|
113
|
+
return position;
|
|
114
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vitest/browser-playwright",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "4.0.0-beta.14",
|
|
5
|
+
"description": "Browser running for Vitest using playwright",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"funding": "https://opencollective.com/vitest",
|
|
8
|
+
"homepage": "https://vitest.dev/guide/browser/playwright",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/vitest-dev/vitest.git",
|
|
12
|
+
"directory": "packages/browser-playwright"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/vitest-dev/vitest/issues"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./context": {
|
|
24
|
+
"types": "./context.d.ts"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"context.d.ts",
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "premove dist && pnpm rollup -c",
|
|
37
|
+
"dev": "rollup -c --watch --watch.include 'src/**'"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"playwright": "*",
|
|
41
|
+
"vitest": "workspace:*"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"playwright": {
|
|
45
|
+
"optional": false
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@vitest/browser": "workspace:*",
|
|
50
|
+
"@vitest/mocker": "workspace:*",
|
|
51
|
+
"tinyrainbow": "catalog:"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"playwright": "^1.55.0",
|
|
55
|
+
"playwright-core": "^1.55.0",
|
|
56
|
+
"vitest": "workspace:*"
|
|
57
|
+
}
|
|
58
|
+
}
|