@letsrunit/playwright 0.8.0 → 0.9.1
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 +19 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/fuzzy-locator.ts +22 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@letsrunit/playwright",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Playwright extensions and utilities for letsrunit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"testing",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"packageManager": "yarn@4.10.3",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@letsrunit/utils": "0.
|
|
45
|
+
"@letsrunit/utils": "0.9.1",
|
|
46
46
|
"@playwright/test": "^1.57.0",
|
|
47
47
|
"case": "^1.6.3",
|
|
48
48
|
"diff": "^8.0.3",
|
package/src/fuzzy-locator.ts
CHANGED
|
@@ -1,26 +1,39 @@
|
|
|
1
1
|
import { Locator, Page } from '@playwright/test';
|
|
2
2
|
|
|
3
|
+
function debug(...args: unknown[]) {
|
|
4
|
+
if (process.env.LETSRUNIT_DEBUG_FUZZY_LOCATOR === '1') {
|
|
5
|
+
// eslint-disable-next-line no-console
|
|
6
|
+
console.log('[fuzzyLocator]', ...args);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
/**
|
|
4
11
|
* Locates an element using Playwright selectors, with lazy fallbacks.
|
|
5
12
|
*/
|
|
6
13
|
export async function fuzzyLocator(page: Page, selector: string): Promise<Locator> {
|
|
14
|
+
debug('input selector:', selector);
|
|
7
15
|
const primary = page.locator(selector);
|
|
8
|
-
const candidates = [
|
|
9
|
-
tryRelaxNameToHasText(page, selector),
|
|
10
|
-
tryTagInsteadOfRole(page, selector),
|
|
11
|
-
tryRoleNameProximity(page, selector),
|
|
12
|
-
tryFieldAlternative(page, selector),
|
|
13
|
-
tryAsField(page, selector),
|
|
16
|
+
const candidates: Array<{ name: string; locator: Locator | null }> = [
|
|
17
|
+
{ name: 'relaxNameToHasText', locator: tryRelaxNameToHasText(page, selector) },
|
|
18
|
+
{ name: 'tagInsteadOfRole', locator: tryTagInsteadOfRole(page, selector) },
|
|
19
|
+
{ name: 'roleNameProximity', locator: tryRoleNameProximity(page, selector) },
|
|
20
|
+
{ name: 'fieldAlternative', locator: tryFieldAlternative(page, selector) },
|
|
21
|
+
{ name: 'asField', locator: tryAsField(page, selector) },
|
|
14
22
|
];
|
|
15
23
|
|
|
16
24
|
let combined = primary;
|
|
25
|
+
const enabled: string[] = [];
|
|
17
26
|
|
|
18
27
|
for (const candidate of candidates) {
|
|
19
|
-
if (!candidate) continue;
|
|
20
|
-
|
|
28
|
+
if (!candidate.locator) continue;
|
|
29
|
+
enabled.push(candidate.name);
|
|
30
|
+
combined = combined.or(candidate.locator);
|
|
21
31
|
}
|
|
32
|
+
debug('enabled fallbacks:', enabled.length ? enabled.join(', ') : '(none)');
|
|
22
33
|
|
|
23
|
-
|
|
34
|
+
const result = combined.first();
|
|
35
|
+
debug('returning locator:', result.toString());
|
|
36
|
+
return result;
|
|
24
37
|
}
|
|
25
38
|
|
|
26
39
|
// Preserve the selector but relax [name="..."] to [has-text="..."]
|