Package com.postman.collection
Class Event
java.lang.Object
com.postman.collection.CollectionElement
com.postman.collection.Event
Encapsulates members of the
event array object. Events contain pre-request and test scripts for Folders, Requests, and Collections
Postman SDK analog: event.
"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"
}
}
]
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionEvent(enumEventType evtType, String sourceCode) Create a new Event object with the specified EventType (eg., pre-request or test) and source code. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSourceCodeElement(String code, int position) Pre-pend source code to the end of theexecproperty array.Returns the type of this script, eg., pre-request or test, as an enumerated value.getKey()Get complete source for this script, or null if none is set.voidremoveSourceCodeElement(int position) voidsetEventType(enumEventType eventType) Sets the type of this event, eg.voidsetSourceCode(String srcCode) Set the source code for this scriptMethods inherited from class com.postman.collection.CollectionElement
getCollection, getDefaultCollectionSchema, getDefaultValidationSchema, getParent, getUUID, getValidationMessages, isEquivalentTo, setParent, setUUID, toJson, toJson, validate, validate
-
Constructor Details
-
Event
Create a new Event object with the specified EventType (eg., pre-request or test) and source code. Thetypeproperty is excluded because it is always 'text/javascript', although the schema does theoretically allow for different values- Parameters:
evtType- Enumerated value of the event type, eg. pre-request or testsourceCode- Source code for the scriptevtType- Content type of the script, always "text/javascript"
-
-
Method Details
-
getScriptType
- Returns:
- String
-
getEventType
Returns the type of this script, eg., pre-request or test, as an enumerated value.- Returns:
- enumEventType The event type
-
setEventType
Sets the type of this event, eg. pre-request or test, as an enumerated value- Parameters:
eventType- The type of the event
-
getSourceCode
Get complete source for this script, or null if none is set. Concatenates all the elements of theexecarray.- Returns:
- Throws:
InvalidPropertyException
-
getSourceCodeElements
- Returns:
- ArrayList<String>
-
setSourceCode
Set the source code for this script- Parameters:
srcCode- The source code (javascript)
-
getKey
- Specified by:
getKeyin classCollectionElement- Returns:
- String
-
addSourceCodeElement
Pre-pend source code to the end of theexecproperty array.- Parameters:
code-
-
removeSourceCodeElement
- Parameters:
position-- Throws:
InvalidPropertyException
-