#342 Fix#366
Conversation
|
@SrinivasanTarget I'm looking forward for more complex solution:
...
public abstract class MobileBy extends By implements Serializable {
private final String automatorText;
public MobileBy(String automatorText) {
this.automatorText = automatorText;
}
protected String getAutomatorText() {
return automatorText;
}
...
public static class ByIosUIAutomation extends MobileBy {
public ByIosUIAutomation(String uiautomationText) {
super(uiautomationText);
}
@SuppressWarnings("unchecked")
@Override
public List<WebElement> findElements(SearchContext context) {
return (List<WebElement>) ((FindsByIosUIAutomation<?>) context)
.findElementsByIosUIAutomation(getAutomatorText());
}
@Override public WebElement findElement(SearchContext context) {
return ((FindsByIosUIAutomation<?>) context)
.findElementByIosUIAutomation(getAutomatorText());
}
@Override public String toString() {
return "By.IosUIAutomation: " + getAutomatorText();
}
}
public static class ByAndroidUIAutomator extends MobileBy {
public ByAndroidUIAutomator(String uiautomatorText) {
super(uiautomationText);
}
@SuppressWarnings("unchecked")
@Override
public List<WebElement> findElements(SearchContext context) {
return (List<WebElement>) ((FindsByAndroidUIAutomator<?>) context)
.findElementsByAndroidUIAutomator(getAutomatorText());
}
@Override public WebElement findElement(SearchContext context) {
return ((FindsByAndroidUIAutomator<?>) context)
.findElementByAndroidUIAutomator(getAutomatorText());
}
@Override public String toString() {
return "By.AndroidUIAutomator: " + automatorText;
}
@Override public String getAutomatorText() {
return automatorText;
}
}
public static class ByAccessibilityId extends By implements Serializable {
private final String id;
public ByAccessibilityId(String id) {
this.id = id;
}
@SuppressWarnings("unchecked")
@Override
public List<WebElement> findElements(SearchContext context) {
return (List<WebElement>) ((FindsByAccessibilityId<?>) context)
.findElementsByAccessibilityId(id);
}
@Override public WebElement findElement(SearchContext context) {
return ((FindsByAccessibilityId<?>) context).findElementByAccessibilityId(id);
}
@Override public String toString() {
return "By.AccessibilityId: " + id;
}
}
}
public class AndroidDriver<T extends WebElement>
extends AppiumDriver<T>
implements AndroidDeviceActionShortcuts, HasNetworkConnection, PushesFiles, StartsActivity,
FindsByAndroidUIAutomator<T> {
....
@Override public T scrollTo(String text) {
String uiScrollables =
uiScrollable("new UiSelector().descriptionContains(\"" + text + "\")")
+ uiScrollable("new UiSelector().textContains(\"" + text + "\")");
return findElementByAndroidUIAutomator(uiScrollables);
}
@Override public T scrollToExact(String text) {
String uiScrollables =
uiScrollable("new UiSelector().description(\"" + text + "\")") + uiScrollable(
"new UiSelector().text(\"" + text + "\")");
return findElementByAndroidUIAutomator(uiScrollables);
}
public T scrollToUsingAutomamator(ByAndroidUIAutomator by) {
return findElementByAndroidUIAutomator(uiScrollable(by.getAutomatorText()));
}
....
}public class IOSDriver<T extends WebElement>
extends AppiumDriver<T>
implements IOSDeviceActionShortcuts, GetsNamedTextField<T>,
FindsByIosUIAutomation<T> {
....
@SuppressWarnings("unchecked")
@Override
public T scrollTo(String text) {
return (T) ((ScrollsTo<?>) findElementByClassName("UIATableView"))
.scrollTo(text);
}
@SuppressWarnings("unchecked")
@Override
public T scrollToExact(String text) {
return (T) ((ScrollsTo<?>) findElementByClassName("UIATableView"))
.scrollToExact(text);
}
public T scrollToUsingPredicate(By scrollableElementBy, String iOSpredicate) {
return (T) findElementBy(scrollableElementBy)
.scrollToUsingPredicate(iOSpredicate);
}
public T scrollToUsingPredicate(String iOSpredicate) {
return scrollToUsingPredicate(By.className("UIATableView"), iOSpredicate);
}
....
}
public class IOSElement extends MobileElement
implements FindsByIosUIAutomation<MobileElement>, ScrollsTo<MobileElement> {
....
public MobileElement scrollToUsingPredicate(String iOSpredicate) {
return (IOSElement) findElementByIosUIAutomation(
".scrollToElementWithPredicate(\"" + iOSpredicate + ""\")");
}
@Override public MobileElement scrollTo(String text) {
return scrollToUsingPredicate("name CONTAINS '" + text + "'");
}
@Override public MobileElement scrollToExact(String text) {
return scrollToUsingPredicate("name == '" + text + "'");
}
....
} |
|
@SrinivasanTarget what do you think about this solution? @bootstraponline @Jonahss you can join to this discussion if you want. |
|
@TikhomirovSergey Apologies for the delay. Above suggested Android changes looks fine for me, Have few queries w.r.t iOS,
I think we need to use ByIosUIAutomation instead of By. Still not clear with this portion.Please clarify. |
|
Hi SrinivasanTarget and TikhomirovSergey (in alpha order), I'm just thinking aloud: #341 supposed to be fixed by #342, and #342 is supposed to be fixed by #366 For #341 the issue is scrollTo() and/or scrollToExact() can not be stopped at first occurrence at first glance, what's the root cause? For #342, the solution seems reasonable from my perspective. For #366, it's more like a new feature - just the methods have different names on two platforms, not ideal. -Bill |
|
@autoaim800 Thanks for your comments. Your observations are correct and the above tagged/discussed issues will be addressed. @TikhomirovSergey Have updated another possible iOS solution that works for all scrollable views now.Please have a look.Waiting for your comments:) |
|
Second Solution: *MobileBy will be re-fractored as you said above *IOSDriver will have below changes, Your thoughts on solution comitted and the second one? |
# The first commit's message is: Merge pull request #378 from TikhomirovSergey/rafael-chavez-xcuitesting addition to the PR #352 Alternative solution for scrollTo # This is the 2nd commit message: App path correction in Tests # This is the 3rd commit message: removed scrollToUsingAutomator # This is the 4th commit message: cleanup
|
I'm closing it according to #385 |
Change list
Added ScrollToUsingPredicates method for android and iOS
Types of changes
What types of changes are you proposing/introducing to Java client?
Put an
xin the boxes that applyDetails
ScrollTo - Existing method doesn't work for UIScrollableView.It works fine only for UITableView since it is hardcoded. This will again be re-fractored in upcoming commits in same PR.
Now introduced a new method "ScrollToUsingPredicates" for both android and iOS that enables user to define their own predicates that works fine for any scrollable views.
For Predicates in iOS refer:
1)https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/ios_predicate.md
2)https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSPredicate_Class/
For Android Scroll refer:
1)http://developer.android.com/reference/android/support/test/uiautomator/UiScrollable.html#scrollTextIntoView(java.lang.String)
@TikhomirovSergey Your thoughts on this?
As we discussed,this PR will continue to fix existing ScrollTo method.Will work on this.