Skip to content

Commit acc617c

Browse files
fix: locator parsing (#151)
1 parent 35173ae commit acc617c

File tree

1 file changed

+31
-41
lines changed

1 file changed

+31
-41
lines changed

src/commands/element.ts

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,36 @@ import { W3C_ELEMENT_KEY } from 'appium/driver';
1010
import type { AppiumFlutterDriver } from '../driver';
1111

1212
export const ELEMENT_CACHE = new Map();
13+
14+
function constructFindElementPayload(
15+
strategy: string,
16+
selector: string,
17+
context: string,
18+
proxyDriver: XCUITestDriver | AndroidUiautomator2Driver | Mac2Driver,
19+
) {
20+
const isFlutterLocator =
21+
strategy.startsWith('-flutter') || FLUTTER_LOCATORS.includes(strategy);
22+
23+
let parsedSelector = selector;
24+
if (
25+
['-flutter descendant', '-flutter ancestor'].includes(strategy) &&
26+
_.isString(selector)
27+
) {
28+
parsedSelector = JSON.parse(selector);
29+
}
30+
31+
// If user is looking for Native IOS/Mac locator
32+
if (
33+
!isFlutterLocator &&
34+
(proxyDriver instanceof XCUITestDriver ||
35+
proxyDriver instanceof Mac2Driver)
36+
) {
37+
return { using: strategy, value: parsedSelector, context };
38+
} else {
39+
return { strategy, selector: parsedSelector, context };
40+
}
41+
}
42+
1343
export async function findElOrEls(
1444
this: AppiumFlutterDriver,
1545
strategy: string,
@@ -19,51 +49,11 @@ export async function findElOrEls(
1949
): Promise<any> {
2050
const driver = await getProxyDriver.bind(this)(strategy);
2151
let elementBody;
22-
function constructFindElementPayload(
23-
strategy: string,
24-
selector: string,
25-
proxyDriver: XCUITestDriver | AndroidUiautomator2Driver | Mac2Driver,
26-
) {
27-
const isFlutterLocator =
28-
strategy.startsWith('-flutter') || FLUTTER_LOCATORS.includes(strategy);
29-
30-
let parsedSelector;
31-
if (['-flutter descendant', '-flutter ancestor'].includes(strategy)) {
32-
// Handle descendant/ancestor special case
33-
parsedSelector = _.isString(selector)
34-
? JSON.parse(selector)
35-
: selector;
36-
37-
// For Mac2Driver and XCUITestDriver, format selector differently
38-
if (
39-
proxyDriver instanceof XCUITestDriver ||
40-
proxyDriver instanceof Mac2Driver
41-
) {
42-
return {
43-
using: strategy,
44-
value: JSON.stringify(parsedSelector),
45-
context,
46-
};
47-
}
48-
} else {
49-
parsedSelector = selector;
50-
}
51-
52-
// If user is looking for Native IOS/Mac locator
53-
if (
54-
!isFlutterLocator &&
55-
(proxyDriver instanceof XCUITestDriver ||
56-
proxyDriver instanceof Mac2Driver)
57-
) {
58-
return { using: strategy, value: parsedSelector, context };
59-
} else {
60-
return { strategy, selector: parsedSelector, context };
61-
}
62-
}
6352

6453
elementBody = constructFindElementPayload(
6554
strategy,
6655
selector,
56+
context,
6757
this.proxydriver,
6858
);
6959
if (mult) {

0 commit comments

Comments
 (0)