@vitest/browser 3.1.0-beta.1 → 3.1.0
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/context.d.ts +24 -1
- package/dist/client/.vite/manifest.json +1 -1
- package/dist/client/__vitest__/assets/index-B0KEk_KY.css +1 -0
- package/dist/client/__vitest__/assets/index-BLZJq7cG.js +52 -0
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/tester-DiLSqOx4.js +3431 -0
- package/dist/client/tester/tester.html +1 -1
- package/dist/client.js +109 -105
- package/dist/context.js +374 -390
- package/dist/expect-element.js +25 -0
- package/dist/index-DjDyxzt8.js +1 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +1991 -1887
- package/dist/locators/index.d.ts +64 -0
- package/dist/locators/index.js +1 -4
- package/dist/locators/playwright.js +1 -123
- package/dist/locators/preview.js +1 -85
- package/dist/locators/webdriverio.js +1 -157
- package/dist/providers.js +35 -37
- package/dist/public-utils-xf4CCUzp.js +6 -0
- package/dist/state.js +170 -1
- package/dist/utils.js +1 -3
- package/dist/webdriver-2iYWIzBv.js +403 -0
- package/jest-dom.d.ts +623 -712
- package/matchers.d.ts +4 -4
- package/package.json +14 -16
- package/dist/client/__vitest__/assets/index-Bne9c1R6.css +0 -1
- package/dist/client/__vitest__/assets/index-CsZqQx26.js +0 -52
- package/dist/client/__vitest_browser__/tester-lo_P6U-u.js +0 -15577
- package/dist/index-DrTP5i7N.js +0 -195
- package/dist/public-utils-J4vwTaki.js +0 -5561
- package/dist/utils-VCysLhWp.js +0 -115
- package/dist/webdriver-C5-VI7VH.js +0 -275
package/dist/locators/index.d.ts
CHANGED
|
@@ -155,6 +155,33 @@ declare class SelectorEvaluatorImpl implements SelectorEvaluator {
|
|
|
155
155
|
private _getEngine;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Copyright (c) Microsoft Corporation.
|
|
160
|
+
*
|
|
161
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
162
|
+
* you may not use this file except in compliance with the License.
|
|
163
|
+
* You may obtain a copy of the License at
|
|
164
|
+
*
|
|
165
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
166
|
+
*
|
|
167
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
168
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
169
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
170
|
+
* See the License for the specific language governing permissions and
|
|
171
|
+
* limitations under the License.
|
|
172
|
+
*/
|
|
173
|
+
interface ByRoleOptions {
|
|
174
|
+
checked?: boolean;
|
|
175
|
+
disabled?: boolean;
|
|
176
|
+
exact?: boolean;
|
|
177
|
+
expanded?: boolean;
|
|
178
|
+
includeHidden?: boolean;
|
|
179
|
+
level?: number;
|
|
180
|
+
name?: string | RegExp;
|
|
181
|
+
pressed?: boolean;
|
|
182
|
+
selected?: boolean;
|
|
183
|
+
}
|
|
184
|
+
|
|
158
185
|
/**
|
|
159
186
|
* Copyright (c) Microsoft Corporation.
|
|
160
187
|
*
|
|
@@ -191,6 +218,40 @@ declare class Ivya {
|
|
|
191
218
|
queryLocatorSelector(locator: string, root?: Node, strict?: boolean): Element | null;
|
|
192
219
|
queryLocatorSelectorAll(locator: string, root?: Node): Element[];
|
|
193
220
|
querySelector(selector: ParsedSelector, root: Node, strict?: boolean): Element | null;
|
|
221
|
+
queryAllByRole(text: string, options?: ByRoleOptions, container?: Node): Element[];
|
|
222
|
+
queryAllByLabelText(text: string | RegExp, options?: {
|
|
223
|
+
exact?: boolean;
|
|
224
|
+
}, container?: Node): Element[];
|
|
225
|
+
queryAllByTestId(text: string | RegExp, container?: Node): Element[];
|
|
226
|
+
queryAllByText(text: string | RegExp, options?: {
|
|
227
|
+
exact?: boolean;
|
|
228
|
+
}, container?: Node): Element[];
|
|
229
|
+
queryAllByTitle(text: string | RegExp, options?: {
|
|
230
|
+
exact?: boolean;
|
|
231
|
+
}, container?: Node): Element[];
|
|
232
|
+
queryAllByPlaceholder(text: string | RegExp, options?: {
|
|
233
|
+
exact?: boolean;
|
|
234
|
+
}, container?: Node): Element[];
|
|
235
|
+
queryAllByAltText(text: string | RegExp, options?: {
|
|
236
|
+
exact?: boolean;
|
|
237
|
+
}, container?: Node): Element[];
|
|
238
|
+
queryByRole(text: string, options?: ByRoleOptions, container?: Node): Element | null;
|
|
239
|
+
queryByLabelText(text: string | RegExp, options?: {
|
|
240
|
+
exact?: boolean;
|
|
241
|
+
}, container?: Node): Element | null;
|
|
242
|
+
queryByTestId(text: string | RegExp, container?: Node): Element | null;
|
|
243
|
+
queryByText(text: string | RegExp, options?: {
|
|
244
|
+
exact?: boolean;
|
|
245
|
+
}, container?: Node): Element | null;
|
|
246
|
+
queryByTitle(text: string | RegExp, options?: {
|
|
247
|
+
exact?: boolean;
|
|
248
|
+
}, container?: Node): Element | null;
|
|
249
|
+
queryByPlaceholder(text: string | RegExp, options?: {
|
|
250
|
+
exact?: boolean;
|
|
251
|
+
}, container?: Node): Element | null;
|
|
252
|
+
queryByAltText(text: string | RegExp, options?: {
|
|
253
|
+
exact?: boolean;
|
|
254
|
+
}, container?: Node): Element | null;
|
|
194
255
|
private strictModeViolationError;
|
|
195
256
|
generateSelectorSimple(targetElement: Element, options?: GenerateSelectorOptions): string;
|
|
196
257
|
parseSelector(selector: string): ParsedSelector;
|
|
@@ -249,6 +310,9 @@ declare abstract class Locator {
|
|
|
249
310
|
getByTestId(testId: string | RegExp): Locator;
|
|
250
311
|
getByText(text: string | RegExp, options?: LocatorOptions): Locator;
|
|
251
312
|
getByTitle(title: string | RegExp, options?: LocatorOptions): Locator;
|
|
313
|
+
filter(filter: LocatorOptions): Locator;
|
|
314
|
+
and(locator: Locator): Locator;
|
|
315
|
+
or(locator: Locator): Locator;
|
|
252
316
|
query(): Element | null;
|
|
253
317
|
element(): Element;
|
|
254
318
|
elements(): Element[];
|
package/dist/locators/index.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import '../public-utils-J4vwTaki.js';
|
|
3
|
-
export { L as Locator, s as selectorEngine } from '../index-DrTP5i7N.js';
|
|
4
|
-
import 'vitest/utils';
|
|
1
|
+
import"@vitest/browser/context";import"../public-utils-xf4CCUzp.js";export{L as Locator,s as selectorEngine}from"../index-DjDyxzt8.js";import"vitest/utils";
|
|
@@ -1,123 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { g as getByTitleSelector, a as getByTextSelector, b as getByPlaceholderSelector, c as getByAltTextSelector, d as getByTestIdSelector, e as getByRoleSelector, f as getByLabelSelector } from '../public-utils-J4vwTaki.js';
|
|
3
|
-
import { s as selectorEngine, L as Locator, g as getBrowserState } from '../index-DrTP5i7N.js';
|
|
4
|
-
import { p as processTimeoutOptions, g as getIframeScale } from '../utils-VCysLhWp.js';
|
|
5
|
-
import 'vitest/utils';
|
|
6
|
-
|
|
7
|
-
page.extend({
|
|
8
|
-
getByLabelText(text, options) {
|
|
9
|
-
return new PlaywrightLocator(getByLabelSelector(text, options));
|
|
10
|
-
},
|
|
11
|
-
getByRole(role, options) {
|
|
12
|
-
return new PlaywrightLocator(getByRoleSelector(role, options));
|
|
13
|
-
},
|
|
14
|
-
getByTestId(testId) {
|
|
15
|
-
return new PlaywrightLocator(getByTestIdSelector(server.config.browser.locators.testIdAttribute, testId));
|
|
16
|
-
},
|
|
17
|
-
getByAltText(text, options) {
|
|
18
|
-
return new PlaywrightLocator(getByAltTextSelector(text, options));
|
|
19
|
-
},
|
|
20
|
-
getByPlaceholder(text, options) {
|
|
21
|
-
return new PlaywrightLocator(getByPlaceholderSelector(text, options));
|
|
22
|
-
},
|
|
23
|
-
getByText(text, options) {
|
|
24
|
-
return new PlaywrightLocator(getByTextSelector(text, options));
|
|
25
|
-
},
|
|
26
|
-
getByTitle(title, options) {
|
|
27
|
-
return new PlaywrightLocator(getByTitleSelector(title, options));
|
|
28
|
-
},
|
|
29
|
-
elementLocator(element) {
|
|
30
|
-
return new PlaywrightLocator(
|
|
31
|
-
selectorEngine.generateSelectorSimple(element),
|
|
32
|
-
element
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
class PlaywrightLocator extends Locator {
|
|
37
|
-
constructor(selector, _container) {
|
|
38
|
-
super();
|
|
39
|
-
this.selector = selector;
|
|
40
|
-
this._container = _container;
|
|
41
|
-
}
|
|
42
|
-
click(options) {
|
|
43
|
-
return super.click(processTimeoutOptions(processClickOptions(options)));
|
|
44
|
-
}
|
|
45
|
-
dblClick(options) {
|
|
46
|
-
return super.dblClick(processTimeoutOptions(processClickOptions(options)));
|
|
47
|
-
}
|
|
48
|
-
tripleClick(options) {
|
|
49
|
-
return super.tripleClick(processTimeoutOptions(processClickOptions(options)));
|
|
50
|
-
}
|
|
51
|
-
selectOptions(value, options) {
|
|
52
|
-
return super.selectOptions(value, processTimeoutOptions(options));
|
|
53
|
-
}
|
|
54
|
-
clear(options) {
|
|
55
|
-
return super.clear(processTimeoutOptions(options));
|
|
56
|
-
}
|
|
57
|
-
hover(options) {
|
|
58
|
-
return super.hover(processTimeoutOptions(processHoverOptions(options)));
|
|
59
|
-
}
|
|
60
|
-
upload(files, options) {
|
|
61
|
-
return super.upload(files, processTimeoutOptions(options));
|
|
62
|
-
}
|
|
63
|
-
fill(text, options) {
|
|
64
|
-
return super.fill(text, processTimeoutOptions(options));
|
|
65
|
-
}
|
|
66
|
-
dropTo(target, options) {
|
|
67
|
-
return super.dropTo(target, processTimeoutOptions(
|
|
68
|
-
processDragAndDropOptions(options)
|
|
69
|
-
));
|
|
70
|
-
}
|
|
71
|
-
locator(selector) {
|
|
72
|
-
return new PlaywrightLocator(`${this.selector} >> ${selector}`, this._container);
|
|
73
|
-
}
|
|
74
|
-
elementLocator(element) {
|
|
75
|
-
return new PlaywrightLocator(
|
|
76
|
-
selectorEngine.generateSelectorSimple(element),
|
|
77
|
-
element
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function processDragAndDropOptions(options_) {
|
|
82
|
-
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
83
|
-
return options_;
|
|
84
|
-
}
|
|
85
|
-
const options = options_;
|
|
86
|
-
if (options.sourcePosition) {
|
|
87
|
-
options.sourcePosition = processPlaywrightPosition(options.sourcePosition);
|
|
88
|
-
}
|
|
89
|
-
if (options.targetPosition) {
|
|
90
|
-
options.targetPosition = processPlaywrightPosition(options.targetPosition);
|
|
91
|
-
}
|
|
92
|
-
return options_;
|
|
93
|
-
}
|
|
94
|
-
function processHoverOptions(options_) {
|
|
95
|
-
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
96
|
-
return options_;
|
|
97
|
-
}
|
|
98
|
-
const options = options_;
|
|
99
|
-
if (options.position) {
|
|
100
|
-
options.position = processPlaywrightPosition(options.position);
|
|
101
|
-
}
|
|
102
|
-
return options_;
|
|
103
|
-
}
|
|
104
|
-
function processClickOptions(options_) {
|
|
105
|
-
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
106
|
-
return options_;
|
|
107
|
-
}
|
|
108
|
-
const options = options_;
|
|
109
|
-
if (options.position) {
|
|
110
|
-
options.position = processPlaywrightPosition(options.position);
|
|
111
|
-
}
|
|
112
|
-
return options;
|
|
113
|
-
}
|
|
114
|
-
function processPlaywrightPosition(position) {
|
|
115
|
-
const scale = getIframeScale();
|
|
116
|
-
if (position.x != null) {
|
|
117
|
-
position.x *= scale;
|
|
118
|
-
}
|
|
119
|
-
if (position.y != null) {
|
|
120
|
-
position.y *= scale;
|
|
121
|
-
}
|
|
122
|
-
return position;
|
|
123
|
-
}
|
|
1
|
+
import{page,server}from"@vitest/browser/context";import{g as getByTitleSelector,a as getByTextSelector,b as getByPlaceholderSelector,c as getByAltTextSelector,d as getByTestIdSelector,e as getByRoleSelector,f as getByLabelSelector}from"../public-utils-xf4CCUzp.js";import{s as selectorEngine,L as Locator,p as processTimeoutOptions,g as getBrowserState,a as getIframeScale}from"../index-DjDyxzt8.js";import"vitest/utils";page.extend({getByLabelText(e,v){return new PlaywrightLocator(getByLabelSelector(e,v))},getByRole(e,v){return new PlaywrightLocator(getByRoleSelector(e,v))},getByTestId(e){return new PlaywrightLocator(getByTestIdSelector(server.config.browser.locators.testIdAttribute,e))},getByAltText(e,v){return new PlaywrightLocator(getByAltTextSelector(e,v))},getByPlaceholder(e,v){return new PlaywrightLocator(getByPlaceholderSelector(e,v))},getByText(e,v){return new PlaywrightLocator(getByTextSelector(e,v))},getByTitle(e,v){return new PlaywrightLocator(getByTitleSelector(e,v))},elementLocator(e){return new PlaywrightLocator(selectorEngine.generateSelectorSimple(e),e)}});class PlaywrightLocator extends Locator{constructor(e,v){super(),this.selector=e,this._container=v}click(e){return super.click(processTimeoutOptions(processClickOptions(e)))}dblClick(e){return super.dblClick(processTimeoutOptions(processClickOptions(e)))}tripleClick(e){return super.tripleClick(processTimeoutOptions(processClickOptions(e)))}selectOptions(e,v){return super.selectOptions(e,processTimeoutOptions(v))}clear(e){return super.clear(processTimeoutOptions(e))}hover(e){return super.hover(processTimeoutOptions(processHoverOptions(e)))}upload(e,v){return super.upload(e,processTimeoutOptions(v))}fill(e,v){return super.fill(e,processTimeoutOptions(v))}dropTo(e,v){return super.dropTo(e,processTimeoutOptions(processDragAndDropOptions(v)))}locator(e){return new PlaywrightLocator(`${this.selector} >> ${e}`,this._container)}elementLocator(e){return new PlaywrightLocator(selectorEngine.generateSelectorSimple(e),e)}}function processDragAndDropOptions(e){if(!e||!getBrowserState().config.browser.ui)return e;let v=e;return v.sourcePosition&&=processPlaywrightPosition(v.sourcePosition),v.targetPosition&&=processPlaywrightPosition(v.targetPosition),e}function processHoverOptions(e){if(!e||!getBrowserState().config.browser.ui)return e;let v=e;return v.position&&=processPlaywrightPosition(v.position),e}function processClickOptions(e){if(!e||!getBrowserState().config.browser.ui)return e;let v=e;return v.position&&=processPlaywrightPosition(v.position),v}function processPlaywrightPosition(e){let v=getIframeScale();return e.x!=null&&(e.x*=v),e.y!=null&&(e.y*=v),e}
|
package/dist/locators/preview.js
CHANGED
|
@@ -1,85 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { g as getByTitleSelector, a as getByTextSelector, b as getByPlaceholderSelector, c as getByAltTextSelector, d as getByTestIdSelector, e as getByRoleSelector, f as getByLabelSelector, h as getElementError } from '../public-utils-J4vwTaki.js';
|
|
3
|
-
import { c as convertElementToCssSelector } from '../utils-VCysLhWp.js';
|
|
4
|
-
import { s as selectorEngine, L as Locator } from '../index-DrTP5i7N.js';
|
|
5
|
-
import 'vitest/utils';
|
|
6
|
-
|
|
7
|
-
page.extend({
|
|
8
|
-
getByLabelText(text, options) {
|
|
9
|
-
return new PreviewLocator(getByLabelSelector(text, options));
|
|
10
|
-
},
|
|
11
|
-
getByRole(role, options) {
|
|
12
|
-
return new PreviewLocator(getByRoleSelector(role, options));
|
|
13
|
-
},
|
|
14
|
-
getByTestId(testId) {
|
|
15
|
-
return new PreviewLocator(getByTestIdSelector(server.config.browser.locators.testIdAttribute, testId));
|
|
16
|
-
},
|
|
17
|
-
getByAltText(text, options) {
|
|
18
|
-
return new PreviewLocator(getByAltTextSelector(text, options));
|
|
19
|
-
},
|
|
20
|
-
getByPlaceholder(text, options) {
|
|
21
|
-
return new PreviewLocator(getByPlaceholderSelector(text, options));
|
|
22
|
-
},
|
|
23
|
-
getByText(text, options) {
|
|
24
|
-
return new PreviewLocator(getByTextSelector(text, options));
|
|
25
|
-
},
|
|
26
|
-
getByTitle(title, options) {
|
|
27
|
-
return new PreviewLocator(getByTitleSelector(title, options));
|
|
28
|
-
},
|
|
29
|
-
elementLocator(element) {
|
|
30
|
-
return new PreviewLocator(
|
|
31
|
-
selectorEngine.generateSelectorSimple(element),
|
|
32
|
-
element
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
class PreviewLocator extends Locator {
|
|
37
|
-
constructor(_pwSelector, _container) {
|
|
38
|
-
super();
|
|
39
|
-
this._pwSelector = _pwSelector;
|
|
40
|
-
this._container = _container;
|
|
41
|
-
}
|
|
42
|
-
get selector() {
|
|
43
|
-
const selectors = this.elements().map((element) => convertElementToCssSelector(element));
|
|
44
|
-
if (!selectors.length) {
|
|
45
|
-
throw getElementError(this._pwSelector, this._container || document.body);
|
|
46
|
-
}
|
|
47
|
-
return selectors.join(", ");
|
|
48
|
-
}
|
|
49
|
-
click() {
|
|
50
|
-
return userEvent.click(this.element());
|
|
51
|
-
}
|
|
52
|
-
dblClick() {
|
|
53
|
-
return userEvent.dblClick(this.element());
|
|
54
|
-
}
|
|
55
|
-
tripleClick() {
|
|
56
|
-
return userEvent.tripleClick(this.element());
|
|
57
|
-
}
|
|
58
|
-
hover() {
|
|
59
|
-
return userEvent.hover(this.element());
|
|
60
|
-
}
|
|
61
|
-
unhover() {
|
|
62
|
-
return userEvent.unhover(this.element());
|
|
63
|
-
}
|
|
64
|
-
async fill(text) {
|
|
65
|
-
return userEvent.fill(this.element(), text);
|
|
66
|
-
}
|
|
67
|
-
async upload(file) {
|
|
68
|
-
return userEvent.upload(this.element(), file);
|
|
69
|
-
}
|
|
70
|
-
selectOptions(options_) {
|
|
71
|
-
return userEvent.selectOptions(this.element(), options_);
|
|
72
|
-
}
|
|
73
|
-
clear() {
|
|
74
|
-
return userEvent.clear(this.element());
|
|
75
|
-
}
|
|
76
|
-
locator(selector) {
|
|
77
|
-
return new PreviewLocator(`${this._pwSelector} >> ${selector}`, this._container);
|
|
78
|
-
}
|
|
79
|
-
elementLocator(element) {
|
|
80
|
-
return new PreviewLocator(
|
|
81
|
-
selectorEngine.generateSelectorSimple(element),
|
|
82
|
-
element
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
1
|
+
import{page,server,userEvent}from"@vitest/browser/context";import{g as getByTitleSelector,a as getByTextSelector,b as getByPlaceholderSelector,c as getByAltTextSelector,d as getByTestIdSelector,e as getByRoleSelector,f as getByLabelSelector,h as getElementError}from"../public-utils-xf4CCUzp.js";import{s as selectorEngine,L as Locator,c as convertElementToCssSelector}from"../index-DjDyxzt8.js";import"vitest/utils";page.extend({getByLabelText(e,m){return new PreviewLocator(getByLabelSelector(e,m))},getByRole(e,m){return new PreviewLocator(getByRoleSelector(e,m))},getByTestId(e){return new PreviewLocator(getByTestIdSelector(server.config.browser.locators.testIdAttribute,e))},getByAltText(e,m){return new PreviewLocator(getByAltTextSelector(e,m))},getByPlaceholder(e,m){return new PreviewLocator(getByPlaceholderSelector(e,m))},getByText(e,m){return new PreviewLocator(getByTextSelector(e,m))},getByTitle(e,m){return new PreviewLocator(getByTitleSelector(e,m))},elementLocator(e){return new PreviewLocator(selectorEngine.generateSelectorSimple(e),e)}});class PreviewLocator extends Locator{constructor(e,m){super(),this._pwSelector=e,this._container=m}get selector(){let e=this.elements().map(e=>convertElementToCssSelector(e));if(!e.length)throw getElementError(this._pwSelector,this._container||document.body);return e.join(`, `)}click(){return userEvent.click(this.element())}dblClick(){return userEvent.dblClick(this.element())}tripleClick(){return userEvent.tripleClick(this.element())}hover(){return userEvent.hover(this.element())}unhover(){return userEvent.unhover(this.element())}async fill(e){return userEvent.fill(this.element(),e)}async upload(e){return userEvent.upload(this.element(),e)}selectOptions(e){return userEvent.selectOptions(this.element(),e)}clear(){return userEvent.clear(this.element())}locator(e){return new PreviewLocator(`${this._pwSelector} >> ${e}`,this._container)}elementLocator(e){return new PreviewLocator(selectorEngine.generateSelectorSimple(e),e)}}
|
|
@@ -1,157 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { g as getByTitleSelector, a as getByTextSelector, b as getByPlaceholderSelector, c as getByAltTextSelector, d as getByTestIdSelector, e as getByRoleSelector, f as getByLabelSelector, h as getElementError } from '../public-utils-J4vwTaki.js';
|
|
3
|
-
import { s as selectorEngine, L as Locator, g as getBrowserState } from '../index-DrTP5i7N.js';
|
|
4
|
-
import { c as convertElementToCssSelector, g as getIframeScale } from '../utils-VCysLhWp.js';
|
|
5
|
-
import 'vitest/utils';
|
|
6
|
-
|
|
7
|
-
page.extend({
|
|
8
|
-
getByLabelText(text, options) {
|
|
9
|
-
return new WebdriverIOLocator(getByLabelSelector(text, options));
|
|
10
|
-
},
|
|
11
|
-
getByRole(role, options) {
|
|
12
|
-
return new WebdriverIOLocator(getByRoleSelector(role, options));
|
|
13
|
-
},
|
|
14
|
-
getByTestId(testId) {
|
|
15
|
-
return new WebdriverIOLocator(getByTestIdSelector(server.config.browser.locators.testIdAttribute, testId));
|
|
16
|
-
},
|
|
17
|
-
getByAltText(text, options) {
|
|
18
|
-
return new WebdriverIOLocator(getByAltTextSelector(text, options));
|
|
19
|
-
},
|
|
20
|
-
getByPlaceholder(text, options) {
|
|
21
|
-
return new WebdriverIOLocator(getByPlaceholderSelector(text, options));
|
|
22
|
-
},
|
|
23
|
-
getByText(text, options) {
|
|
24
|
-
return new WebdriverIOLocator(getByTextSelector(text, options));
|
|
25
|
-
},
|
|
26
|
-
getByTitle(title, options) {
|
|
27
|
-
return new WebdriverIOLocator(getByTitleSelector(title, options));
|
|
28
|
-
},
|
|
29
|
-
elementLocator(element) {
|
|
30
|
-
return new WebdriverIOLocator(selectorEngine.generateSelectorSimple(element));
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
class WebdriverIOLocator extends Locator {
|
|
34
|
-
constructor(_pwSelector, _container) {
|
|
35
|
-
super();
|
|
36
|
-
this._pwSelector = _pwSelector;
|
|
37
|
-
this._container = _container;
|
|
38
|
-
}
|
|
39
|
-
get selector() {
|
|
40
|
-
const selectors = this.elements().map((element) => convertElementToCssSelector(element));
|
|
41
|
-
if (!selectors.length) {
|
|
42
|
-
throw getElementError(this._pwSelector, this._container || document.body);
|
|
43
|
-
}
|
|
44
|
-
return selectors.join(", ");
|
|
45
|
-
}
|
|
46
|
-
click(options) {
|
|
47
|
-
return super.click(processClickOptions(options));
|
|
48
|
-
}
|
|
49
|
-
dblClick(options) {
|
|
50
|
-
return super.dblClick(processClickOptions(options));
|
|
51
|
-
}
|
|
52
|
-
tripleClick(options) {
|
|
53
|
-
return super.tripleClick(processClickOptions(options));
|
|
54
|
-
}
|
|
55
|
-
selectOptions(value, options) {
|
|
56
|
-
const values = getWebdriverioSelectOptions(this.element(), value);
|
|
57
|
-
return this.triggerCommand("__vitest_selectOptions", this.selector, values, options);
|
|
58
|
-
}
|
|
59
|
-
hover(options) {
|
|
60
|
-
return super.hover(processHoverOptions(options));
|
|
61
|
-
}
|
|
62
|
-
dropTo(target, options) {
|
|
63
|
-
return super.dropTo(target, processDragAndDropOptions(options));
|
|
64
|
-
}
|
|
65
|
-
locator(selector) {
|
|
66
|
-
return new WebdriverIOLocator(`${this._pwSelector} >> ${selector}`, this._container);
|
|
67
|
-
}
|
|
68
|
-
elementLocator(element) {
|
|
69
|
-
return new WebdriverIOLocator(selectorEngine.generateSelectorSimple(element), element);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function getWebdriverioSelectOptions(element, value) {
|
|
73
|
-
const options = [...element.querySelectorAll("option")];
|
|
74
|
-
const arrayValues = Array.isArray(value) ? value : [value];
|
|
75
|
-
if (!arrayValues.length) {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
if (arrayValues.length > 1) {
|
|
79
|
-
throw new Error(`Provider "webdriverio" doesn't support selecting multiple values at once`);
|
|
80
|
-
}
|
|
81
|
-
const optionValue = arrayValues[0];
|
|
82
|
-
if (typeof optionValue !== "string") {
|
|
83
|
-
const element2 = "element" in optionValue ? optionValue.element() : optionValue;
|
|
84
|
-
const index = options.indexOf(element2);
|
|
85
|
-
if (index === -1) {
|
|
86
|
-
throw new Error(`The element ${selectorEngine.previewNode(element2)} was not found in the "select" options.`);
|
|
87
|
-
}
|
|
88
|
-
return [{ index }];
|
|
89
|
-
}
|
|
90
|
-
const valueIndex = options.findIndex((option) => option.value === optionValue);
|
|
91
|
-
if (valueIndex !== -1) {
|
|
92
|
-
return [{ index: valueIndex }];
|
|
93
|
-
}
|
|
94
|
-
const labelIndex = options.findIndex(
|
|
95
|
-
(option) => option.textContent?.trim() === optionValue || option.ariaLabel === optionValue
|
|
96
|
-
);
|
|
97
|
-
if (labelIndex === -1) {
|
|
98
|
-
throw new Error(`The option "${optionValue}" was not found in the "select" options.`);
|
|
99
|
-
}
|
|
100
|
-
return [{ index: labelIndex }];
|
|
101
|
-
}
|
|
102
|
-
function processClickOptions(options_) {
|
|
103
|
-
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
104
|
-
return options_;
|
|
105
|
-
}
|
|
106
|
-
const options = options_;
|
|
107
|
-
if (options.x != null || options.y != null) {
|
|
108
|
-
const cache = {};
|
|
109
|
-
if (options.x != null) {
|
|
110
|
-
options.x = scaleCoordinate(options.x, cache);
|
|
111
|
-
}
|
|
112
|
-
if (options.y != null) {
|
|
113
|
-
options.y = scaleCoordinate(options.y, cache);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return options_;
|
|
117
|
-
}
|
|
118
|
-
function processHoverOptions(options_) {
|
|
119
|
-
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
120
|
-
return options_;
|
|
121
|
-
}
|
|
122
|
-
const options = options_;
|
|
123
|
-
const cache = {};
|
|
124
|
-
if (options.xOffset != null) {
|
|
125
|
-
options.xOffset = scaleCoordinate(options.xOffset, cache);
|
|
126
|
-
}
|
|
127
|
-
if (options.yOffset != null) {
|
|
128
|
-
options.yOffset = scaleCoordinate(options.yOffset, cache);
|
|
129
|
-
}
|
|
130
|
-
return options_;
|
|
131
|
-
}
|
|
132
|
-
function processDragAndDropOptions(options_) {
|
|
133
|
-
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
134
|
-
return options_;
|
|
135
|
-
}
|
|
136
|
-
const cache = {};
|
|
137
|
-
const options = options_;
|
|
138
|
-
if (options.sourceX != null) {
|
|
139
|
-
options.sourceX = scaleCoordinate(options.sourceX, cache);
|
|
140
|
-
}
|
|
141
|
-
if (options.sourceY != null) {
|
|
142
|
-
options.sourceY = scaleCoordinate(options.sourceY, cache);
|
|
143
|
-
}
|
|
144
|
-
if (options.targetX != null) {
|
|
145
|
-
options.targetX = scaleCoordinate(options.targetX, cache);
|
|
146
|
-
}
|
|
147
|
-
if (options.targetY != null) {
|
|
148
|
-
options.targetY = scaleCoordinate(options.targetY, cache);
|
|
149
|
-
}
|
|
150
|
-
return options_;
|
|
151
|
-
}
|
|
152
|
-
function scaleCoordinate(coordinate, cache) {
|
|
153
|
-
return Math.round(coordinate * getCachedScale(cache));
|
|
154
|
-
}
|
|
155
|
-
function getCachedScale(cache) {
|
|
156
|
-
return cache.scale ??= getIframeScale();
|
|
157
|
-
}
|
|
1
|
+
import{page,server}from"@vitest/browser/context";import{g as getByTitleSelector,a as getByTextSelector,b as getByPlaceholderSelector,c as getByAltTextSelector,d as getByTestIdSelector,e as getByRoleSelector,f as getByLabelSelector,h as getElementError}from"../public-utils-xf4CCUzp.js";import{s as selectorEngine,L as Locator,c as convertElementToCssSelector,g as getBrowserState,a as getIframeScale}from"../index-DjDyxzt8.js";import"vitest/utils";page.extend({getByLabelText(e,g){return new WebdriverIOLocator(getByLabelSelector(e,g))},getByRole(e,g){return new WebdriverIOLocator(getByRoleSelector(e,g))},getByTestId(e){return new WebdriverIOLocator(getByTestIdSelector(server.config.browser.locators.testIdAttribute,e))},getByAltText(e,g){return new WebdriverIOLocator(getByAltTextSelector(e,g))},getByPlaceholder(e,g){return new WebdriverIOLocator(getByPlaceholderSelector(e,g))},getByText(e,g){return new WebdriverIOLocator(getByTextSelector(e,g))},getByTitle(e,g){return new WebdriverIOLocator(getByTitleSelector(e,g))},elementLocator(e){return new WebdriverIOLocator(selectorEngine.generateSelectorSimple(e))}});class WebdriverIOLocator extends Locator{constructor(e,g){super(),this._pwSelector=e,this._container=g}get selector(){let e=this.elements().map(e=>convertElementToCssSelector(e));if(!e.length)throw getElementError(this._pwSelector,this._container||document.body);return e.join(`, `)}click(e){return super.click(processClickOptions(e))}dblClick(e){return super.dblClick(processClickOptions(e))}tripleClick(e){return super.tripleClick(processClickOptions(e))}selectOptions(e,g){let _=getWebdriverioSelectOptions(this.element(),e);return this.triggerCommand(`__vitest_selectOptions`,this.selector,_,g)}hover(e){return super.hover(processHoverOptions(e))}dropTo(e,g){return super.dropTo(e,processDragAndDropOptions(g))}locator(e){return new WebdriverIOLocator(`${this._pwSelector} >> ${e}`,this._container)}elementLocator(e){return new WebdriverIOLocator(selectorEngine.generateSelectorSimple(e),e)}}function getWebdriverioSelectOptions(e,g){let _=[...e.querySelectorAll(`option`)],v=Array.isArray(g)?g:[g];if(!v.length)return[];if(v.length>1)throw Error(`Provider "webdriverio" doesn't support selecting multiple values at once`);let y=v[0];if(typeof y!=`string`){let e=`element`in y?y.element():y,g=_.indexOf(e);if(g===-1)throw Error(`The element ${selectorEngine.previewNode(e)} was not found in the "select" options.`);return[{index:g}]}let b=_.findIndex(e=>e.value===y);if(b!==-1)return[{index:b}];let x=_.findIndex(e=>e.textContent?.trim()===y||e.ariaLabel===y);if(x===-1)throw Error(`The option "${y}" was not found in the "select" options.`);return[{index:x}]}function processClickOptions(e){if(!e||!getBrowserState().config.browser.ui)return e;let g=e;if(g.x!=null||g.y!=null){let e={};g.x!=null&&(g.x=scaleCoordinate(g.x,e)),g.y!=null&&(g.y=scaleCoordinate(g.y,e))}return e}function processHoverOptions(e){if(!e||!getBrowserState().config.browser.ui)return e;let g=e,_={};return g.xOffset!=null&&(g.xOffset=scaleCoordinate(g.xOffset,_)),g.yOffset!=null&&(g.yOffset=scaleCoordinate(g.yOffset,_)),e}function processDragAndDropOptions(e){if(!e||!getBrowserState().config.browser.ui)return e;let g={},_=e;return _.sourceX!=null&&(_.sourceX=scaleCoordinate(_.sourceX,g)),_.sourceY!=null&&(_.sourceY=scaleCoordinate(_.sourceY,g)),_.targetX!=null&&(_.targetX=scaleCoordinate(_.targetX,g)),_.targetY!=null&&(_.targetY=scaleCoordinate(_.targetY,g)),e}function scaleCoordinate(e,g){return Math.round(e*getCachedScale(g))}function getCachedScale(e){return e.scale??=getIframeScale()}
|
package/dist/providers.js
CHANGED
|
@@ -1,42 +1,40 @@
|
|
|
1
|
-
import { W as WebdriverBrowserProvider, P as PlaywrightBrowserProvider } from './webdriver-
|
|
1
|
+
import { W as WebdriverBrowserProvider, P as PlaywrightBrowserProvider } from './webdriver-2iYWIzBv.js';
|
|
2
|
+
import '@vitest/mocker/node';
|
|
2
3
|
|
|
3
4
|
class PreviewBrowserProvider {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
async close() {
|
|
39
|
-
}
|
|
5
|
+
name = "preview";
|
|
6
|
+
supportsParallelism = false;
|
|
7
|
+
project;
|
|
8
|
+
open = false;
|
|
9
|
+
getSupportedBrowsers() {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
isOpen() {
|
|
13
|
+
return this.open;
|
|
14
|
+
}
|
|
15
|
+
getCommandsContext() {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
async initialize(project) {
|
|
19
|
+
this.project = project;
|
|
20
|
+
this.open = false;
|
|
21
|
+
if (project.config.browser.headless) {
|
|
22
|
+
throw new Error("You've enabled headless mode for \"preview\" provider but it doesn't support it. Use \"playwright\" or \"webdriverio\" instead: https://vitest.dev/guide/browser/#configuration");
|
|
23
|
+
}
|
|
24
|
+
project.vitest.logger.printBrowserBanner(project);
|
|
25
|
+
}
|
|
26
|
+
async openPage(_sessionId, url) {
|
|
27
|
+
this.open = true;
|
|
28
|
+
if (!this.project.browser) {
|
|
29
|
+
throw new Error("Browser is not initialized");
|
|
30
|
+
}
|
|
31
|
+
const options = this.project.browser.vite.config.server;
|
|
32
|
+
const _open = options.open;
|
|
33
|
+
options.open = url;
|
|
34
|
+
this.project.browser.vite.openBrowser();
|
|
35
|
+
options.open = _open;
|
|
36
|
+
}
|
|
37
|
+
async close() {}
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
const webdriverio = WebdriverBrowserProvider;
|