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
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public String handle(AppiumParams params) throws AppiumException {
return Integer.toString(viewElement.getIndex());
case PACKAGE:
return viewElement.getPackageName();
case VIEW_TAG:
return viewElement.getViewTag();
default:
throw new NotYetImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withTagValue;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static io.appium.espressoserver.lib.viewmatcher.WithXPath.withXPath;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.instanceOf;

/**
* Helper methods to find elements based on locator strategies and selectors
Expand Down Expand Up @@ -141,7 +145,6 @@ private static List<View> findAllBy(@Nullable View root,
Strategy strategy, String selector, boolean findOne)
throws InvalidStrategyException, XPathLookupException {
List<View> views;

switch (strategy) {
case ID: // with ID

Expand Down Expand Up @@ -179,6 +182,9 @@ private static List<View> findAllBy(@Nullable View root,
views = getViews(root, withXPath(selector), false);
}
break;
case VIEW_TAG:
views = getViews(root, withTagValue(allOf(instanceOf(String.class), equalTo((Object) selector))), findOne);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why findOne? Cannot it be that two views have the same tag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findOne is a boolean variable... if it's false it will look for multiple instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should've be called shouldFindOne

break;
default:
throw new InvalidStrategyException(String.format("Strategy is not implemented: %s", strategy.getStrategyName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ private void buildXML(Document doc, Element parentElement, View view) {
setAttribute(element, ViewAttributesEnum.PASSWORD, Boolean.toString(viewElement.isPassword()));
setAttribute(element, ViewAttributesEnum.SELECTED, Boolean.toString(viewElement.isSelected()));
setAttribute(element, ViewAttributesEnum.BOUNDS, viewElement.getBounds().toShortString());

final ViewText viewText = viewElement.getText();
if (viewText != null) {
setAttribute(element, ViewAttributesEnum.TEXT, viewText.getRawText());
}
setAttribute(element, ViewAttributesEnum.RESOURCE_ID, viewElement.getResourceId());

if (view.getTag() != null) {
setAttribute(element, ViewAttributesEnum.VIEW_TAG, view.getTag().toString());
setAttribute(element, ViewAttributesEnum.VIEW_TAG, viewElement.getViewTag());
}

// If this is the rootElement, append it to the document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public enum Strategy {
ACCESSIBILITY_ID("accessibility id"),
@SerializedName("text")
TEXT("text"),

ANDROID_UIAUTOMATOR("-android uiautomator");
@SerializedName("-android viewtag")
VIEW_TAG("-android viewtag");

private final String strategyName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public enum ViewAttributesEnum {
INSTANCE,
INDEX,
ADAPTERS,
ADAPTER_TYPE, VIEW_TAG;
ADAPTER_TYPE,
VIEW_TAG;


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,6 @@ public class ViewElement {
public ViewElement(View view) {
this.view = view;

// TODO: Attributes that need to be added with examples
// resource-id android:id/decor_content_parent
// index 0
// package io.appium.android.apis
// content-desc
// checkable false
// checked false
// enabled true
// focusable false
// scrollable false
// password false
// selected false
// bounds [0,0][1440,2560]
// resource-id android:id/decor_content_parent
// instance 0
// visibility

}

public synchronized Activity extractActivity() {
Expand Down Expand Up @@ -248,4 +231,10 @@ public int getRelativeTop() {
public String getPackageName() {
return InstrumentationRegistry.getTargetContext().getPackageName();
}

@Nullable
public String getViewTag() {
Object tag = view.getTag();
return tag == null ? null : tag.toString();
}
}