678
7 years agoRegular Contributor
Reusable REST Requests
I have a scenarios where i need to call some Frequently use REST Requests in other test cases How can i setup this , i am using READYAPI
sample use case
Project 1
Test Suite 1(Common)
Login In - Test Case (Rest Request)
Logout - Test Case (Rest Request)
Test Suite 2 (Actual Test cases)
Test Case (Add User - Rest Request) (Pre-Requisite need to run above Login Request) then test case (adduser) and Logout Request
Test Case (Delete User - Rest Request) (Same like above)
Hi,
erm - I don't know if I'm looking at the question from the wrong perspective - but it's reminding me of a question one of my colleagues asked me.
They were looking at setting up SoapUI using their experience of setting up a front end automation frameworks - e.g. modular/test library automation framework where you have lots of 'scripts' doing actions/navigation through an application which then makes up a larger testcase. Are you considering your question from a similar perspective?
Someone's bound to know more than me - but as far as I can tell, SoapUI doesn't really lend itself to modularizing a test case built from other testscripts like this. Just because you need a login (and perhaps a logout request) to enable you to exercise the other apis for your tests - you'll just end up wrapping the test case requests testing the other api's with the login and logout request. What I mean by this is if you had a 'search' and 'buy' api to test you'd just create a test case like the following hierarchy
Login REST Request Search REST Request Buy REST Request Logout REST Request
OR - have I totally gone off on one and totally misinterpreted your question? :)
There are a couple of Sample SoapUI projects available with SoapUI. These have something similar to above that I mentioned.
Cheers,
richie
Thanks for reply,
with your solution i need to add Login and log out on every test case
and more ever my framework is such a way that all the test case is coming from excel
excel rows:
Row 1 - Test case 1 -Search Request
Row 2 - Test case 2 - Buy Request
in this case what is the solution ?
Hi,
Essentially "yes" is the answer to whether you would need a login request on each test case - that is - as long as there are session variables in the login response you need to pass onto your subsequent requests to enable the other requests to work?
How long does the 'session' (after logging in) last? 15minutes?
Is there a reason you couldn't create a login request in your first test case in your first testsuite, then grab the session variables from the login response passing them to a project property perhaps and then just use these session variables for your other apis you are testing for your other testsuite's testcases so you don't bother logging in for each test and logging out after every test?
If your 'session' lasts 15minutes - depending on your tests/network latency etc., etc. you could possibly only need to login once per execution run.
what I mean by this is the following hierarchy
TestSuite1
TestSuite1 TestCase1 'Login Request' (grab session variables and pass these variables into project or TestSuite1 properties) TestCase2 'Datasource' (fileContents property created) 'Search Request' (using the session variables via the project/TestSuite1 properties, grab values from response to pass to SearchID property) 'Properties' (contains the SearchID property from the Search Request) 'Purchase Request' (uses project properties, SearchID propoerty and the ${Datasource#fileContents})
and final TestCase's final step would be the 'Logout Request' to close the session etc.
Can you be a bit more specific about what you mean by "all the test case is coming from excel"? I'm not really understanding what you mean.
Are you saying the test cases have been defined in a spreadsheet?
Are you saying the test data for the requests for your tests are defined in a spreadsheet?
thanks,
richie
Hi,
I've just been going through earlier posts on the forum and there is something that might help?
there is a 'run testcase' teststep that would allow you to source your login and logout requests.
e.g
Testsuite1 Testcase1 (login) 'Login Request' step Testcase2 (logout) 'Logout Request' step Testcase3 (use case1) 'Run Testcase' step (call Testcase1 (login)) 'Datasource' step (fileContents property) 'Search Request' step (${Datasource#fileContents}) set Recordid property from response 'Buy Request' step (${Search Request#Recordid}) 'Run Testcase' step (call Testcase2 (logout))
Although this approach would only really save you time If the login and logout tests had more steps in them - if the 'preconditional' test cases (login/logout) actually had more than 1 step in them. If there were >1 step in each test - then I suppose doing it this way would save time, effort but with single test step test cases for login/logout it doesnt really save you anything.
Cheers,
richie