0

I am doing API testing. I already have a test script for API testing. But, now the business introduced the concept of roles and permission.

For example, there is one user (SuperAdmin), and there are APIs for Create Users, View Users, Update Users, and Delete Users.

Initially, it was fine without the introduction of roles and permission.

Now, the business has introduced a new user Admin, and Admin can only view users.

How can I achieve multiple user roles/permission in my script without having a drastic changes?

Note: there are more than 100 API samplers in my script.

kishor sharma
  • 179
  • 2
  • 17

2 Answers2

0

Its not very clear what you're asking.

Normally you should be using different Thread Groups to represent different logical groups of business users so you need to have:

  1. Thread Group of "super admins" which has access to all endpoints
  2. Thread Group of "admins" which has access to view users endpoing
  3. Thread Group of "users" having access to only users stuff
  4. etc.

In order to avoid "having drastic changes" you can use Test Fragments and Module Controllers, this way you can keep HTTP Request samplers under Test Fragments and reference it multiple times

Another option is ignoring status code using Response Assertion for instance if you expect HTTP Status Code 200 for the "super admin" and 401 for "normal admin" you can use the following setup:

enter image description here

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Hi Dmitri, thank you. I was expecting your response :) you got me right. And, yes I do want to reuse the same HTTP Request so that it will be easy to maintain in the future. For your response assertion: Assume, SuperAdmin sends HTTP Request and the expected response code is 200. But if the returned response is 401, the test will still pass as per your response assertion. Requirements: HTTP Request should be sent by different users. And based on users, we should assert different responses for the same HTTP Request. if (SupAdmin send Create User) then expect 200 else expect 401 – kishor sharma Nov 02 '20 at 02:56
0

Use Beanshell Sample to close the CSV file because it has been used by the first user. So when the second user access that CSV file it causes an error . Therefore, close the CSV file immediately after exiting the While loop.

import org.apache.jmeter.services.FileServer;
FileServer.getFileServer().closeFile("${testPlanFileDir}${__BeanShell(File.separator,)}adminApprovalSettings.csv");
vars.put("iterationApprovalLSettings", "");

In the HTTP Request. Use BeanShell Assertion which will assert based on user type.

if("${users}".equals("SuperAdmin"))
{
    if (ResponseCode.equals ("${response}") == true )
        {
        Failure= false ;
        prev.setResponseOK();
        }

        else 
        {
        Failure=true ;
        FailureMessage ="Response code was not, " +${response} + "it was"  + ResponseCode + "." ;
        }
}

else
{
    if (ResponseCode.equals ("403") == true )
        {
        Failure= false ;
        prev.setResponseOK();
        }

        else 
        {
        Failure=true ;
        FailureMessage ="Response code was not 403, it was " + ResponseCode + "." ;
        }
}

enter image description here

enter image description here

kishor sharma
  • 179
  • 2
  • 17