Home > Mobile >  How do we execute an async feature test call on karate?
How do we execute an async feature test call on karate?

Time:09-21

I want to run a long-running api call and subsequently, kill it using another api call. I have tried the following methods:

* def longQuery = async function() { karate.call('this:submit-long-running-sync-query.feature', {queryID: queryID})}
* karate.eval(longQuery())

This does not eval the async function and only returns when it timesout.

* def longQuery = function() { karate.call('this:submit-long-running-sync-query.feature', {queryID: queryID})}
* eval new java.lang.Thread(karate.toJava(longQuery)).start()

Caused by host exception: com.intuit.karate.KarateException: The value 'DynamicObject<JSFunction>@4bc59b27' cannot be passed from one context to another. 
* def longQuery = function() { karate.call('this:submit-long-running-sync-query.feature', {queryID: queryIDtest})}
* eval new java.lang.Thread(longQuery).start()

Exception in thread "Thread-1" java.lang.IllegalStateException: Multi threaded access requested by thread Thread[Thread-1,5,main] but is not allowed for language(s) js

How do we execute an async feature test call on karate?

CodePudding user response:

No, Karate's JS engine is a bit "different" and async is not supported.

For these advanced cases the recommendation is to write a bit of Java "glue" code (one-time only). Please refer to this as an example: https://twitter.com/getkarate/status/1417023536082812935

  • Related