1

I have a Karate test like this one. here I create an def = externalIdArray, and It has a view like -

 [print] ["COUNTRY","NAME","SURNAME","SEX", "ID"]

and after I want to put this data from externalIdArray to Examples section and run the tests where every variable from array will be replaced instead of "@@@PRODUCT_ID@@@" so it should be 5 tests. Is that possible to pass somehow the externalIdArray into examples?

Feature: Testing data

Background:

* def app = Java.type('library.classes.application')
* configure retry = { count: 4, interval: 5000 }
* def config = { username: 'username', password: 'password', url: 'url', driverClassName: 'oracle' }
* def DbUtils = Java.type('library.classes.dbUtils')
* def db = new DbUtils(config)
Scenario Outline: Testing data

* def externalIds = db.readRows('SELECT EXTERNAL_ID FROM PRODUCT')
* def externalIdArray = karate.map(externalIds, function(x){ return x.EXTERNAL_ID })
* print externalIdArray
* def requestID = app.GenerateRequestId()
* def createRequest = karate.read('../model/request.xml')
* replace createRequest
  | token              | value        |
  | @@@REQUEST_ID@@@   | requestID    |
  | @@@PRODUCT_ID@@@   | <externalId> |

* print createRequest

And request createRequest
And method post
And print response
Then status 200

Examples:
  | externalId        |
  | <externalIdArray> | ?????

I am expect all data from array will pass into examples section

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
HonzaNova
  • 11
  • 2

1 Answers1

0

I'm ignoring most of your example and focusing on the main question. Yes, you can use a simple array of strings as the basis for a data driven test. A simple example is below, please use that and you should get all your questions answered:

Feature:

  @setup
  Scenario:
    * def names = ["COUNTRY", "NAME", "SURNAME", "SEX", "ID"]
    * def data = names.map(x => ({ name: x }))

  Scenario Outline: name: ${name}
    * print 'name is:', name

    Examples:
      | karate.setup().data |

Please refer to the documentation: https://github.com/karatelabs/karate#setup

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248