Skip to content
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

Predicate locator added in IOSDriver, IOSElement, and iOSFindBy #475

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/io/appium/java_client/ios/IOSDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static io.appium.java_client.MobileCommand.prepareArguments;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.FindsByIosNSPredicate;
import io.appium.java_client.FindsByIosUIAutomation;
import io.appium.java_client.ios.internal.JsonToIOSElementConverter;
import io.appium.java_client.remote.MobilePlatform;
Expand Down Expand Up @@ -50,7 +51,7 @@
public class IOSDriver<T extends WebElement>
extends AppiumDriver<T>
implements IOSDeviceActionShortcuts,
FindsByIosUIAutomation<T>, LocksIOSDevice {
FindsByIosUIAutomation<T>, FindsByIosNSPredicate<T>, LocksIOSDevice {

private static final String IOS_PLATFORM = MobilePlatform.IOS;

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/appium/java_client/ios/IOSElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package io.appium.java_client.ios;

import io.appium.java_client.FindsByIosNSPredicate;
import io.appium.java_client.FindsByIosUIAutomation;
import io.appium.java_client.MobileElement;

public class IOSElement extends MobileElement
implements FindsByIosUIAutomation<MobileElement> {
implements FindsByIosUIAutomation<MobileElement>,
FindsByIosNSPredicate<MobileElement> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ enum Strategies {
return super.getBy(annotation);
}
},
BYPREDICATE("predicate") {
@Override By getBy(Annotation annotation) {
String value = getValue(annotation, this);
if (annotation.annotationType().equals(iOSFindBy.class)) {
return MobileBy.iOSNsPredicateString(value);
}
return super.getBy(annotation);
}
},
BYACCESSABILITY("accessibility") {
@Override By getBy(Annotation annotation) {
return MobileBy.AccessibilityId(getValue(annotation, this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* element or a list of elements. Used in conjunction with
* {@link org.openqa.selenium.support.PageFactory}
* this allows users to quickly and easily create PageObjects.
* using iOS UI selectors, accessibility, id, name, class name, tag and xpath
* using iOS UI selectors, predicate, accessibility, id, name, class name, tag and xpath
*/
@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.TYPE})
public @interface iOSFindBy {
Expand All @@ -38,6 +38,13 @@
*/
String uiAutomator() default "";

/**
* It is a properly formatted string for an NSPredicate.
* {@link "https://developer.apple.com/library/content/documentation/Cocoa/
* Conceptual/Predicates/AdditionalChapters/Introduction.html"}
*/
String predicate() default "";

/**
* It an UI automation accessibility Id which is a convenient to iOS.
* About iOS accessibility
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/io/appium/java_client/ios/IOSElementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public class IOSElementTest extends BaseIOSTest {
.findElementByIosUIAutomation(".elements().withName(\"Answer\")").getText(), null);
}

@Test public void findByPredicateTest() {
assertNotEquals(((IOSElement) driver.findElementsByClassName("UIAWindow")
.get(1))
.findElementByIosNsPredicate("label CONTAINS 'Compute'").getText(), null);
}

@Test public void setValueNunslaughterTest() {
IOSElement slider = (IOSElement) driver.findElementByClassName("UIASlider");
slider.setValue("0%");
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/io/appium/java_client/ios/IOSSearchingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ public class IOSSearchingTest extends BaseIOSTest {
.findElementsByIosUIAutomation(".elements().withName(\"Answer\")")
.size(), 0);
}

@Test public void findByPredicateTest() {
assertNotEquals(driver
.findElementByIosNsPredicate("label CONTAINS 'Compute'")
.getText(), null);
assertNotEquals(driver
.findElementsByIosNsPredicate("label CONTAINS 'Compute'")
.size(), 0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class IOSPageFactoryTest {

@iOSFindBy(uiAutomator = ".elements()[0]") private List<WebElement> iosUIAutomatorButtons;

@iOSFindBy(predicate = "label CONTAINS 'Compute'") private List<WebElement> iosPredicateButtons;

@iOSFindBy(uiAutomator = ".elements()[0]") @AndroidFindBy(className = "android.widget.TextView")
private List<WebElement> androidOriOsTextViews;

Expand All @@ -87,6 +89,8 @@ public class IOSPageFactoryTest {

@iOSFindBy(uiAutomator = ".elements()[0]") private WebElement iosUIAutomatorButton;

@iOSFindBy(predicate = "label CONTAINS 'Compute'") private WebElement iosPredicateButton;

@AndroidFindBy(className = "android.widget.TextView") @iOSFindBy(uiAutomator = ".elements()[0]")
private WebElement androidOriOsTextView;

Expand Down Expand Up @@ -216,6 +220,14 @@ public class IOSPageFactoryTest {
assertNotEquals(null, iosUIAutomatorButton.getText());
}

@Test public void iosFindByPredicateElementsTest() {
assertNotEquals(0, iosPredicateButtons.size());
}

@Test public void iosFindByPredicateElementTest() {
assertNotEquals(null, iosPredicateButton.getText());
}

@Test public void areMobileElementsTest() {
assertNotEquals(0, mobileButtons.size());
}
Expand Down