Trade Me-12-Buy an auction using Buy Now API testing | Postman API automation testing

API Function

Buys an item using Buy Now.

API - Buy an auction using Buy Now 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

  • Key request fields

  • Key response fields - The details of the Buy Now request.

Success Boolean Indicates whether the operation was successful.
Description String or null The description of the error, if the operation failed.
StatusCode Enumeration The status of the Buy Now request.
Success 0 The bid was a success.
PurchaseId Long Integer The ID of the purchase that was just made.

More refer to: Buy an auction using Buy Now

  • Example request

POST https://api.tmsandbox.co.nz/v1/Bidding/BuyNow.JSON

{

“ListingId”:2149302816,

“ShippingOption”:2

}

  • Example response

{
    "Success": true,
    "Description": "Seller's email owen4@snipesoft.net.nz",
    "StatusCode": 0,
    "PurchaseId": 26231
}

Business Presentation

  • Front-end page - Item details page click ‘Buy Now’ button.

Login > search a category > filter buynow item and go to item details page > Click Buy Now > Choose shipping way and confirm purchase

  • Front-end page - Confirm purchase page

  • Front-end page - Purchase details page

  • Business scope selection

Chained combination transactions

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

Fetch ‘ListingId’ from the response of upstream transaction ‘General search ’ as one of the request fields.

Fetch ‘ShippingId’ from the response of upstream transaction ‘Retrieve the details of a single listing’ as one of the request fields.

  • Business verification points

Checking the given item details is displayed on the page.

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 - ListingId means the ID of the listing the Buy Now request is for.

And the listingId origin from the response of upstream request ‘General search ’, and it has already been set to environment variables: {{SingleListingId}}.

Base on the API specification, parameter - ShippingOption means the ID of the preferred shipping option which will be used if the Buy Now request succeeds. This ID can be retrieved from the ShippingId field in the listing detail.

And the ShippingOption origin from the response of upstream request ‘Remove a purchase from your won items list ’, and it has already been set to environment variables: {{ShippingId}}.

So the request should be https://api.tmsandbox.co.nz/v1/Bidding/BuyNow.JSON

  • API connectivity

The connectivity test passes and gets a response example.

{
    "Success": true,
    "Description": "Seller's email mp70@abcde.com",
    "StatusCode": 0,
    "PurchaseId": 26262
}
  • API checkpoint

Check whether the functionality of ‘Buy an auction using Buy Now’ works, and it can successfully buy an item into won items list.

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

// Check BuyNow operation is sucessful
console.log("Post-Transaction: CheckingBuyNow Start");

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

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

    var jsonData = pm.response.json();

    var Success = jsonData.Success;

    var StatusCode = jsonData.StatusCode;

    var PurchaseId= jsonData.PurchaseId;

    postman.setEnvironmentVariable('BuyNowPurchaseId', PurchaseId);  

    if(Success == true && StatusCode == 0){
        
        console.log("Get sucessful StatusCode: " +StatusCode+" (0-Success)");    

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

    }

    else{

        //0-Success, 1-None, 2-ReserveMet, ..., 42-AutoBidDecreased
        console.log("Get failed StatusCode: " +StatusCode);

        var Description = jsonData.Description;

        console.log("Failed Description: " +Description);

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

    }

});

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

const post_request = {

  url:  pm.environment.get("BaseUrl")+'/v1/MyTradeMe/Won/All.JSON',

  method: 'GET',

  header:['Content-Type:application/json', 'Authorization:OAuth oauth_consumer_key="4B34BCCFD24CF3497EE36E54204AA7E2",oauth_token="38B073E4F6C65F722A0CF964492EA6A2",oauth_signature_method="PLAINTEXT",oauth_timestamp="1623834029",oauth_nonce="Zr5dzIAuVON",oauth_version="1.0",oauth_signature="0D8635F6A51F0EA381A8D97F5D7812E2%26293BD08354D18D33871C4EBB02D67ACA"'],

  body: {
  }

};

// setTimeout(()=>{
    pm.sendRequest(post_request, function (err, response) {

        if (err) {

            console.log(err);

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

        } 

        else {

            // Confirm whether PurchaseId of new buy item existed on the won list.
            pm.test("Checking NewPurchasedListId existed in the won list", function () {

                console.log(response.json());

                var jsonData = response.json();

                var Listdata = jsonData['List'];

                var SingleListingId = pm.environment.get("SingleListingId");

                var BuyNowPurchaseId = pm.environment.get("BuyNowPurchaseId");

                breakloop:{

                    for(var i = 0; i < Listdata.length; i++) {

                    // console.log("ListingId: " + Listdata[i].ListingId + ", PurchaseId: " + Listdata[i].PurchaseId);
                    
                        if (SingleListingId == Listdata[i].ListingId && BuyNowPurchaseId == Listdata[i].PurchaseId){

                            console.log("Found PurchaseId " +BuyNowPurchaseId +" and ListingId "+SingleListingId + " exists on the won list"); 

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

                            break breakloop;

                        }

                    }

                    if (i==0){

                        console.log("Not Found any PurchaseId and ListingId exist on the won list.");

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

                    }

                    else{

                        console.log("The purchased item hasn't been shown on the won list page, please waiting 60 seconds to check again.");

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

            });            

        }
        
    });

// }, 70000);

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.

Before the ‘Buy Now’ operation, see the item details.

After the ‘Buy Now’ operation, see the item details.

After the ‘Buy Now’ operation, see the won items list.

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 .