androidx.test.uiautomator.Configurator Java Examples

The following examples show how to use androidx.test.uiautomator.Configurator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UiTestActions.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
public static void clickWebViewText(String text, Integer waitTimeout) {
    Configurator configurator = Configurator.getInstance();
    long originalTimeout = configurator.getWaitForSelectorTimeout();

    configurator.setWaitForSelectorTimeout(waitTimeout);

    try {
        onDevice(withContentDescription(text)).perform(click());
    } catch (RuntimeException e) {
        if (e.getCause() instanceof UiObjectNotFoundException) {
            onDevice(withText(text)).perform(click());
        } else {
            throw e;
        }
    } finally {
        configurator.setWaitForSelectorTimeout(originalTimeout);
    }
}
 
Example #2
Source File: UiTestActions.java    From braintree_android with MIT License 6 votes vote down vote up
public static void clickWebViewText(String text, Integer waitTimeout) {
    Configurator configurator = Configurator.getInstance();
    long originalTimeout = configurator.getWaitForSelectorTimeout();

    configurator.setWaitForSelectorTimeout(waitTimeout);

    try {
        onDevice(withText(text)).perform(click());
    } catch (RuntimeException e) {
        if (e.getCause() instanceof UiObjectNotFoundException) {
            onDevice(withContentDescription(text)).perform(click());
        } else {
            throw e;
        }
    } finally {
        configurator.setWaitForSelectorTimeout(originalTimeout);
    }
}
 
Example #3
Source File: BaseTest.java    From appium-uiautomator2-server with Apache License 2.0 6 votes vote down vote up
/**
 * start io.appium.uiautomator2.server and launch the application main activity
 */
@BeforeClass
public static void startServer() throws JSONException, IOException {
    if (serverInstrumentation != null) {
        return;
    }
    assertNotNull(getUiDevice());
    ctx = InstrumentationRegistry.getInstrumentation().getContext();
    serverInstrumentation = ServerInstrumentation.getInstance();
    Logger.info("Starting Server");
    serverInstrumentation.startServer();
    Client.waitForNettyStatus(NettyStatus.ONLINE);
    createSession();
    Configurator.getInstance().setWaitForSelectorTimeout(0);
    Configurator.getInstance().setWaitForIdleTimeout(50000);
    TestUtils.grantPermission(getApplicationContext(), READ_EXTERNAL_STORAGE);
    TestUtils.grantPermission(getApplicationContext(), WRITE_EXTERNAL_STORAGE);
}
 
Example #4
Source File: ServerInstrumentation.java    From appium-uiautomator2-server with Apache License 2.0 6 votes vote down vote up
private void setAccessibilityServiceState() {
    String disableSuppressAccessibilityService = InstrumentationRegistry.getArguments().getString("DISABLE_SUPPRESS_ACCESSIBILITY_SERVICES");
    if (disableSuppressAccessibilityService == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        return;
    }

    boolean shouldDisableSuppressAccessibilityService = Boolean.parseBoolean(disableSuppressAccessibilityService);
    if (shouldDisableSuppressAccessibilityService) {
        Configurator.getInstance().setUiAutomationFlags(
                UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES);
    } else {
        // We can disable UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES
        // only when we set the value as zero
        Configurator.getInstance().setUiAutomationFlags(0);
    }
}
 
Example #5
Source File: ComplexUiActionHandler.java    From android-uiconductor with Apache License 2.0 6 votes vote down vote up
/** Helper function to obtain a MotionEvent. */
private static MotionEvent getMotionEvent(long downTime, long eventTime, int action,
    float x, float y) {

  PointerProperties properties = new PointerProperties();
  properties.id = 0;
  properties.toolType = Configurator.getInstance().getToolType();

  PointerCoords coords = new PointerCoords();
  coords.pressure = 1;
  coords.size = 1;
  coords.x = x;
  coords.y = y;

  return MotionEvent.obtain(downTime, eventTime, action, 1,
      new PointerProperties[] { properties }, new PointerCoords[] { coords },
      0, 0, 1.0f, 1.0f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
}
 
Example #6
Source File: UiMultiSlider.java    From MultiSlider with Apache License 2.0 5 votes vote down vote up
public boolean setThumbValue(int value) throws UiObjectNotFoundException {
    AccessibilityNodeInfo ani =
            findAccessibilityNodeInfo(Configurator.getInstance().getWaitForSelectorTimeout());
    if (ani == null) {
        throw new UiObjectNotFoundException(getSelector().toString());
    }
    Bundle args = new Bundle();
    args.putInt("value", value);
    return ani.performAction(ACT_SET_PROGRESS, args);
}
 
Example #7
Source File: UiMultiSlider.java    From MultiSlider with Apache License 2.0 5 votes vote down vote up
public boolean moveThumbBackward() throws UiObjectNotFoundException {
    AccessibilityNodeInfo ani =
            findAccessibilityNodeInfo(Configurator.getInstance().getWaitForSelectorTimeout());
    if (ani == null) {
        throw new UiObjectNotFoundException(getSelector().toString());
    }
    return ani.performAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
}
 
Example #8
Source File: UiMultiSlider.java    From MultiSlider with Apache License 2.0 5 votes vote down vote up
public boolean moveThumbForward() throws UiObjectNotFoundException {
    AccessibilityNodeInfo ani =
            findAccessibilityNodeInfo(Configurator.getInstance().getWaitForSelectorTimeout());
    if (ani == null) {
        throw new UiObjectNotFoundException(getSelector().toString());
    }
    return ani.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
}
 
Example #9
Source File: WaitForSelectorTimeoutTests.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    waitForSelectorTimeout = new WaitForSelectorTimeout();
    PowerMockito.mockStatic(Configurator.class);
    when(Configurator.getInstance()).thenReturn(configurator);
    when(configurator.setWaitForSelectorTimeout(anyLong())).thenReturn(configurator);
}
 
