简体   繁体   中英

In karate DSL how do i call javascript function in the 'Then' statement

I have written a JavaScript function but i'm unable to call it in the 'Then' statement of my request. I need the syntax to call a JavaScript function in the same

Background: 
* def randomPhoneString = function(list) {  var rand = Math.random();  Math.floor(rand * 100000000);}

Scenario: Get list 
Given path '/example/test'  
When method get 
Then status 200
Then def resp = response.list
Then def List = randomPhoneString(resp)

Not a great example but it would be a usecase like this. The error I'm getting is : javascript evaluation failed: randomPhoneString(list)

Yes, your example is terrible :P it is still not clear what you are trying to do. I just tried this and it worked:

* def randomPhoneString = function() { var rand = Math.random(); return Math.floor(rand * 100000000) + '' }
* def temp = randomPhoneString()
* print temp

It printed:

[print] 59303272

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM