How to use 'faker' libraries in karate framework?

China☆狼群 提交于 2020-05-31 02:06:50

问题


I'd like to use the 'faker' library to generate fake data in JSON file as below.

In karate-config.js, I do the following:

var faker = require('faker');

In sample.json:

{
    'firstName': '#(faker.name.firstName)'
    'city'     : '#(faker.address.city)'
}

But I'm getting error like 'unable to find 'require' keyword in 'karate-config.js'

Please help on this.


回答1:


Karate does not support NPM or the require keyword. For complex custom logic, the recommendation is to use Java interop.

My suggestion is you should find a Java library that does what "faker" does and integrate it.




回答2:


thanks for your response and suggestion, tried below and working fine.

in karate-config.js:

var faker = Java.type('.FakerClass');

......

config.faker = faker;

in sample.json:

{ 'name': '#(faker.address.city)' }



来源:https://stackoverflow.com/questions/52099988/how-to-use-faker-libraries-in-karate-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!