Package com.postman.collection
Class Item
java.lang.Object
com.postman.collection.CollectionElement
com.postman.collection.Item
Encapsulates the
item object in the postman schema
Postman SDK analog: Item.
{
"name": "Get a list of facts",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"var latencyTestName = \"Response time is less than \" + pm.collectionVariables.get(\"latencyLimit\") + \" ms\";",
"",
"pm.test(latencyTestName, function () {",
" pm.expect(pm.response.responseTime).to.be.below(parseInt(pm.collectionVariables.get(\"latencyLimit\")));",
"});",
"",
"pm.test(\"Response contains fact\", function () {",
" var jsonData = pm.response.json();",
" pm.expect(pm.response.json().length).to.be.greaterThan(1);",
"});"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
"console.log(\"last fact: \" + pm.collectionVariables.get(\"curFact\"));"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{baseUrl}}/facts?max_length=200&limit=2",
"host": [
"{{baseUrl}}"
],
"path": [
"facts"
],
"query": [
{
"key": "max_length",
"value": "200"
},
{
"key": "limit",
"value": "2",
"description": "limit the amount of results returned"
}
]
},
"description": "Returns a a list of facts"
},
"response": [
{
"name": "successful operation",
"originalRequest": {
"method": "GET",
"header": [],
"url": {
"raw": "{{baseUrl}}/facts?max_length=200&limit=2",
"host": [
"{{baseUrl}}"
],
"path": [
"facts"
],
"query": [
{
"key": "max_length",
"value": "200"
},
{
"key": "limit",
"value": "2"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [],
"body": "[\n {\n \"fact\": \"ex ad\",\n \"length\": 200\n }, (...)}\n]"
}
]
}
],
"description": "Cat Facts"
}
Hierarchy
Folders and requests are both items. An item with no request property is rendered by the Postman UI as a Folder. Items with a request property
are rendered as requests. Folders can contain other items, both folders and requests. Requests are always leaf nodes, they cannot contain other items.
A collection is the top level item in the hierarchy. It can contain a tree of items, but cannot itself be contained.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn the value of thedescriptionpropertygetEvent(enumEventType evtType) Get an event, specifying whether to return the pre-request script or test script associated with this item.Return the ArrayList<Event> containing the objects comprising theeventarraygetKey()getName()Get the parent of this item, or null if one is not defined (eg.voidsetDescription(String description) Set the value of thedescriptionpropertyvoidSet the ArrayList<Event> comprising the values in theeventarray.voidvoidSet the parent of this item.voidsetPreRequestScript(String code) Set the pre-request script for this item in theeventarrayvoidsetTestScript(String code) Set the test script for this item in theeventarrayMethods inherited from class com.postman.collection.CollectionElement
getCollection, getDefaultCollectionSchema, getDefaultValidationSchema, getUUID, getValidationMessages, isEquivalentTo, setParent, setUUID, toJson, toJson, validate, validate
-
Constructor Details
-
Item
protected Item() -
Item
Construct an empty item with only anameproperty and assign it as a child ofparent- Parameters:
name- The name of the objectparent- The Item containing this item.
-
Item
* Construct an empty item with only aname>; property. Once added to a Collection, the Postman UI will render this object as an empty folder.- Parameters:
name- The name of the object
-
-
Method Details
-
getDescription
Return the value of thedescriptionproperty- Returns:
- String The description
-
setDescription
Set the value of thedescriptionproperty- Parameters:
description- The description
-
getEvents
Return the ArrayList<Event> containing the objects comprising theeventarray- Returns:
- ArrayList<Event>
-
getEvent
Get an event, specifying whether to return the pre-request script or test script associated with this item.- Parameters:
evtType- Enumerated value for the event type, eg., pre-request or test.- Returns:
- Event The event, if it exists
-
setEvents
Set the ArrayList<Event> comprising the values in theeventarray.- Parameters:
events-
-
setParent
Set the parent of this item.- Parameters:
parent- The parent item.
-
getParent
Get the parent of this item, or null if one is not defined (eg. this item is a collection);- Overrides:
getParentin classCollectionElement- Returns:
- Item The parent item.
-
setPreRequestScript
Set the pre-request script for this item in theeventarray- Parameters:
code- The source code for the script
-
getPreRequestScript
- Returns:
- Event
-
getTestScript
- Returns:
- Event
-
setTestScript
Set the test script for this item in theeventarray- Parameters:
code- The source code for the script
-
getName
- Returns:
- String
-
setName
- Parameters:
name-
-
getKey
- Specified by:
getKeyin classCollectionElement- Returns:
- String
-