Skip to content

Commit b04522a

Browse files
feat: Add locator types supported by flutter integration driver
1 parent 0e24ef1 commit b04522a

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
import java.io.Serializable;
2828
import java.util.List;
29+
import java.util.Map;
30+
import java.util.Collections;
31+
import java.util.HashMap;
2932

3033
import static com.google.common.base.Strings.isNullOrEmpty;
3134

@@ -53,6 +56,13 @@ protected AppiumBy(String selector, String locatorString, String locatorName) {
5356
return String.format("%s.%s: %s", AppiumBy.class.getSimpleName(), locatorName, remoteParameters.value());
5457
}
5558

59+
public Map<String, Object> toJson() {
60+
Map<String, Object> params = new HashMap<String, Object>();
61+
params.put("using", this.remoteParameters.using());
62+
params.put("value", this.remoteParameters.value());
63+
return Collections.unmodifiableMap(params);
64+
}
65+
5666
/**
5767
* About Android accessibility
5868
* https://developer.android.com/intl/ru/training/accessibility/accessible-app.html
@@ -186,6 +196,51 @@ public static By iOSNsPredicateString(final String iOSNsPredicateString) {
186196
return new ByIosNsPredicate(iOSNsPredicateString);
187197
}
188198

199+
/**
200+
* This locator strategy is available in FlutterIntegration Driver mode.
201+
* @param selector is the value defined to the key attribute of the flutter element
202+
* @return an instance of {@link AppiumBy.ByFlutterKey}
203+
*/
204+
public static By flutterKey(final String selector) {
205+
return new ByFlutterKey(selector);
206+
}
207+
208+
/**
209+
* This locator strategy is available in FlutterIntegration Driver mode.
210+
* @param selector is the Type of widget mounted in the app tree
211+
* @return an instance of {@link AppiumBy.ByFlutterType}
212+
*/
213+
public static By flutterType(final String selector) {
214+
return new ByFlutterType(selector);
215+
}
216+
217+
/**
218+
* This locator strategy is available in FlutterIntegration Driver mode.
219+
* @param selector is the text that is present on the widget
220+
* @return an instance of {@link AppiumBy.ByFlutterText}
221+
*/
222+
public static By flutterText(final String selector) {
223+
return new ByFlutterText(selector);
224+
}
225+
226+
/**
227+
* This locator strategy is available in FlutterIntegration Driver mode.
228+
* @param selector is the text that is partially present on the widget
229+
* @return an instance of {@link AppiumBy.ByFlutterTextContaining}
230+
*/
231+
public static By flutterTextContaining(final String selector) {
232+
return new ByFlutterTextContaining(selector);
233+
}
234+
235+
/**
236+
* This locator strategy is available in FlutterIntegration Driver mode.
237+
* @param semanticsLabel represents the value assigned to the label attribute of semantics element
238+
* @return an instance of {@link AppiumBy.ByFlutterSemanticsLabel}
239+
*/
240+
public static By flutterSemanticsLabel(final String semanticsLabel) {
241+
return new ByFlutterSemanticsLabel(semanticsLabel);
242+
}
243+
189244
public static class ByAccessibilityId extends AppiumBy implements Serializable {
190245
public ByAccessibilityId(String accessibilityId) {
191246
super("accessibility id", accessibilityId, "accessibilityId");
@@ -257,4 +312,34 @@ protected ByIosNsPredicate(String locatorString) {
257312
super("-ios predicate string", locatorString, "iOSNsPredicate");
258313
}
259314
}
315+
316+
public static class ByFlutterType extends AppiumBy implements Serializable {
317+
protected ByFlutterType(String locatorString) {
318+
super("-flutter type", locatorString, "flutterType");
319+
}
320+
}
321+
322+
public static class ByFlutterKey extends AppiumBy implements Serializable {
323+
protected ByFlutterKey(String locatorString) {
324+
super("-flutter key", locatorString, "flutterKey");
325+
}
326+
}
327+
328+
public static class ByFlutterSemanticsLabel extends AppiumBy implements Serializable {
329+
protected ByFlutterSemanticsLabel(String locatorString) {
330+
super("-flutter semantics label", locatorString, "flutterSemanticsLabel");
331+
}
332+
}
333+
334+
public static class ByFlutterText extends AppiumBy implements Serializable {
335+
protected ByFlutterText(String locatorString) {
336+
super("-flutter text", locatorString, "flutterText");
337+
}
338+
}
339+
340+
public static class ByFlutterTextContaining extends AppiumBy implements Serializable {
341+
protected ByFlutterTextContaining(String locatorString) {
342+
super("-flutter text containing", locatorString, "flutterTextContaining");
343+
}
344+
}
260345
}

0 commit comments

Comments
 (0)