Skip to content

Instantly share code, notes, and snippets.

@ptrthomas
Last active June 26, 2020 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptrthomas/b0f81875e30390e7c8c097b9a8e91b4e to your computer and use it in GitHub Desktop.
Save ptrthomas/b0f81875e30390e7c8c097b9a8e91b4e to your computer and use it in GitHub Desktop.
Feature:
Scenario: listen to system out and stop after 5 pings
* def count = 0
* def listener =
"""
function(line) {
var temp = karate.get('count');
if (line.contains('bytes from')) {
temp = temp + 1;
karate.set('count', temp);
karate.log('count is', temp);
}
if (temp == 5) {
var proc = karate.get('proc');
karate.signal(proc.buffer);
}
}
"""
* def proc = karate.fork({ args: ['ping', 'google.com'], listener: listener })
* def output = karate.listen(10000)
* print 'console output:', output
Scenario: java cli
* def proc = karate.fork('java -version')
* proc.waitSync()
* match proc.getBuffer() == '#regex java version (.+[\\r\\n])+'
* assert proc.getExitCode() == 0
Scenario: java fail
* def proc = karate.fork('java -foo')
* proc.waitSync()
* match proc.getBuffer() contains 'Unrecognized option: -foo'
* assert proc.getExitCode() == 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment