Skip to content

Commit 42cf914

Browse files
fix: Add support for locator with -flutter prefix (#64)
* feat: add -flutter prefix to locator strategy * Prettier fix * support for backward compatibility * styling fixes
1 parent d3fca03 commit 42cf914

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/driver.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import {
2626
attachAppLaunchArguments,
2727
fetchFlutterServerPort,
28+
FLUTTER_LOCATORS,
2829
getFreePort,
2930
isFlutterDriverCommand,
3031
waitForFlutterServerToBeActive,
@@ -56,16 +57,14 @@ export class AppiumFlutterDriver extends BaseDriver<FlutterDriverConstraints> {
5657
'xpath',
5758
'css selector',
5859
'id',
60+
'name',
61+
'class name',
5962
'-android uiautomator',
6063
'accessibility id',
6164
'-ios predicate string',
6265
'-ios class chain',
63-
'name',
64-
'key',
65-
'class name',
66-
'semantics label',
67-
'text',
68-
'type',
66+
...FLUTTER_LOCATORS, //to support backward compatibility
67+
...FLUTTER_LOCATORS.map((locator) => `-flutter ${locator}`),
6968
];
7069
}
7170

src/utils.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { findAPortNotInUse } from 'portscanner';
33
import { waitForCondition } from 'asyncbox';
44
import { JWProxy } from 'appium/driver';
55
import type { PortForwardCallback, PortReleaseCallback } from './types';
6-
import type { AppiumFlutterDriver } from './driver';
6+
import { type AppiumFlutterDriver } from './driver';
77
import _ from 'lodash';
88
import type { StringRecord } from '@appium/types';
99
import { node } from 'appium/support';
@@ -17,12 +17,18 @@ const {
1717
appium: { flutterServerVersion: FLUTTER_SERVER_VERSION_REQ },
1818
version: PACKAGE_VERSION,
1919
} = readManifest();
20-
20+
export const FLUTTER_LOCATORS = [
21+
'key',
22+
'semantics label',
23+
'text',
24+
'type',
25+
'text containing',
26+
];
2127
export async function getProxyDriver(
2228
this: AppiumFlutterDriver,
2329
strategy: string,
2430
): Promise<JWProxy | undefined> {
25-
if (['key', 'semantics label', 'text', 'type'].includes(strategy)) {
31+
if (strategy.startsWith('-flutter') || FLUTTER_LOCATORS.includes(strategy)) {
2632
return this.proxy;
2733
} else if (this.proxydriver instanceof AndroidUiautomator2Driver) {
2834
// @ts-ignore Proxy instance is OK

0 commit comments

Comments
 (0)