Trade Me-10-General search API testing | Postman API automation testing

API Function

Allows you to search for listings on Trade Me by category, by keywords or a combination of these two.

API - General search script development steps

API Specification -> Business Presentation -> API Testing Script Debugging -> API Testing Script Enhancement -> API Testing Script Negative Cases Extension -> API Testing Script Publishment

API Specification

  • API Function: Allows you to search for listings on Trade Me by category, by keywords or a combination of these two.

The result set can be filtered by a variety of properties, including availability of Buy Now, Pay Now, item condition or seller.

  • Key request fields

page Integer (optional) The page number of the set of results to return, starting from 1. Defaults to 1.
rows Integer (optional) The number of results per page; also the maximum number of results to return. The maximum is 25 for unauthenticated requests and 500 for authenticated requests. Defaults to 25 (unauthenticated) or 50 (authenticated).

More refer to: General search

  • Key response fields

TotalCount Integer The total number of results in the collection. Can be larger than the number of returned results.
TotalCountTruncated Boolean True if the total count of results exceeded the allowed maximum and was truncated.
Page Integer The index of the current page of results (starts at 1).
PageSize Integer The number of results in the current page.
List Collection of or null A list of the results in the current page.
ListingId Long Integer The ID of the listing.
BuyNowPrice Number The Buy Now price.
HasBuyNow Boolean Indicates whether the item has Buy Now.

More refer to: General search

  • Example request

GET https://api.tmsandbox.co.nz/v1/Search/General.JSON?buy=All&rows=500&page=4

  • Example response

{
    "TotalCount": 16479,
    "Page": 4,
    "PageSize": 500,
    "List": [
    	...
        {
            "ListingId": 2149294614,
            "Title": "Cobra Glassware",
            "Category": "0341-0881-4739-",
            "StartPrice": 11.0000,
            "BuyNowPrice": 33.0000,
            ...
            "HasBuyNow": true,
            ...
        },
        ...
    ]
}   

Business Presentation

  • Front-end page - Search box tick the ‘Buy Now’ to filter items with ‘Buy Now’ feature.

Login > search a category

  • Business scope selection

Chained combination transactions

Retrieve your won items -> Remove a purchase from your won items list -> General search(I’m here) -> Retrieve the details of a single listing -> Buy an auction using Buy Now

Searching 500 items by search function and only pick the items that has the ‘HasBuyNow’ feature and the BuyNowPrice <= $20 from the response for downstream transaction ‘Retrieve the details of a single listing’ to use.

  • Business verification points

Checking given searching conditions can get items, and a random item of these items can be stored for downstream transaction ‘RetrieveTheDetailsOfASingleListing’ to use.

API Testing Script Debugging

  • Choose the OAuth 1.0 in the Authorization label of Postman to authorize the request.

The OAuth 1.0 is for the transaction that needs to be authorized before sending. Template likes the below:

How to get Consumer Key, Consumer Secret, OAuth Token, and OAuth Token Secret, please refer to Preparation before API testing demo

Base on the API specification, parameter buy=All means filter listings to only those with Buy Now.

Parameter rows=500 means the maximum number of results per page is 500 for authenticated requests.

Parameter page=4 means The page 4 of the set of results to return.

So the request should be GET https://api.tmsandbox.co.nz/v1/Search/General.JSON?buy=All&rows=500&page=4

  • API connectivity

The connectivity test passes and gets a response example.

