Karate test with Different Request Parameters using Replace

50 Views Asked by At

Anyone know how to run this Karate test, with different parameters? Test was working before I added the table with parameters, using hard coded value 'USA'.

@tag1
Scenario: Business User Sign Up
  * table regions
    | region |
    | 'USA'  |
  Given header Content-Type = applicationJsonHeader
  When url identitySignUpUrl
  And header Authorization = auth
  * def requestBody = read('classpath:resources/test.json')
  * replace requestBody.userName = userNameInput
  * replace requestBody.phoneNumber = phoneNumberInput
  * replace requestBody.country = '#(region)'
  And request requestBody
  When method POST
  Then status 200
  * def errors = response.errors
  And match errors == '#null'
  * print response

This doesnt seem to work https://github.com/karatelabs/karate#data-driven-features

1

There are 1 best solutions below

0
Peter Thomas On BEST ANSWER

I rewrote your test below. I think you are missing some fundamentals, so please go through the documentation: https://github.com/karatelabs/karate#data-driven-tests

You were certainly using replace in the wrong way - and where it was not required.

Scenario Outline: business user sign up
* def body = { foo: 'bar' }
* body.region = region
# this will also work
# def body = { foo: 'bar', region: '#(region)' }

* url 'https://httpbin.org/post'
* request body
* method post
* status 200    

Examples:
  | region |
  | usa    |