Unable to create keydown and keyup action sequences for Android buttons
For some tests, I want to control the time between KeyDown and KeyUp events.
I working with custom hardware that has physical buttons mapped to Android keycodes for buttons. I can use PressKeyCode and simulate button presses like: driver.PressKeyCode(AndroidKeyCode.KeycodeButton_1);
I do not believe that this will work as the time between keydown and keyup will not be long enough for my purpose: driver.LongPressKeyCode(AndroidKeyCode.KeycodeButton_1);
What I want to do is something like this: var inputDevice = new KeyInputDevice(); var actionSequence = new ActionSequence(inputDevice, 0); actionSequence.AddAction(inputDevice.CreateKeyDown(AndroidKeyCode.KeycodeButton_1)); await Task.Delay(5000); actionSequence = new ActionSequence(inputDevice, 0); actionSequence.AddAction(inputDevice.CreateKeyUp(AndroidKeyCode.KeycodeButton_1));
Except, I want to use AndroidKeyCode instead of a character.
I tried to find a character that would work and found that any characters with an ASCII value > 127 throw an error. I have no way of controlling keydown and keyup timing for button key codes. Is there another way?
Environment
Android 10 c#/.NET Appium WebDriver 4.3.1 (nuget) Selenium driver 3.141.0 (nuget) Selenium Server 1.21.0 Testing on real device
Error when using characters > 127: Converge.AutomationTests.ConvergeAutomation.ButtonTest Source: ConvergeAutomation.cs line 266 Duration: 34.3 sec
Message: OpenQA.Selenium.WebDriverException : KeyCharacterMap.getEvents is unable to synthesize KeyEvent sequence out of '190' key code. Consider applying a patch to UiAutomator2 server code or try to synthesize the necessary key event(s) for it manually
Stack Trace:
RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters) AppiumDriver1.Execute(String driverCommandToExecute, Dictionary2 parameters) AppiumDriver1.PerformActions(IList`1 actionSequenceList)
ConvergeAutomation.ButtonTest() line 274
--- End of stack trace from previous location where exception was thrown ---
I don't think the Actions API is harmonized with the Android KeyCode enum. @mykola-mokhnach ?
No, they aren't. This is how keycodes mapping for W3C looks like: https://github.com/appium/appium-uiautomator2-server/blob/master/app/src/main/java/io/appium/uiautomator2/utils/w3c/W3CKeyCode.java
Also, it looks like your sequence is not looking good. Consider checking the server logs to make sure the generated actions chain JSON looks similar to https://github.com/appium/appium-uiautomator2-server/blob/cf8aff01834756c3e51c14c629be6a223b096fda/app/src/test/java/io/appium/uiautomator2/utils/w3c/W3CActionsTokenizationTests.java#L70
@kkohler2 does the recent answers assisted you?
I think I just can't do what I was trying to do with Appium.
@kkohler2 So can I close this issue?
Closed as no Response