API Function
Retrieves the details of a single listing.
API - Retrieve the details of a single listing 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 listing.
ListingId | Long Integer | The ID of the listing. | |
… | … | … | |
HasBuyNow | Boolean | Indicates whether the item has Buy Now. | |
… | … | … | |
ShippingOptions | Collection of or null | A list of shipping options. | |
Method | String or null | The name of the delivery method (e.g. “NZ Courier”, “Rural Delivery”). Only applicable if ShippingType is Custom. | |
ShippingId | Long Integer | The ID of the shipping option (used when bidding or for Buy Now). Not required when listing an item. | |
… | … | … | … |
More refer to: Retrieve the details of a single listing
-
Example request
GET https://api.tmsandbox.co.nz/v1/Listings/2149295093.JSON
-
Example response
{
"ListingId": 2149295093,
...
"AllowsPickups": 3,
"ShippingOptions": [
{
"Type": 4,
"Price": 4.99,
"Method": "nationwide non-rural",
"ShippingId": 4
},
{
"Type": 4,
"Price": 9.99,
"Method": "rural",
"ShippingId": 5
},
{
"Type": 4,
"Price": 0,
"Method": "test free shipping",
"ShippingId": 6
}
],
...
}
Business Presentation
-
Front-end page - details of an item
Login > search a category > filter buy now item and go to the item 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(I’m here) -> Buy an auction using Buy Now
Fetch a random item that has the ‘Buy Now’ feature from upstream transaction ‘Remove a purchase from your won items list ’ to display.
Fetch a random ‘ShippingId’ from the response for downstream transaction ‘Buy an auction using Buy Now’ to use.
-
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
-
Assembling the request - ‘Retrieve the details of a single listing ’
Base on the API specification, parameter - listingId means the ID of the listing to retrieve.
And the listingId origin from the response of upstream request ‘General search ’, and it has already been set to environment variables: {{SingleListingId}}.
So the request should be GET https://api.tmsandbox.co.nz/v1/Listings/{{SingleListingId}}.JSON
-
API connectivity
The connectivity test passes and gets a response example.
{
"ListingId": 2149295658,
...
"BuyNowPrice": 13.4400,
...
"HasBuyNow": true,
...
"AllowsPickups": 1,
"ShippingOptions": [
{
"Type": 4,
"Price": 3.5,
"Method": "Tracked metro courier",
"ShippingId": 4
},
{
"Type": 4,
"Price": 5.75,
"Method": "Tracked rural courier",
"ShippingId": 5
},
{
"Type": 2,
"Price": 0,
"Method": "I intend to pick-up",
"ShippingId": 2
}
],
...
}
-
API checkpoint
Check whether the functionality of ‘Retrieve the details of a single listing’ works, and it can prioritize the pick-up option from its response for the downstream transaction ‘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: CheckingSingleListingIdDetails Start");
pm.test("CheckingSingleListingIdDetails", function () {
console.log(pm.response.json());
var jsonData = pm.response.json();
var ListingId = jsonData.ListingId;
var ShippingOptions = jsonData.ShippingOptions;
var ShippingIds =[];
var Methods =[];
if(jsonData.HasBuyNow == true){
if (ShippingOptions !== []){
breakloop:{
for (i in ShippingOptions){
// Fetch the ShippingId that the shipping way is pick-up for downstream transaction 'Buy an auction using Buy Now' to use
if(ShippingOptions[i].Method == "I intend to pick-up"){
postman.setEnvironmentVariable('ShippingId', ShippingOptions[i].ShippingId);
postman.setEnvironmentVariable('Method', ShippingOptions[i].Method);
break breakloop;
}
// Fetch random ShippingId only when ShippingMethod has no pick-up option
else{
ShippingIds.push(ShippingOptions[i].ShippingId);
Methods.push(ShippingOptions[i].Method);
postman.setEnvironmentVariable('ShippingIdsCount', ShippingIds.length);
postman.setEnvironmentVariable('ShippingIds', ShippingIds);
// If it has too many ShippingId, to get the randdom ShippingId should better not execute in the loop
var ShippingId=pm.environment.get("ShippingIds").split(",");
var ShippingIdsCount=pm.environment.get("ShippingIdsCount");
var RandShippingOptions = Math.floor(Math.random() * Number(ShippingIdsCount));
postman.setEnvironmentVariable('ShippingId', ShippingIds[RandShippingOptions]);
postman.setEnvironmentVariable('Method', Methods[RandShippingOptions]);
}
}
}
var ShippingId=pm.environment.get("ShippingId");
var Method=pm.environment.get("Method");
console.log("ListingId: "+ListingId +", ShippingId: " + ShippingId +", and Method: " +Method);
}
console.log("Post-Transaction: CheckingSingleListingIdDetails Pass");
}
else{
console.log("Post-Transaction: CheckingSingleListingIdDetails Failed");
}
});
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.