REPL Console

Branko Juric edited this page Jul 17, 2017 · 18 revisions

Gwen logo The Gwen REPL Console

Gwen comes with a REPL (Read-Eval-Print-Loop) console. This is a command line shell that prompts you for steps, evaluates them, and then prints their results. You can use it to evaluate individual steps or complete feature files. This gives you the ability to experiment and observe the execution of steps and features as you work on writing them. The scoped data in memory can also be printed to the console at any time for debugging and analysis. The REPL also saves every step and command you type to a local history file. So you can use the up and down arrows to recall previous inputs. Help is also available by typing help (which lists all available commands and what they do). Tab completion support is provided too. All of this makes the REPL a very powerful tool for authoring features and verifying their execution before committing them to an automation cycle.

   __ ___      _____ _ __     _    
  / _` \ \ /\ / / _ \ '_ \   { \," 
 | (_| |\ V  V /  __/ | | | {_`/   
  \__, | \_/\_/ \___|_| |_|   `    
  |___/                            
                                   
Welcome to gwen-web v2.6.0

INFO - Initialising environment context
INFO - WebEnvContext initialised
INFO - gwen-web.sh 

REPL Console

Enter steps to evaluate or type exit to quit..

gwen>

See it in Action:

REPL Commands

Once in the REPL, you can type help at the gwen> prompt at anytime to list available commands.

Gwen REPL commands:

help
  Displays this help text

env [switch] ["filter"]
  Lists attributes in the current environment
    Only lists visible attributes if no options are specified
    switch :
      -a : to list all attributes in all scopes
      -f : to list all attributes in the feature (global) scope
    filter : literal string or regex filter expression

:paste|paste
   Enters paste mode (for evaluating multiline steps)

history
  Lists all previously entered commands

!<#>
  Executes a previously entered command (history bang operator)
    # : the history command number

Given|When|Then|And|But <step>
  Evaluates a step
    step : the step expression

exit|quit|bye
  Closes the REPL session and exits

ctrl-D
   If in past mode: exits paste mode and interprets provided steps
   Otherwise: Closes REPL session and exits

<tab>
  Press tab key at any time for tab completion

Tab Completion

You can press the tab key at any time to see all the available commands and the supported DSL in your installed engine. Tab completion is also available on any custom @StepDefs that you may have loaded. Use the tab key to narrow down and auto complete as you type.

Paste Mode

The REPL console evaluates steps as you type them in and press enter. This works well for single-line steps, but what about multi-line steps that contain Data Tables or Doc Strings like this one for example?

Given I have the following active items
      | Walk the dog |
      | Get the milk |
      | Feed the cat |

If you type the above into the REPL, you will find that the first line will evaluate (and fail) as soon as you press the Enter key before giving you a chance to start typing in the second line. To address this, we have introduced a 'paste' mode.

To use paste mode, just type :paste into the REPL prompt. The following will appear..

gwen> :paste

REPL Console (paste mode)

Enter or paste steps and press ctrl-D to evaluate..

Enter or paste multiple lines containing the step (or steps) you wish to evaluate..

Given I have the following active items
      | Walk the dog |
      | Get the milk |
      | Feed the cat |

On an empty line at the end, press cntl-D. The REPL will evaluate everything you entered and return to the standard prompt.

Exiting paste mode, interpreting now..

gwen> Given I have the following active items
            | Walk the dog |
            | Get the milk |
            | Feed the cat |

INFO - Evaluating Step: Given I have the following active items
...
REPL Console

Enter steps to evaluate or type exit to quit..

gwen>

You can exit the paste mode at any time by pressing cntl-D on the last empty line. If you never entered or pasted any steps, then nothing will execute. But if you did they will.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.