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
Next Next commit
feat: add snapshotMaxDepth
yoshitaka-ogata committed Jun 19, 2023
commit 5e3dc0d76599cc8f8fc78463cf70f761762af862
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@
import io.appium.uiautomator2.model.internal.CustomUiDevice;
import io.appium.uiautomator2.model.settings.Settings;
import io.appium.uiautomator2.model.settings.SimpleBoundsCalculation;
import io.appium.uiautomator2.model.settings.SnapshotMaxDepth;
import io.appium.uiautomator2.utils.Logger;

import static io.appium.uiautomator2.utils.Device.getUiDevice;
@@ -48,8 +49,6 @@
* This class contains static helper methods to work with {@link AccessibilityNodeInfo}
*/
public class AxNodeInfoHelper {
// https://github.com/appium/appium/issues/12892
private static final int MAX_DEPTH = 70;
private static final long UNDEFINED_NODE_ID =
(((long) Integer.MAX_VALUE) << 32) | Integer.MAX_VALUE;
private static final int UNDEFINED_WINDOW_ID = -1;
@@ -233,7 +232,7 @@ public static int calculateIndex(AccessibilityNodeInfo node) {
}

/**
* Returns the node's bounds clipped to the size of the display, limited by the MAX_DEPTH
* Returns the node's bounds clipped to the size of the display, limited by the SnapshotMaxDepth
* The implementation is borrowed from `getVisibleBounds` method of `UiObject2` class
*
* @return Empty rect if node is null, else a Rect containing visible bounds
@@ -263,7 +262,7 @@ private static Rect getBounds(@Nullable AccessibilityNodeInfo node, Rect display
Set<AccessibilityNodeInfo> ancestors = new HashSet<>();
AccessibilityNodeInfo ancestor = node.getParent();
// An erroneous situation is possible where node parent equals to the node itself
while (++currentDepth < MAX_DEPTH && ancestor != null && !ancestors.contains(ancestor)) {
while (++currentDepth < Settings.get(SnapshotMaxDepth.class).getValue() && ancestor != null && !ancestors.contains(ancestor)) {
// If this ancestor is scrollable
if (ancestor.isScrollable()) {
// Trim any portion of the bounds that are hidden by the non-visible portion of our
Original file line number Diff line number Diff line change
@@ -44,7 +44,8 @@ public enum Settings {
MJPEG_SCALING_FACTOR(new MjpegScalingFactor()),
MJPEG_SERVER_SCREENSHOT_QUALITY(new MjpegServerScreenshotQuality()),
MJPEG_BILINEAR_FILTERING(new MjpegBilinearFiltering()),
USE_RESOURCES_FOR_ORIENTATION_DETECTION(new UseResourcesForOrientationDetection());
USE_RESOURCES_FOR_ORIENTATION_DETECTION(new UseResourcesForOrientationDetection()),
SNAPSHOT_MAX_DEPTH(new SnapshotMaxDepth());

private final ISetting<?> setting;

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appium.uiautomator2.model.settings;

public class SnapshotMaxDepth extends AbstractSetting<Integer> {
public static final String SETTING_NAME = "snapshotMaxDepth";
// https://github.com/appium/appium/issues/12892
private static final Integer DEFAULT_VALUE = 70;
private Integer snapshotMaxDepth = DEFAULT_VALUE;

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

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

@Override
public Integer getDefaultValue() {
return DEFAULT_VALUE;
}

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