-
-
Notifications
You must be signed in to change notification settings - Fork 768
feat: add support for descendant and ancestor flutter locators #2357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cb64b05
feat: add support for ancestor and descendant flutter locators
sudharsan-selvaraj efd5bea
add new line
sudharsan-selvaraj d1711b9
Fix styling errors
sudharsan-selvaraj 521ef10
add supported version to javadoc comments
sudharsan-selvaraj 7915c15
Replace GSON with native JSON serializer
sudharsan-selvaraj 44af9da
fix checkstyle errors
sudharsan-selvaraj 585dc7a
add comment to the test
sudharsan-selvaraj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| package io.appium.java_client; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
| import com.google.gson.Gson; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import org.openqa.selenium.By; | ||
|
|
@@ -25,7 +26,9 @@ | |
| import org.openqa.selenium.WebElement; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static com.google.common.base.Strings.isNullOrEmpty; | ||
|
|
||
|
|
@@ -169,9 +172,9 @@ public static By custom(final String selector) { | |
| * as for OpenCV library. | ||
| * @return an instance of {@link ByImage} | ||
| * @see <a href="https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md"> | ||
| * The documentation on Image Comparison Features</a> | ||
| * The documentation on Image Comparison Features</a> | ||
| * @see <a href="https://github.com/appium/appium-base-driver/blob/master/lib/basedriver/device-settings.js"> | ||
| * The settings available for lookup fine-tuning</a> | ||
| * The settings available for lookup fine-tuning</a> | ||
| * @since Appium 1.8.2 | ||
| */ | ||
| public static By image(final String b64Template) { | ||
|
|
@@ -250,6 +253,53 @@ public static FlutterBy flutterSemanticsLabel(final String semanticsLabel) { | |
| return new ByFlutterSemanticsLabel(semanticsLabel); | ||
| } | ||
|
|
||
| /** | ||
| * This locator strategy is available in FlutterIntegration Driver mode. | ||
| * | ||
| * @param of represents the parent widget locator | ||
| * @param matching represents the descendant widget locator to match | ||
| * @param matchRoot determines whether to include the root widget in the search | ||
| * @param skipOffstage determines whether to skip offstage widgets | ||
| * @return an instance of {@link AppiumBy.ByFlutterDescendant} | ||
| */ | ||
| public static FlutterBy flutterDescendant(final FlutterBy of, final FlutterBy matching, boolean matchRoot, boolean skipOffstage) { | ||
| return new ByFlutterDescendant(of, matching, matchRoot, skipOffstage); | ||
| } | ||
|
|
||
| /** | ||
| * This locator strategy is available in FlutterIntegration Driver mode. | ||
sudharsan-selvaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @param of represents the parent widget locator | ||
| * @param matching represents the descendant widget locator to match | ||
| * @return an instance of {@link AppiumBy.ByFlutterDescendant} | ||
| */ | ||
| public static FlutterBy flutterDescendant(final FlutterBy of, final FlutterBy matching) { | ||
| return flutterDescendant(of, matching, false, true); | ||
| } | ||
|
|
||
| /** | ||
| * This locator strategy is available in FlutterIntegration Driver mode. | ||
sudharsan-selvaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @param of represents the child widget locator | ||
| * @param matching represents the ancestor widget locator to match | ||
| * @param matchRoot determines whether to include the root widget in the search | ||
| * @return an instance of {@link AppiumBy.ByFlutterAncestor} | ||
| */ | ||
| public static FlutterBy flutterAncestor(final FlutterBy of, final FlutterBy matching, boolean matchRoot) { | ||
| return new ByFlutterAncestor(of, matching, matchRoot); | ||
| } | ||
|
|
||
| /** | ||
| * This locator strategy is available in FlutterIntegration Driver mode. | ||
sudharsan-selvaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @param of represents the child widget locator | ||
| * @param matching represents the ancestor widget locator to match | ||
| * @return an instance of {@link AppiumBy.ByFlutterAncestor} | ||
| */ | ||
| public static FlutterBy flutterAncestor(final FlutterBy of, final FlutterBy matching) { | ||
| return flutterAncestor(of, matching, false); | ||
| } | ||
|
|
||
| public static class ByAccessibilityId extends AppiumBy implements Serializable { | ||
| public ByAccessibilityId(String accessibilityId) { | ||
| super("accessibility id", accessibilityId, "accessibilityId"); | ||
|
|
@@ -328,6 +378,27 @@ protected FlutterBy(String selector, String locatorString, String locatorName) { | |
| } | ||
| } | ||
|
|
||
| public abstract static class FlutterByHierarchy extends FlutterBy { | ||
| private static final Gson GSON = new Gson(); | ||
|
|
||
| protected FlutterByHierarchy(String selector, FlutterBy of, FlutterBy matching, Map<String, Object> properties, String locatorName) { | ||
| super(selector, formatLocator(of, matching, properties), locatorName); | ||
| } | ||
|
|
||
| static Map<String, Object> parseFlutterLocator(FlutterBy by) { | ||
| Parameters params = by.getRemoteParameters(); | ||
| return Map.of("using", params.using(), "value", params.value()); | ||
| } | ||
|
|
||
| static String formatLocator(FlutterBy of, FlutterBy matching, Map<String, Object> properties) { | ||
| Map<String, Object> locator = new HashMap<>(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we also use Map.of like above? |
||
| locator.put("of", parseFlutterLocator(of)); | ||
| locator.put("matching", parseFlutterLocator(matching)); | ||
| locator.put("parameters", properties); | ||
| return GSON.toJson(locator); | ||
sudharsan-selvaraj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| public static class ByFlutterType extends FlutterBy implements Serializable { | ||
| protected ByFlutterType(String locatorString) { | ||
| super("-flutter type", locatorString, "flutterType"); | ||
|
|
@@ -358,4 +429,15 @@ protected ByFlutterTextContaining(String locatorString) { | |
| } | ||
| } | ||
|
|
||
| public static class ByFlutterDescendant extends FlutterByHierarchy implements Serializable { | ||
| protected ByFlutterDescendant(FlutterBy of, FlutterBy matching, boolean matchRoot, boolean skipOffstage) { | ||
| super("-flutter descendant", of, matching, Map.of("matchRoot", matchRoot, "skipOffstage", skipOffstage), "flutterDescendant"); | ||
| } | ||
| } | ||
|
|
||
| public static class ByFlutterAncestor extends FlutterByHierarchy implements Serializable { | ||
| protected ByFlutterAncestor(FlutterBy of, FlutterBy matching, boolean matchRoot) { | ||
| super("-flutter ancestor", of, matching, Map.of("matchRoot", matchRoot), "flutterAncestor"); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.