Skip to content

Commit

Permalink
chore: Expose standard xml source attributes in the corresponding step
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Jun 18, 2024
1 parent 2dc5c83 commit 2485649
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
20 changes: 2 additions & 18 deletions app/src/main/java/io/appium/uiautomator2/handler/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,26 @@

package io.appium.uiautomator2.handler;

import java.util.HashSet;
import java.util.Set;

import io.appium.uiautomator2.core.AccessibilityNodeInfoDumper;
import io.appium.uiautomator2.handler.request.SafeRequestHandler;
import io.appium.uiautomator2.http.AppiumResponse;
import io.appium.uiautomator2.http.IHttpRequest;
import io.appium.uiautomator2.utils.Attribute;

import static io.appium.uiautomator2.utils.AXWindowHelpers.refreshAccessibilityCache;
import static io.appium.uiautomator2.utils.Attribute.xmlExposableAttributes;

/**
* Get page source. Return as string of XML doc
*/
public class Source extends SafeRequestHandler {
private static final Set<Attribute> includedAttributes = new HashSet<>();

private static synchronized Set<Attribute> getXmlSourceAttributes() {
if (includedAttributes.isEmpty()) {
for (Attribute attribute : Attribute.values()) {
if (attribute.isExposableToXml()) {
includedAttributes.add(attribute);
}
}
}
return includedAttributes;
}

public Source(String mappedUri) {
super(mappedUri);
}

@Override
protected AppiumResponse safeHandle(IHttpRequest request) {
refreshAccessibilityCache();
String xmlSource = new AccessibilityNodeInfoDumper(null, getXmlSourceAttributes()).dumpToXml();
String xmlSource = new AccessibilityNodeInfoDumper(null, xmlExposableAttributes()).dumpToXml();
return new AppiumResponse(getSessionId(request), xmlSource);
}
}
20 changes: 17 additions & 3 deletions app/src/main/java/io/appium/uiautomator2/utils/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public enum Attribute {
CHECKABLE(new String[]{"checkable"}),
Expand Down Expand Up @@ -53,16 +55,18 @@ public enum Attribute {

private final String[] aliases;
// Defines if the attribute is visible to the user from getAttribute call
private boolean isExposable = true;
private final boolean isExposable;
// Defines if the attribute is visible to the user in the xml tree/xpath search
private boolean isExposableToXml = true;
private final boolean isExposableToXml;

Attribute(String[] aliases) {
this.aliases = aliases;
this.isExposable = true;
this.isExposableToXml = true;
}

Attribute(String[] aliases, boolean isExposable, boolean isExposableToXml) {
this(aliases);
this.aliases = aliases;
this.isExposable = isExposable;
this.isExposableToXml = isExposableToXml;
}
Expand Down Expand Up @@ -96,6 +100,16 @@ public static String[] exposableAliases() {
return result.toArray(new String[0]);
}

public static Set<Attribute> xmlExposableAttributes() {
Set<Attribute> result = new HashSet<>();
for (Attribute attribute : Attribute.values()) {
if (attribute.isExposableToXml) {
result.add(attribute);
}
}
return result;
}

@Nullable
public static Attribute fromString(String alias) {
if (alias == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
package io.appium.uiautomator2.utils.actions_scheduler;

import static io.appium.uiautomator2.utils.AXWindowHelpers.refreshAccessibilityCache;

import java.util.Collections;
import static io.appium.uiautomator2.utils.Attribute.xmlExposableAttributes;

import io.appium.uiautomator2.core.AccessibilityNodeInfoDumper;
import io.appium.uiautomator2.model.api.scheduled.ScheduledActionStepModel;
Expand Down Expand Up @@ -46,6 +45,6 @@ protected Object runInternalImplementation(String subtype) throws UnknownStepSub

private String fetchXmlSource() {
refreshAccessibilityCache();
return new AccessibilityNodeInfoDumper(null, Collections.emptySet()).dumpToXml();
return new AccessibilityNodeInfoDumper(null, xmlExposableAttributes()).dumpToXml();
}
}

0 comments on commit 2485649

Please sign in to comment.