Run

WebTau can run commands in foreground and in background . When command is ran in foreground WebTau will wait for the command to finish.To run a command use cli.run with a single string parameter that includes a command and all its arguments: cli.run('echo hello world')

Run With Validation

cli.run('echo hello world') { output.should contain('hello') output.should contain('world') } cli.run('scripts/error-output') { error.should == 'error B892T' } cli.run('scripts/exit-code 8') { exitCode.should == 8 exitCode.shouldNot == 0 }

Implicit Exit Code Validation

WebTau performs implicit exit code validation and adds exitCode equals zero when you don't specify explicit exitCode validation. cli.run('echo hello world') Example above is equivalent to cli.run('echo hello world') { exitCode.should == 0 }

Run Result

Use the result of cli.run if you need to process the output of the command. def result = cli.run('scripts/my-script') { exitCode.shouldNot == 0 } println result.output println result.error if (result.exitCode == 1) { // ... } Warning: Perform validation inside validation block so WebTau can track what was checked. def result = cli.run('scripts/generate-id') def id = result.extractFromOutputByRegexp("id=(\\d+)") def result = cli.run('scripts/generate-id') def id = result.extractFromErrorByRegexp("id=(\\d+)")

Working Dir

Use cli.workingDir as a second parameter to cli.run to set a working dir: cli.run('./listing', cli.workingDir('scripts')) { output.should contain('listing files') output.should contain('sleeps') }

Environment Variables

Use cli.env as a second parameter to cli.run to set the environment variables: #!/bin/bash echo "hello $MY_VAR" cli.run('scripts/hello-env-var', cli.env([MY_VAR: 'webtau'])) { output.should == 'hello webtau' }

Common Environment Variables

Set cliEnv config value with environment values that needs to be passed to each cli.run : cliEnv { MY_VAR = "webtau" PREFIX_VAR = "__" } cli.run('scripts/hello-env-var') { output.should == 'hello webtau' }

Chain Cli Run Config

Combine configs by using cli.env(...).workingDir(...) in any order to set both: cli.run('./hello-env-var', cli.workingDir('scripts').env([MY_VAR: 'webtau'])) { output.should == 'hello webtau' }

Path

To specify PATH to use for CLI commands lookup use cliPath = ['scripts/more']

Timeout

cli.run command fails if it doesn't complete in 30 seconds.To override default timeout use cliTimeout config value: cliTimeout = 400 To override timeout for a specific cli.run use cli.run("scripts/sleeps", cli.timeout(300)) Note: Timeout value is specified in milliseconds