How to integrate cucumber with Python language

2019-08-14 16:54发布

问题:

I have few scenarios which needs some data manipulation for Assertion. I know, it can be done by Java Script. But I wish to create a Utility file for custom reusable functions. Is there any possibility to integrate with Python through which Utility function can be called.

回答1:

I strongly advise against it.

If you really want, you might be able to call a command-line python program like this:

* def FileUtils = Java.type('com.intuit.karate.FileUtils')
* def runtime = java.lang.Runtime.getRuntime()
* def exec = function(cmd){ return FileUtils.toString(runtime.exec(cmd).getInputStream()) }
* def result = exec('my-python-command')

Of course if you are able to expose your Python utils as a REST-API, that's another option :)

But please don't do this.