I’m working on a Postman collection that includes various API requests and tests. The collection should pass several checks, including a specific skill check where I need to set a collection variable in the Tests tab script. However, I am encountering an error when running the tests.
The specific requirement for the test is:
6. [skillcheck] Set "favoriteActor" as a collection variable using
pm.collectionVariables.set(...) in the Tests tab script
And getting Postman Test Script Error: “Cannot read properties of undefined (reading ‘filter’)”
I’m getting an error when running my Postman collection:
{
"status": "error",
"message": "Your collection failed one or more Postman tests. See the errors array for details.",
"errors": [
{
"test": "6. [skillcheck] Set "favoriteActor" as a collection variable using pm.collectionVariables set(...) in Tests tab script",
"message": "Cannot read properties of undefined (reading 'filter')"
}
]
}
Here is the relevant part of my test script:
pm.test(`6. [skillcheck] Set "favoriteActor" as a collection variable using pm.collectionVariables.set(...) in Tests tab script`, function () {
pm.collectionVariables.set("favoriteActor", "Tony Stark");
const favoriteActor = pm.collectionVariables.get("favoriteActor");
pm.expect(favoriteActor).to.equal("Tony Stark");
});
I tried submitting the “Submit your Postman collection” for Postman API Fundamentals Student Expert certification and instead of getting this:
{
"status" : "ok",
"message" : Congratulations! the lesson 'Submit your Postman collection' is now marked as complete."
}
I got an error as:
{
"status": "error",
"message": "Your collection failed one or more Postman tests. See the errors array for details.",
"errors": [
{
"test": "6. [skillcheck] Set "favoriteActor" as a collection variable using pm.collectionVariables set(...) in Tests tab script",
"message": "Cannot read properties of undefined (reading 'filter')"
}
]
}