Home > Enterprise >  How to use Karate * def data in js script in feature file
How to use Karate * def data in js script in feature file

Time:11-09

**Feature file code: ** `

  Scenario: Create Route
* def num = '3513113555'
* def details = "NAN"

  * text func  =
    """
   UserId,Details
    num ,details
    """

    * print func

`

Problem

on mentioned code snipped my def variable is considering as string also tried with " or ' or <>

I want to generate runtime CSV with some dynamic data and data is coming from a JSON / test file

CodePudding user response:

There is a way to convert JSON to CSV in Karate: https://github.com/karatelabs/karate#karate-tocsv

You already know how to create dynamic JSON in Karate. So it becomes simple:

* def num = '3513113555'
* def details = 'NAN'
* def users = []
* users.push({ num: num, details: details })
* def raw = karate.toCsv(users)
* print raw

For more advanced things, refer: https://stackoverflow.com/a/54593057/143475

  • Related