There is several different ways to do this. I personally have a UI that controls my automation script that allows me to go step by step (in record mode or playback), full automation or however I like. Just build a UI to control the flow and then have different functions that can be controlled by the UI as needed.
For example, a step by step UI would do a function called nextStep() nextStep would find the next desired step and perform that action.
A fully automated one would check a boolean for true while automating and as long as it's true, it keeps going. Set up a pause/stop button that changes that boolean and that is done.
In order to create functionality like this, in a simplistic way:
Create a UI that lists out your test steps, how you do this is up to you. I made mine editable and drag and drop within a table (JTree for Suites, JList for Cases, JTable for Steps).
Add Stop and Play ToggleButtons on the UI in a button group Add an actionEventListener to the play button that grabs the selected step(s) and runs them. Between each step have it check that the play button is still selected. When it is no longer selected, the execution will stop.
For things like groovy script just add in a groovy console and create a trigger (IE. Keyword being Groovy=script) and then have the console parse that whenever it sees it.
I also added in keywords like screenshot, pause, wait and such. This gives the ability for the system to stop automatically until user intervention occurs.