2

This is my current Karate test scenario. I am posting a message using REST API and then validating it in certain tables in the database. By default status in a database table goes to wait . After 30 sec-1 min a batch job processes it and changes it to either success or failure status. How do I capture this part? in the below code:- if finalstatus = Success, its passed and if its changed to failed, the TC is failed.

* url apiurl
  And request data
  When method POST
  Then status 200
  * def id11 = db.readRows('select id1, payload1 from test1 where id = \'' + response + '\'')
  And eval Thread.sleep(600)
  And match id11.id1 == response
  And match id11.payload1 == data
  * def id22 = db.readRows('select id2,  msg2 from test2 where id2 = \'' + response + '\'')
  And eval Thread.sleep(400)
  And match id22.id2 == response
  And eval Thread.sleep(300)
  * def xmlPayload = dba.readRows('select top 1 final_id, payload, status  from test3 order by  final_id desc')
  * def xml = xmlPayload[0].payload
  * def happyid = xmlPayload[0]. final_id
* def finalstatus = xmlPayload[0].status

  Examples:
    | read('data.json') |
Kavi
  • 87
  • 1
  • 5

1 Answers1

1

Two suggestions:

  1. look at retry until: https://stackoverflow.com/a/55823180/143475

  2. Use a polling loop instead of a sleep.

Since you have already used Java code to implement db.readRows() etc, I suggest you just add one or two more utility methods to wait for what you want, and you have full control of calling the database, looping etc.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248