Release all holding keys
I have multiple test cases that will run automatically. One of my case, i need to hold Ctrl key (for example) and do some mouse actions. Unexpectedly, an exception occurred and that case is stopped with the Ctrl key is still holding. All the cases that run afterward will be run with holding Ctrl key environment and failed.
Up to now, i have 2 solutions:
- In any test case that holds a key, i push it in a try/catch/finally block. Implement the releasing keys logic in finally block.
- Storing a static data or a sharing storage between test cases that will store any holding keys. When test cleanup logic is called, it will release any keys in that storage.
The 2nd solution looks better. My question: Does WinAppDriver has a builtin solution for my case?
I think that you're looking for this: https://seleniumhq.github.io/selenium/docs/api/dotnet/html/T_OpenQA_Selenium_Interactions_Actions.htm
I know how to use Action and for sure, i have to use it to stimulate keyboard/mouse actions. However, none of them help me. The most relating things i can imagine are using KeyUp and KeyDown. I have thought that i can call KeyUp on all modifier keys (Ctrl, Alt, Windows, Shift) but it still fail. In case i just hold Ctrl, at the end of test, i call KeyUp on (Ctrl, Alt, Windows, Shift), it will release Ctrl but hold Alt, Windows and Shift.