{
    "TotalCount": 16479,
    "Page": 4,
    "PageSize": 500,
    "List": [
    	...
        {
            "ListingId": 2149288229,
            "Title": "The Shawshank Redemption (Special Edition)",
            "Category": "0003-9232-9241-",
            "StartPrice": 0,
            "BuyNowPrice": 12,
            "StartDate": "/Date(1625090253613)/",
            "EndDate": "/Date(1625695053613)/",
            "ListingLength": null,
            "HasGallery": true,
            "AsAt": "/Date(1625649443316)/",
            "CategoryPath": "/Movies-TV/Bluray/Drama",
            "PictureHref": "https://images.tmsandbox.co.nz/photoserver/thumb/104197832.jpg",
            "Region": "Wellington",
            "Suburb": "Wellington City",
            "HasBuyNow": true,
            "NoteDate": "/Date(0)/",
            "ReserveState": 3,
            "IsBuyNowOnly": true,
            "PriceDisplay": "$12.00 per item",
            "HasFreeShipping": true,
            "PromotionId": 2,
            "AdditionalData": {
                "BulletPoints": [],
                "Tags": []
            },
            "MemberId": 4007156
        },
        ...
    ]
}
  • API checkpoint

Check whether the functionality of ‘general search’ works, and it can fetch any ListingId has the ‘HasBuyNow’ feature from its response for the downstream transaction ‘Retrieve the details of a single listing ’ or ‘Buy an auction using Buy Now ’ to use.

Then we get the checking code snippet below base on the example feature.

console.log("Post-Transaction: CheckingListingIdHasBuyNow Start");

pm.test("GetListingIdHasBuyNow", function () {

    var jsonData = pm.response.json();

    var Page = jsonData.Page;

    var PageSize = jsonData.PageSize;

    var arr =[];

    var List = jsonData.List;

    if (typeof(List) !== "undefined"){

        for (i in List){

            var ListingId = List[i].ListingId;

            //Only pick the items that has the 'HasBuyNow' feature and the BuyNowPrice <= $20
            if(List[i].HasBuyNow == true && List[i].BuyNowPrice <=20){

                arr.push(ListingId);

                }

        }

        postman.setEnvironmentVariable('ListingIdHasBuyNowCount', arr.length);  

    }

    if(Array.isArray(arr) && arr.length === 0){        

        console.log(pm.response.json());

        console.log("Didn't fetch any ListingId has the 'HasBuyNow' feature: " +SingleListingId);

        console.log("Post-Transaction: CheckingListingIdHasBuyNow Failed");

    }
    else{

        postman.setEnvironmentVariable('ListingIdHasBuyNow', arr);

        console.log("Page: "+Page+", total items: "+PageSize);
        
        console.log("'HasBuyNow and BuyNowPrice <=20' items counts to: " + arr.length + ", ListingId details: ");

        console.log(arr);

        // Randomly get one ListingId from the stored ListingId list that has the 'HasBuyNow' feature.
        // The ListingId will be picked for downstream transaction 'RetrieveTheDetailsOfASingleListing' to use.
        var ListingIdHasBuyNowCount = pm.environment.get("ListingIdHasBuyNowCount");

        var ListingIdHasBuyNow=pm.environment.get("ListingIdHasBuyNow").split(",");

        postman.setEnvironmentVariable('SingleListingId', ListingIdHasBuyNow[Math.floor(Math.random() * Number(ListingIdHasBuyNowCount))]);

        var SingleListingId = pm.environment.get("SingleListingId");
        
        console.log("Get random SingleListingId: " +SingleListingId);

        console.log("Post-Transaction: CheckingListingIdHasBuyNow Pass");

    }

});

Run script to verify the checkpoint works from console log.

API Testing Script Enhancement

  • Enhance the script, such as to add the transactional function, exceptional verification, parameterization, etc.

  • Run the final script and to verify from front-end page or console log.

API Testing Script Negative Cases Extension

Using the ‘Equivalent Class Partitioning’ and ‘Boundary Value Analysis’ as we did in manual testing cases.

These API test scripts are doing the negative direction of the business, to be an extension to the above API positive case.

API Testing Script Publishment

Move script from debug folder to public folder when we finished API positive and negative cases.

Then wait to be published to the GitHub specific repo combining with other scripts using the CICD tool.

Copyright

This work is licensed under CC BY-NC-ND 4.0 .