Skip to content

Commit bb4ee2d

Browse files
feat: Add locator types supported by flutter integration driver (#2201)
1 parent 0e24ef1 commit bb4ee2d

File tree

1 file changed

+113
-12
lines changed

1 file changed

+113
-12
lines changed

src/main/java/io/appium/java_client/AppiumBy.java

Lines changed: 113 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
@EqualsAndHashCode(callSuper = true)
3333
public abstract class AppiumBy extends By implements Remotable {
3434

35-
@Getter private final Parameters remoteParameters;
35+
@Getter
36+
private final Parameters remoteParameters;
3637
private final String locatorName;
3738

3839
protected AppiumBy(String selector, String locatorString, String locatorName) {
@@ -41,15 +42,18 @@ protected AppiumBy(String selector, String locatorString, String locatorName) {
4142
this.locatorName = locatorName;
4243
}
4344

44-
@Override public List<WebElement> findElements(SearchContext context) {
45+
@Override
46+
public List<WebElement> findElements(SearchContext context) {
4547
return context.findElements(this);
4648
}
4749

48-
@Override public WebElement findElement(SearchContext context) {
50+
@Override
51+
public WebElement findElement(SearchContext context) {
4952
return context.findElement(this);
5053
}
5154

52-
@Override public String toString() {
55+
@Override
56+
public String toString() {
5357
return String.format("%s.%s: %s", AppiumBy.class.getSimpleName(), locatorName, remoteParameters.value());
5458
}
5559

@@ -59,6 +63,7 @@ protected AppiumBy(String selector, String locatorString, String locatorName) {
5963
* About iOS accessibility
6064
* https://developer.apple.com/library/ios/documentation/UIKit/Reference/
6165
* UIAccessibilityIdentification_Protocol/index.html
66+
*
6267
* @param accessibilityId id is a convenient UI automation accessibility Id.
6368
* @return an instance of {@link AppiumBy.ByAndroidUIAutomator}
6469
*/
@@ -68,9 +73,10 @@ public static By accessibilityId(final String accessibilityId) {
6873

6974
/**
7075
* This locator strategy is only available in Espresso Driver mode.
76+
*
7177
* @param dataMatcherString is a valid json string detailing hamcrest matcher for Espresso onData().
72-
* See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">
73-
* the documentation</a> for more details
78+
* See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">
79+
* the documentation</a> for more details
7480
* @return an instance of {@link AppiumBy.ByAndroidDataMatcher}
7581
*/
7682
public static By androidDataMatcher(final String dataMatcherString) {
@@ -79,6 +85,7 @@ public static By androidDataMatcher(final String dataMatcherString) {
7985

8086
/**
8187
* Refer to https://developer.android.com/training/testing/ui-automator
88+
*
8289
* @param uiautomatorText is Android UIAutomator string
8390
* @return an instance of {@link AppiumBy.ByAndroidUIAutomator}
8491
*/
@@ -88,9 +95,10 @@ public static By androidUIAutomator(final String uiautomatorText) {
8895

8996
/**
9097
* This locator strategy is only available in Espresso Driver mode.
98+
*
9199
* @param viewMatcherString is a valid json string detailing hamcrest matcher for Espresso onView().
92-
* See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">
93-
* the documentation</a> for more details
100+
* See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">
101+
* the documentation</a> for more details
94102
* @return an instance of {@link AppiumBy.ByAndroidViewMatcher}
95103
*/
96104
public static By androidViewMatcher(final String viewMatcherString) {
@@ -99,9 +107,10 @@ public static By androidViewMatcher(final String viewMatcherString) {
99107

100108
/**
101109
* This locator strategy is available in Espresso Driver mode.
102-
* @since Appium 1.8.2 beta
110+
*
103111
* @param tag is a view tag string
104112
* @return an instance of {@link ByAndroidViewTag}
113+
* @since Appium 1.8.2 beta
105114
*/
106115
public static By androidViewTag(final String tag) {
107116
return new ByAndroidViewTag(tag);
@@ -110,6 +119,7 @@ public static By androidViewTag(final String tag) {
110119
/**
111120
* For IOS it is the full name of the XCUI element and begins with XCUIElementType.
112121
* For Android it is the full name of the UIAutomator2 class (e.g.: android.widget.TextView)
122+
*
113123
* @param selector the class name of the element
114124
* @return an instance of {@link ByClassName}
115125
*/
@@ -120,6 +130,7 @@ public static By className(final String selector) {
120130
/**
121131
* For IOS the element name.
122132
* For Android it is the resource identifier.
133+
*
123134
* @param selector element id
124135
* @return an instance of {@link ById}
125136
*/
@@ -130,6 +141,7 @@ public static By id(final String selector) {
130141
/**
131142
* For IOS the element name.
132143
* For Android it is the resource identifier.
144+
*
133145
* @param selector element id
134146
* @return an instance of {@link ByName}
135147
*/
@@ -153,21 +165,22 @@ public static By custom(final String selector) {
153165
* This locator strategy is available only if OpenCV libraries and
154166
* Node.js bindings are installed on the server machine.
155167
*
168+
* @param b64Template base64-encoded template image string. Supported image formats are the same
169+
* as for OpenCV library.
170+
* @return an instance of {@link ByImage}
156171
* @see <a href="https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md">
157172
* The documentation on Image Comparison Features</a>
158173
* @see <a href="https://github.com/appium/appium-base-driver/blob/master/lib/basedriver/device-settings.js">
159174
* The settings available for lookup fine-tuning</a>
160175
* @since Appium 1.8.2
161-
* @param b64Template base64-encoded template image string. Supported image formats are the same
162-
* as for OpenCV library.
163-
* @return an instance of {@link ByImage}
164176
*/
165177
public static By image(final String b64Template) {
166178
return new ByImage(b64Template);
167179
}
168180

169181
/**
170182
* This locator strategy is available in XCUITest Driver mode.
183+
*
171184
* @param iOSClassChainString is a valid class chain locator string.
172185
* See <a href="https://github.com/facebookarchive/WebDriverAgent/wiki/Class-Chain-Queries-Construction-Rules">
173186
* the documentation</a> for more details
@@ -179,13 +192,64 @@ public static By iOSClassChain(final String iOSClassChainString) {
179192

180193
/**
181194
* This locator strategy is available in XCUITest Driver mode.
195+
*
182196
* @param iOSNsPredicateString is an iOS NsPredicate String
183197
* @return an instance of {@link AppiumBy.ByIosNsPredicate}
184198
*/
185199
public static By iOSNsPredicateString(final String iOSNsPredicateString) {
186200
return new ByIosNsPredicate(iOSNsPredicateString);
187201
}
188202

203+
/**
204+
* This locator strategy is available in FlutterIntegration Driver mode.
205+
*
206+
* @param selector is the value defined to the key attribute of the flutter element
207+
* @return an instance of {@link AppiumBy.ByFlutterKey}
208+
*/
209+
public static By flutterKey(final String selector) {
210+
return new ByFlutterKey(selector);
211+
}
212+
213+
/**
214+
* This locator strategy is available in FlutterIntegration Driver mode.
215+
*
216+
* @param selector is the Type of widget mounted in the app tree
217+
* @return an instance of {@link AppiumBy.ByFlutterType}
218+
*/
219+
public static By flutterType(final String selector) {
220+
return new ByFlutterType(selector);
221+
}
222+
223+
/**
224+
* This locator strategy is available in FlutterIntegration Driver mode.
225+
*
226+
* @param selector is the text that is present on the widget
227+
* @return an instance of {@link AppiumBy.ByFlutterText}
228+
*/
229+
public static By flutterText(final String selector) {
230+
return new ByFlutterText(selector);
231+
}
232+
233+
/**
234+
* This locator strategy is available in FlutterIntegration Driver mode.
235+
*
236+
* @param selector is the text that is partially present on the widget
237+
* @return an instance of {@link AppiumBy.ByFlutterTextContaining}
238+
*/
239+
public static By flutterTextContaining(final String selector) {
240+
return new ByFlutterTextContaining(selector);
241+
}
242+
243+
/**
244+
* This locator strategy is available in FlutterIntegration Driver mode.
245+
*
246+
* @param semanticsLabel represents the value assigned to the label attribute of semantics element
247+
* @return an instance of {@link AppiumBy.ByFlutterSemanticsLabel}
248+
*/
249+
public static By flutterSemanticsLabel(final String semanticsLabel) {
250+
return new ByFlutterSemanticsLabel(semanticsLabel);
251+
}
252+
189253
public static class ByAccessibilityId extends AppiumBy implements Serializable {
190254
public ByAccessibilityId(String accessibilityId) {
191255
super("accessibility id", accessibilityId, "accessibilityId");
@@ -257,4 +321,41 @@ protected ByIosNsPredicate(String locatorString) {
257321
super("-ios predicate string", locatorString, "iOSNsPredicate");
258322
}
259323
}
324+
325+
public abstract static class FlutterBy extends AppiumBy {
326+
protected FlutterBy(String selector, String locatorString, String locatorName) {
327+
super(selector, locatorString, locatorName);
328+
}
329+
}
330+
331+
public static class ByFlutterType extends FlutterBy implements Serializable {
332+
protected ByFlutterType(String locatorString) {
333+
super("-flutter type", locatorString, "flutterType");
334+
}
335+
}
336+
337+
public static class ByFlutterKey extends FlutterBy implements Serializable {
338+
protected ByFlutterKey(String locatorString) {
339+
super("-flutter key", locatorString, "flutterKey");
340+
}
341+
}
342+
343+
public static class ByFlutterSemanticsLabel extends FlutterBy implements Serializable {
344+
protected ByFlutterSemanticsLabel(String locatorString) {
345+
super("-flutter semantics label", locatorString, "flutterSemanticsLabel");
346+
}
347+
}
348+
349+
public static class ByFlutterText extends FlutterBy implements Serializable {
350+
protected ByFlutterText(String locatorString) {
351+
super("-flutter text", locatorString, "flutterText");
352+
}
353+
}
354+
355+
public static class ByFlutterTextContaining extends FlutterBy implements Serializable {
356+
protected ByFlutterTextContaining(String locatorString) {
357+
super("-flutter text containing", locatorString, "flutterTextContaining");
358+
}
359+
}
360+
260361
}

0 commit comments

Comments
 (0)