Skip to content
Merged
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
46 changes: 33 additions & 13 deletions src/main/java/io/appium/java_client/AppiumBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.io.Serializable;
import java.util.List;

@SuppressWarnings("serial")
public abstract class AppiumBy extends By implements Remotable {

@Getter private final Parameters remoteParameters;
Expand All @@ -38,7 +37,6 @@ protected AppiumBy(String selector, String locatorString, String locatorName) {
this.locatorName = locatorName;
}

@SuppressWarnings("unchecked")
@Override public List<WebElement> findElements(SearchContext context) {
return context.findElements(this);
}
Expand All @@ -48,7 +46,7 @@ protected AppiumBy(String selector, String locatorString, String locatorName) {
}

@Override public String toString() {
return String.format("AppiumBy.%s: %s", locatorName, remoteParameters.value());
return String.format("%s.%s: %s", AppiumBy.class.getSimpleName(), locatorName, remoteParameters.value());
}

/**
Expand Down Expand Up @@ -115,6 +113,26 @@ public static By className(final String selector) {
return new ByClassName(selector);
}

/**
* For IOS the element name.
* For Android it is the resource identifier.
* @param selector element id
* @return an instance of {@link ById}
*/
public static By id(final String selector) {
return new ById(selector);
}

/**
* For IOS the element name.
* For Android it is the resource identifier.
* @param selector element id
* @return an instance of {@link ByName}
*/
public static By name(final String selector) {
return new ByName(selector);
}

/**
* This type of locator requires the use of the 'customFindModules' capability and a
* separately-installed element finding plugin.
Expand Down Expand Up @@ -165,70 +183,72 @@ public static By iOSNsPredicateString(final String iOSNsPredicateString) {
}

public static class ByAccessibilityId extends AppiumBy implements Serializable {

public ByAccessibilityId(String accessibilityId) {
super("accessibility id", accessibilityId, "accessibilityId");
}
}

public static class ByAndroidDataMatcher extends AppiumBy implements Serializable {

protected ByAndroidDataMatcher(String locatorString) {
super("-android datamatcher", locatorString, "androidDataMatcher");
}
}

public static class ByAndroidUIAutomator extends AppiumBy implements Serializable {

public ByAndroidUIAutomator(String uiautomatorText) {
super("-android uiautomator", uiautomatorText, "androidUIAutomator");
}
}

public static class ByAndroidViewMatcher extends AppiumBy implements Serializable {

protected ByAndroidViewMatcher(String locatorString) {
super("-android viewmatcher", locatorString, "androidViewMatcher");
}
}

public static class ByAndroidViewTag extends AppiumBy implements Serializable {

public ByAndroidViewTag(String tag) {
super("-android viewtag", tag, "androidViewTag");
}
}

public static class ByClassName extends AppiumBy implements Serializable {
public static class ById extends AppiumBy implements Serializable {
protected ById(String selector) {
super("id", selector, "id");
}
}

public static class ByName extends AppiumBy implements Serializable {
protected ByName(String selector) {
super("name", selector, "name");
}
}

public static class ByClassName extends AppiumBy implements Serializable {
protected ByClassName(String selector) {
super("class name", selector, "className");
}
}

public static class ByCustom extends AppiumBy implements Serializable {

protected ByCustom(String selector) {
super("-custom", selector, "custom");
}
}

public static class ByImage extends AppiumBy implements Serializable {

protected ByImage(String b64Template) {
super("-image", b64Template, "image");
}
}

public static class ByIosClassChain extends AppiumBy implements Serializable {

protected ByIosClassChain(String locatorString) {
super("-ios class chain", locatorString, "iOSClassChain");
}
}

public static class ByIosNsPredicate extends AppiumBy implements Serializable {

protected ByIosNsPredicate(String locatorString) {
super("-ios predicate string", locatorString, "iOSNsPredicate");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,17 @@ enum Strategies {
},
BYID("id") {
@Override By getBy(Annotation annotation) {
return By.id(getValue(annotation, this));
return AppiumBy.id(getValue(annotation, this));
}
},
BYTAG("tagName") {
@Override By getBy(Annotation annotation) {
return By
.tagName(getValue(annotation, this));
return By.tagName(getValue(annotation, this));
}
},
BYNAME("name") {
@Override By getBy(Annotation annotation) {
return By
.name(getValue(annotation, this));
return AppiumBy.name(getValue(annotation, this));
}
},
BYXPATH("xpath") {
Expand Down