Long press on power button by UiAutomator

action long press
appium click button
touch perform
mobileelement tap
two finger tap in appium
appium touch action scroll
tap in appium ruby
self driver tap

How achieve long press on power button (KeyEvent 26 ) to get a power menu by UiAutomator ?

Below,it is long press home button solution,and it works.Maybe you can attempt to use power KeyCode instead of mDevice.pressHome().

public void longPressHome(){
    long timeout = Configurator.getInstance().getActionAcknowledgmentTimeout();
    Configurator.getInstance().setActionAcknowledgmentTimeout(0);
    mDevice.pressHome();
    mDevice.pressHome();
    Configurator.getInstance().setActionAcknowledgmentTimeout(timeout);
}

Long press on power button by UiAutomator, Below,it is long press home button solution,and it works.Maybe you can attempt to use power KeyCode instead of mDevice.pressHome(). public void  The power button is a hard button, in your example there a long pressing of virtual button on the Ui device. – user3741350 Jun 19 '16 at 18:25 The power button is a hard button, in your example there a long pressing of virtual button on the Ui device.

I solved this using reflection:

Class<?> clazz = mDevice.getClass();
Method getUiAutomation = clazz.getDeclaredMethod("getUiAutomation");
getUiAutomation.setAccessible(true);

((UiAutomation) getUiAutomation.invoke(mDevice)).performGlobalAction(GLOBAL_ACTION_POWER_DIALOG);

android: Long press on power button by UiAutomator, How achieve long press on power button (KeyEvent 26 ) to get a power menu by UiAutomator ? This method simulates pressing the power button if the screen is OFF else it does nothing if the screen is already ON. If the screen was OFF and it just got turned ON, this method will insert a 500ms delay to allow the device time to wake up and accept input.

To tackle this- Please try this tool.Android Record N Play . Record your power button long press. And run with the tool. Or push the xxx.mes file to phone and run adb shell sh xxx.mes to run separately. I tested on Galaxy s6, it works fine. if you face any problem please comment here. I can fix the issue.

you can call the adb shell sh comamnd from uiautomator.

How to long press certain time a power button using adb event , The problem I'm trying to hold power button using adb command key for certain not work first just clicks does not long press and with touchscreen fails. {"​strategy":"-android uiautomator","selector":"adb shell input keyevent  Press and Hold is not supported officially on uiautomator, so currently I can only put it as an enhancement but no plan on it. A workaround is to use adb shell input keyevent --longpress or adb shell sendevent.

Long Press, Edit this Doc Long Tap. Long press on the touch screen using finger motion events longPress(element); action.perform(); UiAutomator, 4.3+, All, All. Edit this Doc Long Tap Long press on the touch screen using finger motion events. Example Usage

uiautomator/library/src/com/android/uiautomator/core/UiDevice.java , pressing hardware buttons such as DPad or the soft buttons such as Home and Menu. */. public class private static final long DEFAULT_TIMEOUT_MILLIS = 10 * 1000; This method simply presses the power button if the screen is OFF else. The way to start a session using the UiAutomator driver is to include the platformName capability in your new session request, with the value Android. Of course, you must also include appropriate platformVersion , deviceName , and app capabilities, at a minimum.

Long press keycode, README · Power ac · Power capacity README · Button down · Button up · Click · Doubleclick · Moveto Long Press Key Code. Press and hold a particular key code on the device Editing for this document happens in /commands-yml/​commands/device/keys/long-press-keycode.yml) // wd UiAutomator, 4.2+, All, All. Once you completed the steps, every time you press the power button your computer will respond to the new action. Depending on the hardware and device you own the settings available will be different.

Comments
  • This long press example might give you some ideas -
  • The power button is a hard button , in your example there a long pressing of virtual button on the Ui device.