Conditional goto
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Conditional goto
I dont have any experience with the Conditional goto step.
When I try to "run the current condition against the previous responce" I get: "Condition not true for current response in [Product_Details]"
my condition is:
exists(//id)
[Product_Details] JSON responce starts off as:
{ "id":"...
So I think "//id" should exist.
When I run the test, the log for the Conditional goto displays:
Tue Oct 20 14:37:29 CEST 2015: Missing matching condition, moving on.
Am I missing something?
Thanks,
Teak
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi again Teak,
Its not a direct answer to the issue with the conditional goto TestStep (not sure how well they work with JSON), but since you are doing well with your Groovy, I thought I'd suggest a Groovy alternative that I personally find more flexible:
import static com.jayway.jsonpath.JsonPath.parse def response = context.expand( '${REST Request#Response}' ) def id = parse(response).read('$.id') log.info id if (id!=null) testRunner.gotoStepByName("TestStepName")
So, instead of teh Conditional Goto TestStep, if you instead create a Groovy TestStep after your Request TestStep, then the above code shows how you could:
1) Get the response JSON from (in this case) a REST Request TestStep called REST Request.
2) Parse the JSON response using JSONPath
3) Test the value of id from the JSON document, and use the programatic equivalent of conditional goto.
Hope this helps,
Cheers,
Rupert
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi again Rupert,
Yes it doesnt answer the issue of goto but your solution is much more flexable.
Excellent I can do all my logic in the groovy script.
So I was able to:
import static com.jayway.jsonpath.JsonPath.parse def response = context.expand( '${Product Details#Response}' ) def ratings_down = parse(response).read('$.ratings.down') log.info ratings_down if (ratings_down!=1) testRunner.gotoStepByName("Rating down") else testRunner.gotoStepByName("Rating DELETE")
Thanks a lot.
Teak
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Teak,
Excellent - glad you're happy with the Groovy alternative, should hopefully serve you well! 🙂
Thanks again for sharing the solution and marking the post as complete.
Cheers,
Rup
