@allwright.dev/core 0.0.31 → 0.0.32
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/dist/index.js +54 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,6 +12,39 @@ const PROTO_ROOT = path.join(PACKAGE_ROOT, "proto");
|
|
|
12
12
|
const ENGINE_PROTO_PATH = path.join(PROTO_ROOT, "engine", "v1", "engine.proto");
|
|
13
13
|
let runtimePromise = null;
|
|
14
14
|
let serverAddrOverride = null;
|
|
15
|
+
function parseSelectorForTransport(selector) {
|
|
16
|
+
const trimmed = selector.trim();
|
|
17
|
+
const lower = trimmed.toLowerCase();
|
|
18
|
+
if (lower.startsWith("xpath=") || lower.startsWith("xpath:")) {
|
|
19
|
+
return { flavor: "xpath", body: trimmed.slice(6).trim() };
|
|
20
|
+
}
|
|
21
|
+
if (lower.startsWith("css=") || lower.startsWith("css:")) {
|
|
22
|
+
return { flavor: "css", body: trimmed.slice(4).trim() };
|
|
23
|
+
}
|
|
24
|
+
if (trimmed.startsWith("//") ||
|
|
25
|
+
trimmed.startsWith(".//") ||
|
|
26
|
+
trimmed.startsWith("../") ||
|
|
27
|
+
trimmed.startsWith("/") ||
|
|
28
|
+
trimmed.startsWith("(")) {
|
|
29
|
+
return { flavor: "xpath", body: trimmed };
|
|
30
|
+
}
|
|
31
|
+
return { flavor: "css", body: trimmed };
|
|
32
|
+
}
|
|
33
|
+
function normalizeSelectorForTransport(selector) {
|
|
34
|
+
const parsed = parseSelectorForTransport(selector);
|
|
35
|
+
return `${parsed.flavor}=${JSON.stringify(parsed.body)}`;
|
|
36
|
+
}
|
|
37
|
+
function chainSelectorForTransport(parent, child) {
|
|
38
|
+
const parentSelector = normalizeSelectorForTransport(parent);
|
|
39
|
+
const childSelector = normalizeSelectorForTransport(child);
|
|
40
|
+
if (!parentSelector) {
|
|
41
|
+
return childSelector;
|
|
42
|
+
}
|
|
43
|
+
if (!childSelector) {
|
|
44
|
+
return parentSelector;
|
|
45
|
+
}
|
|
46
|
+
return `${parentSelector} ${childSelector}`;
|
|
47
|
+
}
|
|
15
48
|
const CONFIG_FILENAMES = [
|
|
16
49
|
"allwright.config.yaml",
|
|
17
50
|
"allwright.config.yml",
|
|
@@ -199,7 +232,7 @@ class PageImpl {
|
|
|
199
232
|
sessionId;
|
|
200
233
|
browserSessionId;
|
|
201
234
|
locator(selector) {
|
|
202
|
-
return new LocatorImpl({ page: this, selector });
|
|
235
|
+
return new LocatorImpl({ page: this, selector: normalizeSelectorForTransport(selector) });
|
|
203
236
|
}
|
|
204
237
|
async goto(url, options = {}) {
|
|
205
238
|
const handle = await this.#getHandle();
|
|
@@ -244,11 +277,12 @@ class PageImpl {
|
|
|
244
277
|
async click(selector, options = {}) {
|
|
245
278
|
const handle = await this.#getHandle();
|
|
246
279
|
this.#ensureOpen(handle);
|
|
280
|
+
const transportSelector = normalizeSelectorForTransport(selector);
|
|
247
281
|
handle.stream.write({
|
|
248
282
|
browserSessionId: this.browserSessionId,
|
|
249
283
|
tabSessionId: this.sessionId,
|
|
250
284
|
clickElement: {
|
|
251
|
-
cssSelector:
|
|
285
|
+
cssSelector: transportSelector,
|
|
252
286
|
retryOptions: options.timeoutMs ? { timeoutMs: options.timeoutMs } : undefined,
|
|
253
287
|
},
|
|
254
288
|
});
|
|
@@ -273,11 +307,12 @@ class PageImpl {
|
|
|
273
307
|
async count(selector, options = {}) {
|
|
274
308
|
const handle = await this.#getHandle();
|
|
275
309
|
this.#ensureOpen(handle);
|
|
310
|
+
const transportSelector = normalizeSelectorForTransport(selector);
|
|
276
311
|
handle.stream.write({
|
|
277
312
|
browserSessionId: this.browserSessionId,
|
|
278
313
|
tabSessionId: this.sessionId,
|
|
279
314
|
countElements: {
|
|
280
|
-
cssSelector:
|
|
315
|
+
cssSelector: transportSelector,
|
|
281
316
|
retryOptions: options.timeoutMs ? { timeoutMs: options.timeoutMs } : undefined,
|
|
282
317
|
},
|
|
283
318
|
});
|
|
@@ -302,11 +337,12 @@ class PageImpl {
|
|
|
302
337
|
async highlight(selector, options = {}) {
|
|
303
338
|
const handle = await this.#getHandle();
|
|
304
339
|
this.#ensureOpen(handle);
|
|
340
|
+
const transportSelector = normalizeSelectorForTransport(selector);
|
|
305
341
|
handle.stream.write({
|
|
306
342
|
browserSessionId: this.browserSessionId,
|
|
307
343
|
tabSessionId: this.sessionId,
|
|
308
344
|
highlightElements: {
|
|
309
|
-
cssSelector:
|
|
345
|
+
cssSelector: transportSelector,
|
|
310
346
|
durationMs: options.durationMs,
|
|
311
347
|
retryOptions: options.timeoutMs ? { timeoutMs: options.timeoutMs } : undefined,
|
|
312
348
|
},
|
|
@@ -332,11 +368,12 @@ class PageImpl {
|
|
|
332
368
|
async focus(selector, options = {}) {
|
|
333
369
|
const handle = await this.#getHandle();
|
|
334
370
|
this.#ensureOpen(handle);
|
|
371
|
+
const transportSelector = normalizeSelectorForTransport(selector);
|
|
335
372
|
handle.stream.write({
|
|
336
373
|
browserSessionId: this.browserSessionId,
|
|
337
374
|
tabSessionId: this.sessionId,
|
|
338
375
|
focusElement: {
|
|
339
|
-
cssSelector:
|
|
376
|
+
cssSelector: transportSelector,
|
|
340
377
|
retryOptions: options.timeoutMs ? { timeoutMs: options.timeoutMs } : undefined,
|
|
341
378
|
},
|
|
342
379
|
});
|
|
@@ -360,11 +397,12 @@ class PageImpl {
|
|
|
360
397
|
async fill(selector, value, options = {}) {
|
|
361
398
|
const handle = await this.#getHandle();
|
|
362
399
|
this.#ensureOpen(handle);
|
|
400
|
+
const transportSelector = normalizeSelectorForTransport(selector);
|
|
363
401
|
handle.stream.write({
|
|
364
402
|
browserSessionId: this.browserSessionId,
|
|
365
403
|
tabSessionId: this.sessionId,
|
|
366
404
|
fillElement: {
|
|
367
|
-
cssSelector:
|
|
405
|
+
cssSelector: transportSelector,
|
|
368
406
|
value,
|
|
369
407
|
retryOptions: options.timeoutMs ? { timeoutMs: options.timeoutMs } : undefined,
|
|
370
408
|
},
|
|
@@ -390,11 +428,12 @@ class PageImpl {
|
|
|
390
428
|
async hover(selector, options = {}) {
|
|
391
429
|
const handle = await this.#getHandle();
|
|
392
430
|
this.#ensureOpen(handle);
|
|
431
|
+
const transportSelector = normalizeSelectorForTransport(selector);
|
|
393
432
|
handle.stream.write({
|
|
394
433
|
browserSessionId: this.browserSessionId,
|
|
395
434
|
tabSessionId: this.sessionId,
|
|
396
435
|
hoverElement: {
|
|
397
|
-
cssSelector:
|
|
436
|
+
cssSelector: transportSelector,
|
|
398
437
|
retryOptions: options.timeoutMs ? { timeoutMs: options.timeoutMs } : undefined,
|
|
399
438
|
},
|
|
400
439
|
});
|
|
@@ -418,11 +457,12 @@ class PageImpl {
|
|
|
418
457
|
async press(selector, key, options = {}) {
|
|
419
458
|
const handle = await this.#getHandle();
|
|
420
459
|
this.#ensureOpen(handle);
|
|
460
|
+
const transportSelector = normalizeSelectorForTransport(selector);
|
|
421
461
|
handle.stream.write({
|
|
422
462
|
browserSessionId: this.browserSessionId,
|
|
423
463
|
tabSessionId: this.sessionId,
|
|
424
464
|
pressKey: {
|
|
425
|
-
cssSelector:
|
|
465
|
+
cssSelector: transportSelector,
|
|
426
466
|
key,
|
|
427
467
|
text: options.text,
|
|
428
468
|
retryOptions: options.timeoutMs ? { timeoutMs: options.timeoutMs } : undefined,
|
|
@@ -455,11 +495,12 @@ class PageImpl {
|
|
|
455
495
|
async waitForSelector(selector, options = {}) {
|
|
456
496
|
const handle = await this.#getHandle();
|
|
457
497
|
this.#ensureOpen(handle);
|
|
498
|
+
const transportSelector = normalizeSelectorForTransport(selector);
|
|
458
499
|
handle.stream.write({
|
|
459
500
|
browserSessionId: this.browserSessionId,
|
|
460
501
|
tabSessionId: this.sessionId,
|
|
461
502
|
waitForSelector: {
|
|
462
|
-
cssSelector:
|
|
503
|
+
cssSelector: transportSelector,
|
|
463
504
|
visible: options.visible,
|
|
464
505
|
retryOptions: options.timeoutMs ? { timeoutMs: options.timeoutMs } : undefined,
|
|
465
506
|
},
|
|
@@ -540,12 +581,13 @@ class PageImpl {
|
|
|
540
581
|
async #readText(selector, options, textContent) {
|
|
541
582
|
const handle = await this.#getHandle();
|
|
542
583
|
this.#ensureOpen(handle);
|
|
584
|
+
const transportSelector = normalizeSelectorForTransport(selector);
|
|
543
585
|
handle.stream.write(textContent
|
|
544
586
|
? {
|
|
545
587
|
browserSessionId: this.browserSessionId,
|
|
546
588
|
tabSessionId: this.sessionId,
|
|
547
589
|
getTextContent: {
|
|
548
|
-
cssSelector:
|
|
590
|
+
cssSelector: transportSelector,
|
|
549
591
|
retryOptions: options.timeoutMs ? { timeoutMs: options.timeoutMs } : undefined,
|
|
550
592
|
},
|
|
551
593
|
}
|
|
@@ -553,7 +595,7 @@ class PageImpl {
|
|
|
553
595
|
browserSessionId: this.browserSessionId,
|
|
554
596
|
tabSessionId: this.sessionId,
|
|
555
597
|
getInnerText: {
|
|
556
|
-
cssSelector:
|
|
598
|
+
cssSelector: transportSelector,
|
|
557
599
|
retryOptions: options.timeoutMs ? { timeoutMs: options.timeoutMs } : undefined,
|
|
558
600
|
},
|
|
559
601
|
});
|
|
@@ -634,7 +676,7 @@ class LocatorImpl {
|
|
|
634
676
|
locator(selector) {
|
|
635
677
|
return new LocatorImpl({
|
|
636
678
|
page: this.page,
|
|
637
|
-
selector:
|
|
679
|
+
selector: chainSelectorForTransport(this.selector, selector),
|
|
638
680
|
});
|
|
639
681
|
}
|
|
640
682
|
}
|