peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.61k stars 238 forks source link

Automate user inputs #364

Closed physicalit closed 1 year ago

physicalit commented 1 year ago

Is your feature request related to a problem? Please describe. Is hard to automate user inputs

Describe the solution you'd like So, i have a complex tui made with asciimatics, where users add add informations in some fields or makes selections. I should be able to do same thing automatically from terminal with arguments or some kind of api. (Some rest API endpoints that are generated automatically from the TUI code would be awesome or similar.)

it can be useful for automatic testing also

peterbrittain commented 1 year ago

Thanks for the feedback! Can I try to clarify what you're looking for?

Have you looked at the automatic tests in asciimatics? If so, how does the testing that you're hoping to do compare to those tests? What additional features do you need to get started? Obviously, auto-generated REST APIs are a little further down the line! :-)

physicalit commented 1 year ago

Thanks for the fat replay. So, basically I have inherited a 2000 line files that is actually the asciimatics interface. At the end, it generates a json file based on user input. What i want to obtain, is an easy way to add the input automatically, without extract all the functionality from the existing python file. It will be harder to maintain, 2 files that do the same thing.

peterbrittain commented 1 year ago

Assuming your predecessor implemented the TUI as a separate class that could be imported, you could use the code in test_widgets.py to create the form without a real screen and then inject the necessary input to the form using the process_keys function method.

See https://github.com/peterbrittain/asciimatics/blob/31b3fe579af6ef08bcd8e01e33aeaf8d46805353/tests/test_widgets.py#L614 for an example of what I mean.

peterbrittain commented 1 year ago

I'm assuming that gave you what you needed... Pls shout if not.