678
6 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
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
I am not only using Login and Logout i have other scenarios also where i need to call some rest request frequently as a pre-req
example ... create user, edit user, etc.,
Scenarios ; Testcase 1 : Step 1 (Login Rest Request)
Step 2 ( create user Rest Request)
Step 3 (do some validiations)
Step 4 (logout Rest Request)
Testcase 2: Step 1( Login Rest Request)
Step 2 ( create user Rest Request)
Step 3 (Do some validations )
Step 4 (logout Rest Request)
on the above scenarios login, create, logout are repeatable REST Requests... any help appreciated for solution