cancel
Showing results for 
Search instead for 
Did you mean: 

Reusable REST Requests

Regular 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

 

 

10 REPLIES 10
Community Hero

Re: Reusable REST Requests

It is good practice that each test case is independent.
Can you elaborate your use case please?


Regards,
Rao.
Regular Contributor

Re: Reusable REST Requests

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) 

 

 

Community Hero

Re: Reusable REST Requests

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? Smiley Happy

 

There are a couple of Sample SoapUI projects available with SoapUI.  These have something similar to above that I mentioned.

 

Cheers,

 

richie

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Regular Contributor

Re: Reusable REST Requests

@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 ?

 

Community Hero

Re: Reusable REST Requests

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

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Community Hero

Re: Reusable REST Requests

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

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Regular Contributor

Re: Reusable REST Requests

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

                                    

Community Hero

Re: Reusable REST Requests

Hi,

in that case I think the 'Run testcase' step is your only option and carefully think of your strategy for configuring your preconditional test cases accordingly. ive always had a problem with test rrdundancy with this sort of thing...theres no point repeating test steps that do the same test multiple times within a single build of software (e.g. test login works more than once) and this is especially significant for manual testing. however due to the speed that automated tools allow us to test with, it mitigates the issue of repeating test steps multiple times despite it not adding value.

so. yeah. in summary. wrap up the actions you want to repeat multiple times throughout your testsuite into separate test cases and for call these repeatable actions via the 'run testcase' step in your use cases tests.

richie
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Regular Contributor

Re: Reusable REST Requests

@richie 

 

as per your suggestion i used run Testcase step but properties are not returning from that runtest case like i am grabing a token from login request (Runtestcase step) i checked return properties but properties are coming as empty