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

feat: add snapshotMaxDepth to be able to detect deep depth elements #517

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: use SnapshotMaxDepth in UiElementSnapshot
yoshitaka-ogata committed Jun 19, 2023
commit bdeca65fc8065c4aa508e1dc53fb1d94796ec00c
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@
import io.appium.uiautomator2.core.AxNodeInfoHelper;
import io.appium.uiautomator2.model.settings.AllowInvisibleElements;
import io.appium.uiautomator2.model.settings.IncludeExtrasInPageSource;
import io.appium.uiautomator2.model.settings.SnapshotMaxDepth;
import io.appium.uiautomator2.model.settings.Settings;
import io.appium.uiautomator2.utils.Attribute;
import io.appium.uiautomator2.utils.Logger;
@@ -55,8 +56,6 @@
@TargetApi(18)
public class UiElementSnapshot extends UiElement<AccessibilityNodeInfo, UiElementSnapshot> {
private final static String ROOT_NODE_NAME = "hierarchy";
// https://github.com/appium/appium/issues/12545
private final static int DEFAULT_MAX_DEPTH = 70;
// The same order will be used for node attributes in xml page source
public final static Attribute[] SUPPORTED_ATTRIBUTES = new Attribute[]{
Attribute.INDEX, Attribute.PACKAGE, Attribute.CLASS, Attribute.TEXT,
@@ -95,15 +94,15 @@ private UiElementSnapshot(AccessibilityNodeInfo node, int index, int depth, int

private UiElementSnapshot(AccessibilityNodeInfo node, int index, int depth,
Set<Attribute> includedAttributes) {
this(node, index, depth, DEFAULT_MAX_DEPTH, includedAttributes);
this(node, index, depth, Settings.get(SnapshotMaxDepth.class).getValue(), includedAttributes);
}

private UiElementSnapshot(AccessibilityNodeInfo[] childNodes,
Set<Attribute> includedAttributes) {
super(null);
this.depth = 0;
this.index = 0;
this.maxDepth = DEFAULT_MAX_DEPTH;
this.maxDepth = Settings.get(SnapshotMaxDepth.class).getValue();
Map<Attribute, Object> attribs = new LinkedHashMap<>();
putAttribute(attribs, Attribute.INDEX, this.index);
putAttribute(attribs, Attribute.CLASS, ROOT_NODE_NAME);
Original file line number Diff line number Diff line change
@@ -18,17 +18,19 @@

public class SnapshotMaxDepth extends AbstractSetting<Integer> {
public static final String SETTING_NAME = "snapshotMaxDepth";
// Set DEFAULT_VALUE as 70 to avoid StackOverflow from infinite recursion
// https://github.com/appium/appium/issues/12545
// https://github.com/appium/appium/issues/12892
private static final Integer DEFAULT_VALUE = 70;
private Integer snapshotMaxDepth = DEFAULT_VALUE;
private Integer value = DEFAULT_VALUE;

public SnapshotMaxDepth() {
super(Integer.class, SETTING_NAME);
}

@Override
public Integer getValue() {
return snapshotMaxDepth;
return value;
}

@Override
@@ -38,6 +40,6 @@ public Integer getDefaultValue() {

@Override
protected void apply(Integer value) {
snapshotMaxDepth = value;
this.value = value;
}
}