API Testing

 

In today’s scenario, API testing plays an important role in testing a software thoroughly. Bqurious thus allows it’s users to perform API testing since it is essential for test coverage.

Instructions to create an API Test

  1. Navigate to Test Case screen.

  2. Create / select a module.

  3. Click on Add Test button.

  4. Under Test Case Detail tab, enter the meta-data and select Type as API.

     

  5. Click on Save.

  6. Click on Test Steps tab.
    The API test template will be generated. Requests and Details sections will be displayed.


    The API template displays :

    1. Left Nav (Requests section) which lists steps. You can add, delete and move steps here.

    2. On the right (Details section) you have step group, url, credentials & tabbed grid for various inputs.

 

Key points to remember while adding steps to the API test

  1. Under Request section, various requests are made available like GET, POST, PUT, PATCH, DELETE and HEAD.
    GET request is selected by default.

  2. For each request, the request details need to be entered under the ‘Details’ section.

    1. Enter meta-data like the Group Name and URL.

       

    2. Enter request header data under the Header Parameter.

       

    3. Enter the query string under the Query Parameter.

       

    4. For POST request, enter form-data under the Body Parameter.

      Please note that Body Parameter will be disabled for GET request.

    5. Use Extract & Store tab for retrieving, extracting and storing the data in a variable.

       

      1. Data can be retrieved from options like Header, Cookies and Response in the Source column.
        User Source as Header when data to be extracted is displayed under Request Headers.
        User Source as Response when data to be extracted is displayed under Response.
        User Source as Cookie when cookies need to be extracted and stored.

      2. Search type can be selected from available options like Regex, JSONPath and XPath.

      3. Enter the Pattern/Query according to the search type selected.
        Regex : Suppose we select Regex as the search type, we will have to enter the query using the regular expressions
        For example :
        This is the link from which you wish to retrieve data : https://app.bqurious.com
        The response received using a simple GET Request is as displayed below

        Now, suppose we wish to extract the title of the page.
        The query that we would enter would be (\w{1,}-\w{8})



        JSONPath : Suppose we select JSONPath as the search type, we will have to enter the query using JSONPath.
        For example :
        This is the link from which you wish to retrieve data : https://reqres.in/api/users?page=2
        The response received using a simple GET Request is as displayed below

        Now, suppose we wish to extract the first name of the user displayed at the third position on this page.
        The query that we would enter would be data[2].first_name

        Please note that indexing in JSONPath starts from 0.


        XPath : Suppose we select XPath as the search type, we will have to enter the query using XPath
        Simply mention the XPath of the element you wish to extract and store.
        For example :
        This is the link from which you wish to retrieve data : https://app.bqurious.com
        The response received using a simple GET Request is as displayed below

        Now, suppose we wish to extract the username.
        The query that we would enter would be //input[@id='username']

         

      4. Enter the variable name for the data to be stored.

    6. Use Assertions tab for various verification like : verifyHttpResponse, verifyHttpHeader, verifyHttpStatus, verifyHttpResponseTime and verifyHttpResponseSize

       

  3. If you wish to use some other request, other than GET :

    1. Click on Add Steps button under the ‘Requests’ section

    2. Choose the particular request from the dropdown displayed within the URL field.

       

  4. If you wish to delete a particular request :

    1. Click on the blue colored arrows >> displayed besides the particular request under the Requests section

    2. Click on Delete Step.

      You will notice that the step will strike out like the below image :

    3. Click on Save and the step will be deleted.

  5. If you mistakenly clicked on the Delete Step option but haven’t saved the test case yet, you can still use that step.

    1. Click on the arrows >> displayed besides the particular request under the Requests section

    2. Click on Step Active.

    3. Click on Save and the step won’t be deleted.

 

If any API requires authentication, follow the below steps to create an API Authentication.

 

Creating API Authentication

  1. Click on Configure on the left panel.

  2. Click on API Authentication.

  3. Enter the meta-data :

    1. Authentication Name

    2. Select Authentication Type : None, Basic, Digest, BearerToken, Oauth1, Oauth2

      If you select Basic or Digest, User Name and Password fields will be displayed.

       



      If you select BearerToken, Token Type and Bearer Token fields will be displayed.

      If you already have a token (Basic token, Bearer token, Digest token, Oauth token etc.), you can simply add the token type and token in the fields and use the authentication.
      Suppose the client has provided you a Basic type authorization token

      You can simply use the token as below



      If you select Oauth1, below fields will be displayed.


      If you select Oauth2, below fields will be displayed.

       

  4. Enter the details and click on Save.
    Once you save the API Authentication, it will be displayed under the Authentication dropdown within the API test.

Â