@@ -10,6 +10,36 @@ import { W3C_ELEMENT_KEY } from 'appium/driver';
1010import type { AppiumFlutterDriver } from '../driver' ;
1111
1212export 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+
1343export 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