Ready API integration with cucumber
- 3 years ago
Hey harry
There was a link I'm trying to find (SmartBear published it) a while back about BDDs in ReadyAPI - struggling to find it right now (but I'll summarise the article below) - but the following link uses the petstore example project as the basis for ReadyAPI BDDs --> https://github.com/SmartBear/testserver-cucumber
Regarding the resource I cant find quite now - the summary of the article was as follows:
1. Prefix the names of your test steps using GIVEN, WHEN, THEN - e.g. for a POST step - it might be called 'WHEN - POST Request', etc.
2. REMEMBER! Most REST clients/API testing tools will submit a request and a response is returned on that request and the assertions are saved ON that request. If you think about it - this doesn't work if you want to split out your test steps from the perspective of the Gherkin syntax of GIVEN, WHEN & THEN - cos the WHEN (when the request is submitted) and the THEN (the expected results - the assertions) are on the same test step object within your test case. Hence the one of the main reasons I don't think BDDs work as well in a REST client/API testing tools. HOWEVER - ReadyAPI! includes an 'Assertion' test step object - which should allow you to separate out the WHEN and THEN statements - cos using the Assertion test step - this allows you to have separate test step objects with the correct WHEN and THEN prefix.
So your testcase hierarchy might be as follows:
If you have a testcase that uses the DataSource (file type), followed by a PropertyTransfer direct to a POST REST step - if not using Gherkin syntax, your testcase would appear as follows in your TestSuite object
TestSuite
----TestCase
---------DataSource(filetype)
---------POST Request
HOWEVER - if you want to create the above testcase using BDDs - your testcase would appear something like the following:
TestSuite
------TestCase
------'GIVEN - DataSource'
------'WHEN - POST Request'
------'THEN - Assertion Step'
I've never actually used the Assertion step before and my laptop's getting wiped as I type - so I cant check if the Assertion Step supports >1 assertion at a type - if it doesn't and you wanted to assert on say 2 items for example, your test case would appear as follows:
TestSuite
------TestCase
------'GIVEN - DataSource'
------'WHEN - POST Request'
------'THEN - Assertion Step'
------'AND THEN - Assertion Step'
Cheers,
Rich