Skip to content

Commit

Permalink
Remove ineffectiveness Configurator settings (#50)
Browse files Browse the repository at this point in the history
- Timeout for `action_acknowledgment`, `scroll_acknowledgment`, and
`wait_for_selector` have no effect on UiObject2.
- Timeout for `key_injection_delay` is deprecated.
  • Loading branch information
ko1in1u authored Jun 26, 2024
1 parent 46e2e3b commit 4e881db
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 172 deletions.
18 changes: 3 additions & 15 deletions docs/configurator.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,19 @@ ad.services.register(

## Timeout

By default, Snippet UiAutomator will set `wait_for_selector` to 0 seconds, which
means there will be no waiting for a widget matched by a selector to become
visible.
By default, Snippet UiAutomator will set `wait_for_idle` to 0 seconds, which
means there will be no waiting for the user interface to go into an idle
state before starting a uiautomator action.

Timeouts can be also customized via passing
[datetime.timedelta](https://docs.python.org/3/library/datetime.html#timedelta-objects).

- [key_injection_delay](https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setKeyInjectionDelay\(long\))

- [action_acknowledgment](https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setActionAcknowledgmentTimeout\(long\))

- [scroll_acknowledgment](https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setScrollAcknowledgmentTimeout\(long\))

- [wait_for_idle](https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setWaitForIdleTimeout\(long\))

- [wait_for_selector](https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setWaitForSelectorTimeout\(long\))

```python
configurator = uiautomator.Configurator(
timeout=uiautomator.Timeout(
key_injection_delay=datetime.timedelta(seconds=0),
action_acknowledgment=datetime.timedelta(seconds=0),
scroll_acknowledgment=datetime.timedelta(seconds=0),
wait_for_idle=datetime.timedelta(seconds=0),
wait_for_selector=datetime.timedelta(seconds=0),
)
)
ad.services.register(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
package com.google.android.mobly.snippet.uiautomator;

import androidx.test.uiautomator.Configurator;

import com.google.android.mobly.snippet.Snippet;
import com.google.android.mobly.snippet.rpc.Rpc;
import com.google.android.mobly.snippet.uiautomator.Info.ConfiguratorInfo;

import org.json.JSONException;

/**
Expand All @@ -37,34 +35,9 @@ public class ConfiguratorSnippet implements Snippet {
@Rpc(description = "Gets all properties of Configurator.")
public ConfiguratorInfo getConfigurator() {
return ConfiguratorInfo.create(
/* actionAcknowledgmentTimeout= */ configurator.getActionAcknowledgmentTimeout(),
/* keyInjectionDelay= */ configurator.getKeyInjectionDelay(),
/* scrollAcknowledgmentTimeout= */ configurator.getScrollAcknowledgmentTimeout(),
/* toolType= */ configurator.getToolType(),
/* uiAutomationFlags= */ configurator.getUiAutomationFlags(),
/* waitForIdleTimeout= */ configurator.getWaitForIdleTimeout(),
/* waitForSelectorTimeout= */ configurator.getWaitForSelectorTimeout());
}

@Rpc(
description =
"Gets the current timeout for waiting for an acknowledgment of generic uiautomator"
+ " actions, such as clicks, text setting, and menu presses.")
public long getActionAcknowledgmentTimeout() {
return configurator.getActionAcknowledgmentTimeout();
}

@Rpc(description = "Gets the current delay between key presses when injecting text input.")
public long getKeyInjectionDelay() {
return configurator.getKeyInjectionDelay();
}

@Rpc(
description =
"Gets the timeout for waiting for an acknowledgement of an uiautomator scroll swipe"
+ " action.")
public long getScrollAcknowledgmentTimeout() {
return configurator.getScrollAcknowledgmentTimeout();
/* waitForIdleTimeout= */ configurator.getWaitForIdleTimeout());
}

@Rpc(description = "Gets the current tool type to use for motion events.")
Expand All @@ -87,25 +60,8 @@ public long getWaitForIdleTimeout() {
return configurator.getWaitForIdleTimeout();
}

@Rpc(
description =
"Gets the current timeout in milliseconds for waiting for a widget to become visible in"
+ " the user interface so that it can be matched by a selector.")
public long getWaitForSelectorTimeout() {
return configurator.getWaitForSelectorTimeout();
}

@Rpc(description = "Sets up Configurator.")
public void setConfigurator(ConfiguratorInfo config) throws JSONException {
if (config.actionAcknowledgmentTimeout() != null) {
configurator.setActionAcknowledgmentTimeout(config.actionAcknowledgmentTimeout());
}
if (config.keyInjectionDelay() != null) {
configurator.setKeyInjectionDelay(config.keyInjectionDelay());
}
if (config.scrollAcknowledgmentTimeout() != null) {
configurator.setScrollAcknowledgmentTimeout(config.scrollAcknowledgmentTimeout());
}
if (config.toolType() != null) {
configurator.setToolType(config.toolType());
}
Expand All @@ -115,30 +71,6 @@ public void setConfigurator(ConfiguratorInfo config) throws JSONException {
if (config.waitForIdleTimeout() != null) {
configurator.setWaitForIdleTimeout(config.waitForIdleTimeout());
}
if (config.waitForSelectorTimeout() != null) {
configurator.setWaitForSelectorTimeout(config.waitForSelectorTimeout());
}
}

@Rpc(
description =
"Sets the timeout for waiting for an acknowledgment of generic uiautomator actions, such"
+ " as clicks, text setting, and menu presses.")
public void setActionAcknowledgmentTimeout(long timeoutInMillis) {
configurator.setActionAcknowledgmentTimeout(timeoutInMillis);
}

@Rpc(description = "Sets a delay between key presses when injecting text input.")
public void setKeyInjectionDelay(long delayInMillis) {
configurator.setKeyInjectionDelay(delayInMillis);
}

@Rpc(
description =
"Sets the timeout for waiting for an acknowledgement of an uiautomator scroll swipe"
+ " action.")
public void setScrollAcknowledgmentTimeout(long timeoutInMillis) {
configurator.setScrollAcknowledgmentTimeout(timeoutInMillis);
}

@Rpc(description = "Sets the current tool type to use for motion events.")
Expand All @@ -159,14 +91,6 @@ public void setWaitForIdleTimeout(long timeoutInMillis) {
configurator.setWaitForIdleTimeout(timeoutInMillis);
}

@Rpc(
description =
"Sets the timeout for waiting for a widget to become visible in the user interface so"
+ " that it can be matched by a selector.")
public void setWaitForSelectorTimeout(long timeoutInMillis) {
configurator.setWaitForSelectorTimeout(timeoutInMillis);
}

@Override
public void shutdown() throws JSONException {
setConfigurator(defaultConfiguratorInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,9 @@ public JSONObject serialize(Object object) throws JSONException {
return obj;
} else if (object instanceof ConfiguratorInfo) {
ConfiguratorInfo configuratorInfo = (ConfiguratorInfo) object;
obj.put("actionAcknowledgmentTimeout", configuratorInfo.actionAcknowledgmentTimeout());
obj.put("keyInjectionDelay", configuratorInfo.keyInjectionDelay());
obj.put("scrollAcknowledgmentTimeout", configuratorInfo.scrollAcknowledgmentTimeout());
obj.put("toolType", configuratorInfo.toolType());
obj.put("uiAutomationFlags", configuratorInfo.uiAutomationFlags());
obj.put("waitForIdleTimeout", configuratorInfo.waitForIdleTimeout());
obj.put("waitForSelectorTimeout", configuratorInfo.waitForSelectorTimeout());
return obj;
} else if (object instanceof UiDeviceInfo) {
UiDeviceInfo uiDeviceInfo = (UiDeviceInfo) object;
Expand Down Expand Up @@ -98,19 +94,9 @@ public Object deserialize(JSONObject jsonObject, Type type) throws JSONException
return new Selector(jsonObject);
} else if (type == ConfiguratorInfo.class) {
return ConfiguratorInfo.create(
jsonObject.has("actionAcknowledgmentTimeout")
? jsonObject.getLong("actionAcknowledgmentTimeout")
: null,
jsonObject.has("keyInjectionDelay") ? jsonObject.getLong("keyInjectionDelay") : null,
jsonObject.has("scrollAcknowledgmentTimeout")
? jsonObject.getLong("scrollAcknowledgmentTimeout")
: null,
jsonObject.has("toolType") ? jsonObject.getInt("toolType") : null,
jsonObject.has("uiAutomationFlags") ? jsonObject.getInt("uiAutomationFlags") : null,
jsonObject.has("waitForIdleTimeout") ? jsonObject.getLong("waitForIdleTimeout") : null,
jsonObject.has("waitForSelectorTimeout")
? jsonObject.getLong("waitForSelectorTimeout")
: null);
jsonObject.has("waitForIdleTimeout") ? jsonObject.getLong("waitForIdleTimeout") : null);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,38 +125,12 @@ public static RectInfo create(int top, int bottom, int left, int right) {
public abstract static class ConfiguratorInfo {

public static ConfiguratorInfo create(
@Nullable Long actionAcknowledgmentTimeout,
@Nullable Long keyInjectionDelay,
@Nullable Long scrollAcknowledgmentTimeout,
@Nullable Integer toolType,
@Nullable Integer uiAutomationFlags,
@Nullable Long waitForIdleTimeout,
@Nullable Long waitForSelectorTimeout) {
return new AutoValue_Info_ConfiguratorInfo(
actionAcknowledgmentTimeout,
keyInjectionDelay,
scrollAcknowledgmentTimeout,
toolType,
uiAutomationFlags,
waitForIdleTimeout,
waitForSelectorTimeout);
@Nullable Long waitForIdleTimeout) {
return new AutoValue_Info_ConfiguratorInfo(toolType, uiAutomationFlags, waitForIdleTimeout);
}

/**
* Returns the current timeout in milliseconds for waiting for an acknowledgment of generic
* uiautomator actions.
*/
abstract @Nullable Long actionAcknowledgmentTimeout();

/** Returns the current delay in milliseconds between key presses when injecting text input. */
abstract @Nullable Long keyInjectionDelay();

/**
* Returns the timeout in milliseconds for waiting for an acknowledgement of an uiautomator
* scroll swipe action.
*/
abstract @Nullable Long scrollAcknowledgmentTimeout();

/** Returns the current tool type to use for motion events. */
abstract @Nullable Integer toolType();

Expand All @@ -168,12 +142,6 @@ public static ConfiguratorInfo create(
* into an idle state.
*/
abstract @Nullable Long waitForIdleTimeout();

/**
* Returns the current timeout in milliseconds for waiting for a widget to become visible in the
* user interface so that it can be matched by a selector.
*/
abstract @Nullable Long waitForSelectorTimeout();
}

/** Corresponds to the properties of androidx.test.uiautomator.UiDevice. */
Expand Down
Binary file modified snippet_uiautomator/android/app/uiautomator.apk
Binary file not shown.
31 changes: 0 additions & 31 deletions snippet_uiautomator/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import functools
from typing import Mapping, Optional, Sequence

from snippet_uiautomator import constants
from snippet_uiautomator import utils


Expand Down Expand Up @@ -72,25 +71,11 @@ class Timeout:
"""Indicates timers to wait for UiAutomator to take specific actions.
Attributes:
key_injection_delay: Delay time between key presses when injecting text
input.
action_acknowledgment: Wait for an acknowledgment of generic uiautomator
actions. Generally, this timeout should not be modified.
scroll_acknowledgment: Wait for an acknowledgement of an uiautomtor scroll
swipe action. Generally, this timeout should not be modified.
wait_for_idle: Wait for the user interface to go into an idle state before
starting a uiautomator action.
wait_for_selector: Wait for a widget to become visible in the user interface
so that it can be matched by a selector.
"""

key_injection_delay: Optional[datetime.timedelta] = None
action_acknowledgment: Optional[datetime.timedelta] = None
scroll_acknowledgment: Optional[datetime.timedelta] = None
wait_for_idle: Optional[datetime.timedelta] = None
wait_for_selector: datetime.timedelta = (
constants.DEFAULT_WAIT_FOR_SELECTOR_TIMEOUT
)


@dataclasses.dataclass(frozen=True)
Expand Down Expand Up @@ -123,25 +108,9 @@ def to_dict(self) -> Mapping[str, int]:
lambda x, y: x | y, self.flags
)

if self.timeout.action_acknowledgment is not None:
config['actionAcknowledgmentTimeout'] = utils.covert_to_millisecond(
self.timeout.action_acknowledgment
)
if self.timeout.key_injection_delay is not None:
config['keyInjectionDelay'] = utils.covert_to_millisecond(
self.timeout.key_injection_delay
)
if self.timeout.scroll_acknowledgment is not None:
config['scrollAcknowledgmentTimeout'] = utils.covert_to_millisecond(
self.timeout.scroll_acknowledgment
)
if self.timeout.wait_for_idle is not None:
config['waitForIdleTimeout'] = utils.covert_to_millisecond(
self.timeout.wait_for_idle
)
if self.timeout.wait_for_selector is not None:
config['waitForSelectorTimeout'] = utils.covert_to_millisecond(
self.timeout.wait_for_selector
)

return config

0 comments on commit 4e881db

Please sign in to comment.