Skip to content

Commit

Permalink
added example for karate.fromString() in js block #1202
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas committed Jul 13, 2020
1 parent 2f8765b commit 12f2b98
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,23 @@ Scenario: java pojo to xml
Scenario: parsing json, xml or string
* def temp = karate.fromString('{ "foo": "bar" }')
* assert temp.json
* match (temp.value) == { foo: 'bar' }
* match temp.value == { foo: 'bar' }
* def temp = karate.fromString('<foo>bar</foo>')
* assert temp.xml
* match (temp.value) == <foo>bar</foo>
* match temp.value == <foo>bar</foo>
* def temp = karate.fromString('random text')
* assert temp.string
* match (temp.value) == 'random text'
* match temp.value == 'random text'

Scenario: parsing json, xml or string within a js block
* eval
"""
var temp = karate.fromString('{ "foo": "bar" }');
if (!temp.json) karate.fail('expected json');
var val = temp.asMap;
var res = karate.match(val, { foo: 'bar' });
if (!res.pass) karate.fail(res.message);
"""

Scenario: inspecting an arbitrary object
* def foo = { foo: 'bar' }
Expand Down

0 comments on commit 12f2b98

Please sign in to comment.