@vitest/browser 3.1.0-beta.1 → 3.1.0-beta.2
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 +22 -0
- package/dist/client/.vite/manifest.json +1 -1
- package/dist/client/__vitest__/assets/{index-CsZqQx26.js → index-C3wX9Cb1.js} +1 -1
- package/dist/client/__vitest__/index.html +1 -1
- package/dist/client/__vitest_browser__/{tester-lo_P6U-u.js → tester-DRF-LncV.js} +1112 -324
- package/dist/client/tester/tester.html +1 -1
- package/dist/client.js +91 -105
- package/dist/context.js +374 -390
- package/dist/index-VvsEiykv.js +327 -0
- package/dist/index.js +1914 -1885
- package/dist/locators/index.d.ts +3 -0
- package/dist/locators/index.js +2 -2
- package/dist/locators/playwright.js +99 -108
- package/dist/locators/preview.js +71 -78
- package/dist/locators/webdriverio.js +135 -138
- package/dist/providers.js +34 -37
- package/dist/{public-utils-J4vwTaki.js → public-utils-4WiYB3_6.js} +38 -40
- package/dist/state.js +170 -1
- package/dist/utils.js +1 -1
- package/dist/webdriver-BP2w_ajA.js +271 -0
- package/package.json +8 -8
- package/dist/index-DrTP5i7N.js +0 -195
- package/dist/utils-VCysLhWp.js +0 -115
- package/dist/webdriver-C5-VI7VH.js +0 -275
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
const playwrightBrowsers = [
|
|
2
|
+
"firefox",
|
|
3
|
+
"webkit",
|
|
4
|
+
"chromium"
|
|
5
|
+
];
|
|
6
|
+
class PlaywrightBrowserProvider {
|
|
7
|
+
name = "playwright";
|
|
8
|
+
supportsParallelism = true;
|
|
9
|
+
browser = null;
|
|
10
|
+
browserName;
|
|
11
|
+
project;
|
|
12
|
+
options;
|
|
13
|
+
contexts = new Map();
|
|
14
|
+
pages = new Map();
|
|
15
|
+
browserPromise = null;
|
|
16
|
+
getSupportedBrowsers() {
|
|
17
|
+
return playwrightBrowsers;
|
|
18
|
+
}
|
|
19
|
+
initialize(project, { browser, options }) {
|
|
20
|
+
this.project = project;
|
|
21
|
+
this.browserName = browser;
|
|
22
|
+
this.options = options;
|
|
23
|
+
}
|
|
24
|
+
async openBrowser() {
|
|
25
|
+
if (this.browserPromise) {
|
|
26
|
+
return this.browserPromise;
|
|
27
|
+
}
|
|
28
|
+
if (this.browser) {
|
|
29
|
+
return this.browser;
|
|
30
|
+
}
|
|
31
|
+
this.browserPromise = (async () => {
|
|
32
|
+
const options = this.project.config.browser;
|
|
33
|
+
const playwright = await import('playwright');
|
|
34
|
+
const launchOptions = {
|
|
35
|
+
...this.options?.launch,
|
|
36
|
+
headless: options.headless
|
|
37
|
+
};
|
|
38
|
+
if (this.project.config.inspector.enabled) {
|
|
39
|
+
const port = this.project.config.inspector.port || 9229;
|
|
40
|
+
const host = this.project.config.inspector.host || "127.0.0.1";
|
|
41
|
+
launchOptions.args ||= [];
|
|
42
|
+
launchOptions.args.push(`--remote-debugging-port=${port}`);
|
|
43
|
+
launchOptions.args.push(`--remote-debugging-address=${host}`);
|
|
44
|
+
this.project.vitest.logger.log(`Debugger listening on ws://${host}:${port}`);
|
|
45
|
+
}
|
|
46
|
+
if (this.project.config.browser.ui && this.browserName === "chromium") {
|
|
47
|
+
if (!launchOptions.args) {
|
|
48
|
+
launchOptions.args = [];
|
|
49
|
+
}
|
|
50
|
+
if (!launchOptions.args.includes("--start-maximized") && !launchOptions.args.includes("--start-fullscreen")) {
|
|
51
|
+
launchOptions.args.push("--start-maximized");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const browser = await playwright[this.browserName].launch(launchOptions);
|
|
55
|
+
this.browser = browser;
|
|
56
|
+
this.browserPromise = null;
|
|
57
|
+
return this.browser;
|
|
58
|
+
})();
|
|
59
|
+
return this.browserPromise;
|
|
60
|
+
}
|
|
61
|
+
async createContext(sessionId) {
|
|
62
|
+
if (this.contexts.has(sessionId)) {
|
|
63
|
+
return this.contexts.get(sessionId);
|
|
64
|
+
}
|
|
65
|
+
const browser = await this.openBrowser();
|
|
66
|
+
const { actionTimeout,...contextOptions } = this.options?.context ?? {};
|
|
67
|
+
const options = {
|
|
68
|
+
...contextOptions,
|
|
69
|
+
ignoreHTTPSErrors: true,
|
|
70
|
+
serviceWorkers: "allow"
|
|
71
|
+
};
|
|
72
|
+
if (this.project.config.browser.ui) {
|
|
73
|
+
options.viewport = null;
|
|
74
|
+
}
|
|
75
|
+
const context = await browser.newContext(options);
|
|
76
|
+
if (actionTimeout) {
|
|
77
|
+
context.setDefaultTimeout(actionTimeout);
|
|
78
|
+
}
|
|
79
|
+
this.contexts.set(sessionId, context);
|
|
80
|
+
return context;
|
|
81
|
+
}
|
|
82
|
+
getPage(sessionId) {
|
|
83
|
+
const page = this.pages.get(sessionId);
|
|
84
|
+
if (!page) {
|
|
85
|
+
throw new Error(`Page "${sessionId}" not found in ${this.browserName} browser.`);
|
|
86
|
+
}
|
|
87
|
+
return page;
|
|
88
|
+
}
|
|
89
|
+
getCommandsContext(sessionId) {
|
|
90
|
+
const page = this.getPage(sessionId);
|
|
91
|
+
return {
|
|
92
|
+
page,
|
|
93
|
+
context: this.contexts.get(sessionId),
|
|
94
|
+
frame() {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
const frame = page.frame("vitest-iframe");
|
|
97
|
+
if (frame) {
|
|
98
|
+
return resolve(frame);
|
|
99
|
+
}
|
|
100
|
+
const timeout = setTimeout(() => {
|
|
101
|
+
const err = new Error(`Cannot find "vitest-iframe" on the page. This is a bug in Vitest, please report it.`);
|
|
102
|
+
reject(err);
|
|
103
|
+
}, 1e3);
|
|
104
|
+
page.on("frameattached", (frame) => {
|
|
105
|
+
clearTimeout(timeout);
|
|
106
|
+
resolve(frame);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
get iframe() {
|
|
111
|
+
return page.frameLocator("[data-vitest=\"true\"]");
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async openBrowserPage(sessionId) {
|
|
116
|
+
if (this.pages.has(sessionId)) {
|
|
117
|
+
const page = this.pages.get(sessionId);
|
|
118
|
+
await page.close();
|
|
119
|
+
this.pages.delete(sessionId);
|
|
120
|
+
}
|
|
121
|
+
const context = await this.createContext(sessionId);
|
|
122
|
+
const page = await context.newPage();
|
|
123
|
+
this.pages.set(sessionId, page);
|
|
124
|
+
if (process.env.VITEST_PW_DEBUG) {
|
|
125
|
+
page.on("requestfailed", (request) => {
|
|
126
|
+
console.error("[PW Error]", request.resourceType(), "request failed for", request.url(), "url:", request.failure()?.errorText);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
page.on("crash", () => {
|
|
130
|
+
const session = this.project.vitest._browserSessions.getSession(sessionId);
|
|
131
|
+
session?.reject(new Error("Page crashed when executing tests"));
|
|
132
|
+
});
|
|
133
|
+
return page;
|
|
134
|
+
}
|
|
135
|
+
async openPage(sessionId, url, beforeNavigate) {
|
|
136
|
+
const browserPage = await this.openBrowserPage(sessionId);
|
|
137
|
+
await beforeNavigate?.();
|
|
138
|
+
await browserPage.goto(url, { timeout: 0 });
|
|
139
|
+
}
|
|
140
|
+
async getCDPSession(sessionid) {
|
|
141
|
+
const page = this.getPage(sessionid);
|
|
142
|
+
const cdp = await page.context().newCDPSession(page);
|
|
143
|
+
return {
|
|
144
|
+
async send(method, params) {
|
|
145
|
+
const result = await cdp.send(method, params);
|
|
146
|
+
return result;
|
|
147
|
+
},
|
|
148
|
+
on(event, listener) {
|
|
149
|
+
cdp.on(event, listener);
|
|
150
|
+
},
|
|
151
|
+
off(event, listener) {
|
|
152
|
+
cdp.off(event, listener);
|
|
153
|
+
},
|
|
154
|
+
once(event, listener) {
|
|
155
|
+
cdp.once(event, listener);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
async close() {
|
|
160
|
+
const browser = this.browser;
|
|
161
|
+
this.browser = null;
|
|
162
|
+
await Promise.all([...this.pages.values()].map((p) => p.close()));
|
|
163
|
+
this.pages.clear();
|
|
164
|
+
await Promise.all([...this.contexts.values()].map((c) => c.close()));
|
|
165
|
+
this.contexts.clear();
|
|
166
|
+
await browser?.close();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const webdriverBrowsers = [
|
|
171
|
+
"firefox",
|
|
172
|
+
"chrome",
|
|
173
|
+
"edge",
|
|
174
|
+
"safari"
|
|
175
|
+
];
|
|
176
|
+
class WebdriverBrowserProvider {
|
|
177
|
+
name = "webdriverio";
|
|
178
|
+
supportsParallelism = false;
|
|
179
|
+
browser = null;
|
|
180
|
+
browserName;
|
|
181
|
+
project;
|
|
182
|
+
options;
|
|
183
|
+
getSupportedBrowsers() {
|
|
184
|
+
return webdriverBrowsers;
|
|
185
|
+
}
|
|
186
|
+
async initialize(ctx, { browser, options }) {
|
|
187
|
+
this.project = ctx;
|
|
188
|
+
this.browserName = browser;
|
|
189
|
+
this.options = options;
|
|
190
|
+
}
|
|
191
|
+
async switchToTestFrame() {
|
|
192
|
+
const page = this.browser;
|
|
193
|
+
if (page.switchFrame) {
|
|
194
|
+
await page.switchFrame(page.$("iframe[data-vitest]"));
|
|
195
|
+
} else {
|
|
196
|
+
const iframe = await page.findElement("css selector", "iframe[data-vitest]");
|
|
197
|
+
await page.switchToFrame(iframe);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async switchToMainFrame() {
|
|
201
|
+
const page = this.browser;
|
|
202
|
+
if (page.switchFrame) {
|
|
203
|
+
await page.switchFrame(null);
|
|
204
|
+
} else {
|
|
205
|
+
await page.switchToParentFrame();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
getCommandsContext() {
|
|
209
|
+
return { browser: this.browser };
|
|
210
|
+
}
|
|
211
|
+
async openBrowser() {
|
|
212
|
+
if (this.browser) {
|
|
213
|
+
return this.browser;
|
|
214
|
+
}
|
|
215
|
+
const options = this.project.config.browser;
|
|
216
|
+
if (this.browserName === "safari") {
|
|
217
|
+
if (options.headless) {
|
|
218
|
+
throw new Error("You've enabled headless mode for Safari but it doesn't currently support it.");
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const { remote } = await import('webdriverio');
|
|
222
|
+
this.browser = await remote({
|
|
223
|
+
...this.options,
|
|
224
|
+
logLevel: "error",
|
|
225
|
+
capabilities: this.buildCapabilities()
|
|
226
|
+
});
|
|
227
|
+
return this.browser;
|
|
228
|
+
}
|
|
229
|
+
buildCapabilities() {
|
|
230
|
+
const capabilities = {
|
|
231
|
+
...this.options?.capabilities,
|
|
232
|
+
browserName: this.browserName
|
|
233
|
+
};
|
|
234
|
+
const headlessMap = {
|
|
235
|
+
chrome: ["goog:chromeOptions", ["headless", "disable-gpu"]],
|
|
236
|
+
firefox: ["moz:firefoxOptions", ["-headless"]],
|
|
237
|
+
edge: ["ms:edgeOptions", ["--headless"]]
|
|
238
|
+
};
|
|
239
|
+
const options = this.project.config.browser;
|
|
240
|
+
const browser = this.browserName;
|
|
241
|
+
if (browser !== "safari" && options.headless) {
|
|
242
|
+
const [key, args] = headlessMap[browser];
|
|
243
|
+
const currentValues = (this.options?.capabilities)?.[key] || {};
|
|
244
|
+
const newArgs = [...currentValues.args || [], ...args];
|
|
245
|
+
capabilities[key] = {
|
|
246
|
+
...currentValues,
|
|
247
|
+
args: newArgs
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if (options.ui && (browser === "chrome" || browser === "edge")) {
|
|
251
|
+
const key = browser === "chrome" ? "goog:chromeOptions" : "ms:edgeOptions";
|
|
252
|
+
const args = capabilities[key]?.args || [];
|
|
253
|
+
if (!args.includes("--start-maximized") && !args.includes("--start-fullscreen")) {
|
|
254
|
+
args.push("--start-maximized");
|
|
255
|
+
}
|
|
256
|
+
capabilities[key] ??= {};
|
|
257
|
+
capabilities[key].args = args;
|
|
258
|
+
}
|
|
259
|
+
return capabilities;
|
|
260
|
+
}
|
|
261
|
+
async openPage(_sessionId, url) {
|
|
262
|
+
const browserInstance = await this.openBrowser();
|
|
263
|
+
await browserInstance.url(url);
|
|
264
|
+
}
|
|
265
|
+
async close() {
|
|
266
|
+
await Promise.all([this.browser?.sessionId ? this.browser?.deleteSession?.() : null]);
|
|
267
|
+
process.exit();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export { PlaywrightBrowserProvider as P, WebdriverBrowserProvider as W };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.1.0-beta.
|
|
4
|
+
"version": "3.1.0-beta.2",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"playwright": "*",
|
|
68
68
|
"webdriverio": "^7.0.0 || ^8.0.0 || ^9.0.0",
|
|
69
|
-
"vitest": "3.1.0-beta.
|
|
69
|
+
"vitest": "3.1.0-beta.2"
|
|
70
70
|
},
|
|
71
71
|
"peerDependenciesMeta": {
|
|
72
72
|
"playwright": {
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"sirv": "^3.0.1",
|
|
88
88
|
"tinyrainbow": "^2.0.0",
|
|
89
89
|
"ws": "^8.18.1",
|
|
90
|
-
"@vitest/mocker": "3.1.0-beta.
|
|
91
|
-
"@vitest/utils": "3.1.0-beta.
|
|
90
|
+
"@vitest/mocker": "3.1.0-beta.2",
|
|
91
|
+
"@vitest/utils": "3.1.0-beta.2"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
94
|
"@testing-library/jest-dom": "^6.6.3",
|
|
@@ -105,10 +105,10 @@
|
|
|
105
105
|
"playwright-core": "^1.50.1",
|
|
106
106
|
"safaridriver": "^1.0.0",
|
|
107
107
|
"webdriverio": "^9.10.0",
|
|
108
|
-
"@vitest/runner": "3.1.0-beta.
|
|
109
|
-
"@vitest/
|
|
110
|
-
"
|
|
111
|
-
"vitest": "3.1.0-beta.
|
|
108
|
+
"@vitest/runner": "3.1.0-beta.2",
|
|
109
|
+
"@vitest/ui": "3.1.0-beta.2",
|
|
110
|
+
"vitest": "3.1.0-beta.2",
|
|
111
|
+
"@vitest/ws-client": "3.1.0-beta.2"
|
|
112
112
|
},
|
|
113
113
|
"scripts": {
|
|
114
114
|
"build": "rimraf dist && pnpm build:node && pnpm build:client",
|
package/dist/index-DrTP5i7N.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { server, page } from '@vitest/browser/context';
|
|
2
|
-
import { I as Ivya, e as getByRoleSelector, c as getByAltTextSelector, f as getByLabelSelector, b as getByPlaceholderSelector, d as getByTestIdSelector, a as getByTextSelector, g as getByTitleSelector, h as getElementError } from './public-utils-J4vwTaki.js';
|
|
3
|
-
|
|
4
|
-
function ensureAwaited(promise) {
|
|
5
|
-
const test = (/* @__PURE__ */ getWorkerState()).current;
|
|
6
|
-
if (!test || test.type !== "test") {
|
|
7
|
-
return promise();
|
|
8
|
-
}
|
|
9
|
-
let awaited = false;
|
|
10
|
-
const sourceError = new Error("STACK_TRACE_ERROR");
|
|
11
|
-
test.onFinished ??= [];
|
|
12
|
-
test.onFinished.push(() => {
|
|
13
|
-
if (!awaited) {
|
|
14
|
-
const error = new Error(
|
|
15
|
-
`The call was not awaited. This method is asynchronous and must be awaited; otherwise, the call will not start to avoid unhandled rejections.`
|
|
16
|
-
);
|
|
17
|
-
error.stack = sourceError.stack?.replace(sourceError.message, error.message);
|
|
18
|
-
throw error;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
let promiseResult;
|
|
22
|
-
return {
|
|
23
|
-
then(onFulfilled, onRejected) {
|
|
24
|
-
awaited = true;
|
|
25
|
-
return (promiseResult ||= promise(sourceError)).then(onFulfilled, onRejected);
|
|
26
|
-
},
|
|
27
|
-
catch(onRejected) {
|
|
28
|
-
return (promiseResult ||= promise(sourceError)).catch(onRejected);
|
|
29
|
-
},
|
|
30
|
-
finally(onFinally) {
|
|
31
|
-
return (promiseResult ||= promise(sourceError)).finally(onFinally);
|
|
32
|
-
},
|
|
33
|
-
[Symbol.toStringTag]: "Promise"
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
// @__NO_SIDE_EFFECTS__
|
|
37
|
-
function getBrowserState() {
|
|
38
|
-
return window.__vitest_browser_runner__;
|
|
39
|
-
}
|
|
40
|
-
// @__NO_SIDE_EFFECTS__
|
|
41
|
-
function getWorkerState() {
|
|
42
|
-
const state = window.__vitest_worker__;
|
|
43
|
-
if (!state) {
|
|
44
|
-
throw new Error("Worker state is not found. This is an issue with Vitest. Please, open an issue.");
|
|
45
|
-
}
|
|
46
|
-
return state;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const selectorEngine = Ivya.create({
|
|
50
|
-
browser: ((name) => {
|
|
51
|
-
switch (name) {
|
|
52
|
-
case "edge":
|
|
53
|
-
case "chrome":
|
|
54
|
-
return "chromium";
|
|
55
|
-
case "safari":
|
|
56
|
-
return "webkit";
|
|
57
|
-
default:
|
|
58
|
-
return name;
|
|
59
|
-
}
|
|
60
|
-
})(server.config.browser.name),
|
|
61
|
-
testIdAttribute: server.config.browser.locators.testIdAttribute
|
|
62
|
-
});
|
|
63
|
-
class Locator {
|
|
64
|
-
_parsedSelector;
|
|
65
|
-
_container;
|
|
66
|
-
_pwSelector;
|
|
67
|
-
click(options = {}) {
|
|
68
|
-
return this.triggerCommand("__vitest_click", this.selector, options);
|
|
69
|
-
}
|
|
70
|
-
dblClick(options = {}) {
|
|
71
|
-
return this.triggerCommand("__vitest_dblClick", this.selector, options);
|
|
72
|
-
}
|
|
73
|
-
tripleClick(options = {}) {
|
|
74
|
-
return this.triggerCommand("__vitest_tripleClick", this.selector, options);
|
|
75
|
-
}
|
|
76
|
-
clear(options) {
|
|
77
|
-
return this.triggerCommand("__vitest_clear", this.selector, options);
|
|
78
|
-
}
|
|
79
|
-
hover(options) {
|
|
80
|
-
return this.triggerCommand("__vitest_hover", this.selector, options);
|
|
81
|
-
}
|
|
82
|
-
unhover(options) {
|
|
83
|
-
return this.triggerCommand("__vitest_hover", "html > body", options);
|
|
84
|
-
}
|
|
85
|
-
fill(text, options) {
|
|
86
|
-
return this.triggerCommand("__vitest_fill", this.selector, text, options);
|
|
87
|
-
}
|
|
88
|
-
async upload(files, options) {
|
|
89
|
-
const filesPromise = (Array.isArray(files) ? files : [files]).map(async (file) => {
|
|
90
|
-
if (typeof file === "string") {
|
|
91
|
-
return file;
|
|
92
|
-
}
|
|
93
|
-
const bas64String = await new Promise((resolve, reject) => {
|
|
94
|
-
const reader = new FileReader();
|
|
95
|
-
reader.onload = () => resolve(reader.result);
|
|
96
|
-
reader.onerror = () => reject(new Error(`Failed to read file: ${file.name}`));
|
|
97
|
-
reader.readAsDataURL(file);
|
|
98
|
-
});
|
|
99
|
-
return {
|
|
100
|
-
name: file.name,
|
|
101
|
-
mimeType: file.type,
|
|
102
|
-
base64: bas64String
|
|
103
|
-
};
|
|
104
|
-
});
|
|
105
|
-
return this.triggerCommand("__vitest_upload", this.selector, await Promise.all(filesPromise), options);
|
|
106
|
-
}
|
|
107
|
-
dropTo(target, options = {}) {
|
|
108
|
-
return this.triggerCommand(
|
|
109
|
-
"__vitest_dragAndDrop",
|
|
110
|
-
this.selector,
|
|
111
|
-
target.selector,
|
|
112
|
-
options
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
selectOptions(value, options) {
|
|
116
|
-
const values = (Array.isArray(value) ? value : [value]).map((v) => {
|
|
117
|
-
if (typeof v !== "string") {
|
|
118
|
-
const selector = "element" in v ? v.selector : selectorEngine.generateSelectorSimple(v);
|
|
119
|
-
return { element: selector };
|
|
120
|
-
}
|
|
121
|
-
return v;
|
|
122
|
-
});
|
|
123
|
-
return this.triggerCommand("__vitest_selectOptions", this.selector, values, options);
|
|
124
|
-
}
|
|
125
|
-
screenshot(options) {
|
|
126
|
-
return page.screenshot({
|
|
127
|
-
...options,
|
|
128
|
-
element: this
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
getByRole(role, options) {
|
|
132
|
-
return this.locator(getByRoleSelector(role, options));
|
|
133
|
-
}
|
|
134
|
-
getByAltText(text, options) {
|
|
135
|
-
return this.locator(getByAltTextSelector(text, options));
|
|
136
|
-
}
|
|
137
|
-
getByLabelText(text, options) {
|
|
138
|
-
return this.locator(getByLabelSelector(text, options));
|
|
139
|
-
}
|
|
140
|
-
getByPlaceholder(text, options) {
|
|
141
|
-
return this.locator(getByPlaceholderSelector(text, options));
|
|
142
|
-
}
|
|
143
|
-
getByTestId(testId) {
|
|
144
|
-
return this.locator(getByTestIdSelector(server.config.browser.locators.testIdAttribute, testId));
|
|
145
|
-
}
|
|
146
|
-
getByText(text, options) {
|
|
147
|
-
return this.locator(getByTextSelector(text, options));
|
|
148
|
-
}
|
|
149
|
-
getByTitle(title, options) {
|
|
150
|
-
return this.locator(getByTitleSelector(title, options));
|
|
151
|
-
}
|
|
152
|
-
query() {
|
|
153
|
-
const parsedSelector = this._parsedSelector || (this._parsedSelector = selectorEngine.parseSelector(this._pwSelector || this.selector));
|
|
154
|
-
return selectorEngine.querySelector(parsedSelector, document.documentElement, true);
|
|
155
|
-
}
|
|
156
|
-
element() {
|
|
157
|
-
const element = this.query();
|
|
158
|
-
if (!element) {
|
|
159
|
-
throw getElementError(this._pwSelector || this.selector, this._container || document.body);
|
|
160
|
-
}
|
|
161
|
-
return element;
|
|
162
|
-
}
|
|
163
|
-
elements() {
|
|
164
|
-
const parsedSelector = this._parsedSelector || (this._parsedSelector = selectorEngine.parseSelector(this._pwSelector || this.selector));
|
|
165
|
-
return selectorEngine.querySelectorAll(parsedSelector, document.documentElement);
|
|
166
|
-
}
|
|
167
|
-
all() {
|
|
168
|
-
return this.elements().map((element) => this.elementLocator(element));
|
|
169
|
-
}
|
|
170
|
-
nth(index) {
|
|
171
|
-
return this.locator(`nth=${index}`);
|
|
172
|
-
}
|
|
173
|
-
first() {
|
|
174
|
-
return this.nth(0);
|
|
175
|
-
}
|
|
176
|
-
last() {
|
|
177
|
-
return this.nth(-1);
|
|
178
|
-
}
|
|
179
|
-
toString() {
|
|
180
|
-
return this.selector;
|
|
181
|
-
}
|
|
182
|
-
toJSON() {
|
|
183
|
-
return this.selector;
|
|
184
|
-
}
|
|
185
|
-
triggerCommand(command, ...args) {
|
|
186
|
-
const commands = getBrowserState().commands;
|
|
187
|
-
return ensureAwaited((error) => commands.triggerCommand(
|
|
188
|
-
command,
|
|
189
|
-
args,
|
|
190
|
-
error
|
|
191
|
-
));
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export { Locator as L, getWorkerState as a, getBrowserState as g, selectorEngine as s };
|
package/dist/utils-VCysLhWp.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { g as getBrowserState, a as getWorkerState } from './index-DrTP5i7N.js';
|
|
2
|
-
|
|
3
|
-
const provider = getBrowserState().provider;
|
|
4
|
-
// @__NO_SIDE_EFFECTS__
|
|
5
|
-
function convertElementToCssSelector(element) {
|
|
6
|
-
if (!element || !(element instanceof Element)) {
|
|
7
|
-
throw new Error(
|
|
8
|
-
`Expected DOM element to be an instance of Element, received ${typeof element}`
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
return getUniqueCssSelector(element);
|
|
12
|
-
}
|
|
13
|
-
function escapeIdForCSSSelector(id) {
|
|
14
|
-
return id.split("").map((char) => {
|
|
15
|
-
const code = char.charCodeAt(0);
|
|
16
|
-
if (char === " " || char === "#" || char === "." || char === ":" || char === "[" || char === "]" || char === ">" || char === "+" || char === "~" || char === "\\") {
|
|
17
|
-
return `\\${char}`;
|
|
18
|
-
} else if (code >= 65536) {
|
|
19
|
-
return `\\${code.toString(16).toUpperCase().padStart(6, "0")} `;
|
|
20
|
-
} else if (code < 32 || code === 127) {
|
|
21
|
-
return `\\${code.toString(16).toUpperCase().padStart(2, "0")} `;
|
|
22
|
-
} else if (code >= 128) {
|
|
23
|
-
return `\\${code.toString(16).toUpperCase().padStart(2, "0")} `;
|
|
24
|
-
} else {
|
|
25
|
-
return char;
|
|
26
|
-
}
|
|
27
|
-
}).join("");
|
|
28
|
-
}
|
|
29
|
-
function getUniqueCssSelector(el) {
|
|
30
|
-
const path = [];
|
|
31
|
-
let parent;
|
|
32
|
-
let hasShadowRoot = false;
|
|
33
|
-
while (parent = getParent(el)) {
|
|
34
|
-
if (parent.shadowRoot) {
|
|
35
|
-
hasShadowRoot = true;
|
|
36
|
-
}
|
|
37
|
-
const tag = el.tagName;
|
|
38
|
-
if (el.id) {
|
|
39
|
-
path.push(`#${escapeIdForCSSSelector(el.id)}`);
|
|
40
|
-
} else if (!el.nextElementSibling && !el.previousElementSibling) {
|
|
41
|
-
path.push(tag.toLowerCase());
|
|
42
|
-
} else {
|
|
43
|
-
let index = 0;
|
|
44
|
-
let sameTagSiblings = 0;
|
|
45
|
-
let elementIndex = 0;
|
|
46
|
-
for (const sibling of parent.children) {
|
|
47
|
-
index++;
|
|
48
|
-
if (sibling.tagName === tag) {
|
|
49
|
-
sameTagSiblings++;
|
|
50
|
-
}
|
|
51
|
-
if (sibling === el) {
|
|
52
|
-
elementIndex = index;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (sameTagSiblings > 1) {
|
|
56
|
-
path.push(`${tag.toLowerCase()}:nth-child(${elementIndex})`);
|
|
57
|
-
} else {
|
|
58
|
-
path.push(tag.toLowerCase());
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
el = parent;
|
|
62
|
-
}
|
|
63
|
-
return `${getBrowserState().provider === "webdriverio" && hasShadowRoot ? ">>>" : ""}${path.reverse().join(" > ")}`;
|
|
64
|
-
}
|
|
65
|
-
function getParent(el) {
|
|
66
|
-
const parent = el.parentNode;
|
|
67
|
-
if (parent instanceof ShadowRoot) {
|
|
68
|
-
return parent.host;
|
|
69
|
-
}
|
|
70
|
-
return parent;
|
|
71
|
-
}
|
|
72
|
-
const now = Date.now;
|
|
73
|
-
function processTimeoutOptions(options_) {
|
|
74
|
-
if (
|
|
75
|
-
// if timeout is set, keep it
|
|
76
|
-
options_ && options_.timeout != null || provider !== "playwright"
|
|
77
|
-
) {
|
|
78
|
-
return options_;
|
|
79
|
-
}
|
|
80
|
-
if (getWorkerState().config.browser.providerOptions.actionTimeout != null) {
|
|
81
|
-
return options_;
|
|
82
|
-
}
|
|
83
|
-
const currentTest = getWorkerState().current;
|
|
84
|
-
const startTime = currentTest?.result?.startTime;
|
|
85
|
-
if (!currentTest || currentTest.type === "suite" || !startTime) {
|
|
86
|
-
return options_;
|
|
87
|
-
}
|
|
88
|
-
const timeout = currentTest.timeout;
|
|
89
|
-
if (timeout === 0 || timeout === Number.POSITIVE_INFINITY) {
|
|
90
|
-
return options_;
|
|
91
|
-
}
|
|
92
|
-
options_ = options_ || {};
|
|
93
|
-
const currentTime = now();
|
|
94
|
-
const endTime = startTime + timeout;
|
|
95
|
-
const remainingTime = endTime - currentTime;
|
|
96
|
-
if (remainingTime <= 0) {
|
|
97
|
-
return options_;
|
|
98
|
-
}
|
|
99
|
-
options_.timeout = remainingTime - 100;
|
|
100
|
-
return options_;
|
|
101
|
-
}
|
|
102
|
-
function getIframeScale() {
|
|
103
|
-
const testerUi = window.parent.document.querySelector("#tester-ui");
|
|
104
|
-
if (!testerUi) {
|
|
105
|
-
throw new Error(`Cannot find Tester element. This is a bug in Vitest. Please, open a new issue with reproduction.`);
|
|
106
|
-
}
|
|
107
|
-
const scaleAttribute = testerUi.getAttribute("data-scale");
|
|
108
|
-
const scale = Number(scaleAttribute);
|
|
109
|
-
if (Number.isNaN(scale)) {
|
|
110
|
-
throw new TypeError(`Cannot parse scale value from Tester element (${scaleAttribute}). This is a bug in Vitest. Please, open a new issue with reproduction.`);
|
|
111
|
-
}
|
|
112
|
-
return scale;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export { convertElementToCssSelector as c, getIframeScale as g, processTimeoutOptions as p };
|