1

I have got the response in the background to one of the request and passing to the function for polling purpose and need to run until specific condition met. In that function, I need to pass the values to the calling feature JSON file

  while (true) {
  var result = karate.call('extractProgress.feature') packageid; -- package id 

is response of another request

I followed the similar way as mentioned but in that not passing any parameter. https://github.com/intuit/karate/blob/933d3803987a736cc1a38893e7039c4b5e5132fc/karate-demo/src/test/java/demo/polling/polling.feature

But i am getting the below error

feature(com.intuit.karate.testng.KarateTestngTest): java.lang.RuntimeException: javascript evaluation failed: packageid, ReferenceError: "packageid" is not defined in at line number 1

Jayendran
  • 9,638
  • 8
  • 60
  • 103

2 Answers2

1

Input for call inside js should be given as

karate.call("<featureFile>",yourInputVaraible);

refer this on doc https://github.com/intuit/karate#the-karate-object

Babu Sekaran
  • 4,129
  • 1
  • 9
  • 20
  • its correct way of passing arguments? var result = karate.call('extractProgress.feature','#(packageid)'); I tried with '' still i get the same error – user1980552 Oct 04 '18 at 15:56
  • var packageId = {"packageid":packageid}; var result = karate.call('extractProgress.feature',packageId ); – Babu Sekaran Oct 04 '18 at 16:06
  • '#(packageId)' this way of assigning json values from variables only works on feature file. – Babu Sekaran Oct 04 '18 at 16:07
  • @ here I followed the similar logic as mentioned in below url but the loop is never ending once the condition has met it should stop but again its calling the same scenario again. Any idea on that? https://github.com/intuit/karate/blob/933d3803987a736cc1a38893e7039c4b5e5132fc/karate-demo/src/test/java/demo/polling/polling.feature – user1980552 Oct 05 '18 at 12:14
  • your above code says its while(true), this would always be an infinite loop unless until you have a valid break/ return condition inside your loop, the code also has an if-condition for breaking the while loop (if (greeting.id == x). make sure you have a valid condition (please refer Answer 2 in this : 'https://stackoverflow.com/questions/52596736/how-to-add-conditional-wait-for-a-response-in-karate') – Babu Sekaran Oct 05 '18 at 12:51
  • got it, let me try it out.Thank You again – user1980552 Oct 05 '18 at 12:59
  • I followed the same as you mentioned still its looping even after 1st time is completed function(status) { var actualstatus = null while (actualstatus != 'Complete') { var packageId = {"packageid": packageid}; var result = karate.call('extractProgress.feature',packageId); var greeting = result.response; if(greeting.payload.progressStatus == status) { actualstatus = greeting.payload.progressStatus return;} actualstatus = greeting.payload.progressStatus java.lang.Thread.sleep(100); } } """ – user1980552 Oct 05 '18 at 14:16
  • this is the scenario: after that function: * def packageId = packageid * def result = call read('Progress.feature') {packageid: '#(packageId)'} * def current = result.response * def status = 'Complete' * call waitUntil status – user1980552 Oct 05 '18 at 14:16
  • This look like a javascript related question. Can you please create a question under javascript and karate tags – Babu Sekaran Oct 05 '18 at 15:11
  • ok sure. Thank You but i see the tags are separated. It doesn't have javascript and karate – user1980552 Oct 05 '18 at 15:16
  • posted it by adding both tags, – user1980552 Oct 05 '18 at 15:30
0

It sounds wrong to me, maybe you have a typo.

Also please read the docs carefully. Only JSON is supported as a call argument.

The best way for you to get support is to follow this process, else no one can help you with the limited info you seem to be providing in your questions.

https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Sure. I tried to add sample code but it throwing error so that is the reason i questioned in a wage – user1980552 Oct 04 '18 at 15:11
  • Given url 'url1' And request someJson When method POST Then status 200 And def packageid = response.payload.packageID * def waitUntil = """ function(status) { while (true) { var result = karate.call('extractProgress.feature') {packageid: '#(packageid)' }; var greeting = result.response; if(greeting.payload.progressStatus == status) { return;} java.lang.Thread.sleep(100); } } """ As mentioned above the passing of variable to the function is correct? – user1980552 Oct 04 '18 at 15:17
  • are you trying to pass the varaible packageid as an input to your feature file ? – Babu Sekaran Oct 04 '18 at 15:18
  • Answered :@user1980552 – Babu Sekaran Oct 04 '18 at 15:28
  • Any idea how to use it? – user1980552 Oct 04 '18 at 15:29
  • refer my answer below or [karate Doc](https://github.com/intuit/karate#the-karate-object) – Babu Sekaran Oct 04 '18 at 15:30