Matt Bangert
Matt Bangert

Reputation: 27

How to include a table value as part of URI?

I am attempting to add a table's value as part of a URI with Karate 0.9.0.RC4's and do not seem to be inheriting the value. The below example is a test for me trying to print out the passed table's value in the inherited feature file:

Test feature file

Scenario: Data Table Test
* table kittens
    | name       | age |
    | 'Bob'      | 2   |
    | 'Wild'     | 1   |
    | 'Nyan'     | 3   |
    | 'Keyboard' | 5   |
    | 'LOL'      | 3   |
    | 'Ceiling'  | 2   |

* def result = call read('comments-call.feature') kittens

Comments-Call.feature

@ignore
Feature: re-usable feature to create a single cat

Scenario:
* match __arg == kittens[__loop]

* print '#(name)'

In the log, I see the following:

14:30:55.714 [main] INFO  com.intuit.karate - found scenario at line: 
45 - ^Data Table Test$
14:30:55.879 [main] INFO  com.intuit.karate - [print] #(name)
14:30:55.902 [main] INFO  com.intuit.karate - [print] #(name)
14:30:55.929 [main] INFO  com.intuit.karate - [print] #(name)
14:30:55.947 [main] INFO  com.intuit.karate - [print] #(name)
14:30:55.961 [main] INFO  com.intuit.karate - [print] #(name)
14:30:55.971 [main] INFO  com.intuit.karate - [print] #(name)Karate 
version: 0.9.0.RC4

I am basing this off the example Data Driven Tests

Upvotes: 1

Views: 184

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58088

Just 2 points. Karate is pure JavaScript by default. So if you have a variable name in scope, this will work !

* print name

And please read the rules for embedded expressions carefully. The #(foo) system is designed to work only for templating within JSON and XML.

https://github.com/intuit/karate#rules-for-embedded-expressions

Upvotes: 2

Related Questions