Example #10
Source File: WaitForIdleTimeoutTests.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    waitForIdleTimeout = new WaitForIdleTimeout();
    PowerMockito.mockStatic(Configurator.class);
    when(Configurator.getInstance()).thenReturn(configurator);
    when(configurator.setWaitForIdleTimeout(anyLong())).thenReturn(configurator);
}
 
Example #11
Source File: KeyInjectionDelayTests.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    keyInjectionDelay = new KeyInjectionDelay();
    PowerMockito.mockStatic(Configurator.class);
    when(Configurator.getInstance()).thenReturn(configurator);
    when(configurator.setKeyInjectionDelay(anyLong())).thenReturn(configurator);
}
 
Example #12
Source File: UiObjectElement.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
public String getResourceId() {
    String resourceId = "";

    try {
        /*
         * Unfortunately UiObject does not implement a getResourceId method.
         * There is currently no way to determine the resource-id of a given
         * element represented by UiObject. Until this support is added to
         * UiAutomater, we try to match the implementation pattern that is
         * already used by UiObject for getting attributes using reflection.
         * The returned string matches exactly what is displayed in the
         * UiAutomater inspector.
         */
        AccessibilityNodeInfo node = (AccessibilityNodeInfo) invoke(method(element.getClass(), "findAccessibilityNodeInfo", long.class),
                element, Configurator.getInstance().getWaitForSelectorTimeout());

        if (node == null) {
            throw new UiObjectNotFoundException(element.getSelector().toString());
        }

        resourceId = node.getViewIdResourceName();
    } catch (final Exception e) {
        Logger.error("Exception: " + e + " (" + e.getMessage() + ")");
    }

    return resourceId;
}
 
Example #13
Source File: ScrollAcknowledgmentTimeoutTests.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    scrollAcknowledgmentTimeout = new ScrollAcknowledgmentTimeout();
    PowerMockito.mockStatic(Configurator.class);
    when(Configurator.getInstance()).thenReturn(configurator);
    when(configurator.setScrollAcknowledgmentTimeout(anyLong())).thenReturn(configurator);
}
 
Example #14
Source File: ActionAcknowledgmentTimeoutTests.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    actionAcknowledgmentTimeout = new ActionAcknowledgmentTimeout();
    PowerMockito.mockStatic(Configurator.class);
    when(Configurator.getInstance()).thenReturn(configurator);
    when(configurator.setActionAcknowledgmentTimeout(anyLong())).thenReturn(configurator);
}
 
Example #15
Source File: WaitForSelectorTimeout.java    From appium-uiautomator2-server with Apache License 2.0 4 votes vote down vote up
@Override
public Long getValue() {
    return Configurator.getInstance().getWaitForSelectorTimeout();
}
 
Example #16
Source File: ActionAcknowledgmentTimeout.java    From appium-uiautomator2-server with Apache License 2.0 4 votes vote down vote up
@Override
public Long getValue() {
    return Configurator.getInstance().getActionAcknowledgmentTimeout();
}
 
Example #17
Source File: WaitForSelectorTimeout.java    From appium-uiautomator2-server with Apache License 2.0 4 votes vote down vote up
@Override
protected void apply(Long timeout) {
    Configurator.getInstance().setWaitForSelectorTimeout(timeout);
}
 
Example #18
Source File: ScrollAcknowledgmentTimeout.java    From appium-uiautomator2-server with Apache License 2.0 4 votes vote down vote up
@Override
protected void apply(Long timeout) {
    Configurator.getInstance().setScrollAcknowledgmentTimeout(timeout);
}
 
Example #19
Source File: ScrollAcknowledgmentTimeout.java    From appium-uiautomator2-server with Apache License 2.0 4 votes vote down vote up
@Override
public Long getValue() {
    return Configurator.getInstance().getScrollAcknowledgmentTimeout();
}
 
Example #20
Source File: WaitForIdleTimeout.java    From appium-uiautomator2-server with Apache License 2.0 4 votes vote down vote up
@Override
protected void apply(Long timeout) {
    Configurator.getInstance().setWaitForIdleTimeout(timeout);
}
 
Example #21
Source File: WaitForIdleTimeout.java    From appium-uiautomator2-server with Apache License 2.0 4 votes vote down vote up
@Override
public Long getValue() {
    return Configurator.getInstance().getWaitForIdleTimeout();
}
 
Example #22
Source File: KeyInjectionDelay.java    From appium-uiautomator2-server with Apache License 2.0 4 votes vote down vote up
@Override
protected void apply(Long timeout) {
    Configurator.getInstance().setKeyInjectionDelay(timeout);
}
 
Example #23
Source File: KeyInjectionDelay.java    From appium-uiautomator2-server with Apache License 2.0 4 votes vote down vote up
@Override
public Long getValue() {
    return Configurator.getInstance().getKeyInjectionDelay();
}
 
Example #24
Source File: ActionAcknowledgmentTimeout.java    From appium-uiautomator2-server with Apache License 2.0 4 votes vote down vote up
@Override
protected void apply(Long timeout) {
    Configurator.getInstance().setActionAcknowledgmentTimeout(timeout);
}