0
0
Postmantesting~10 mins

Folder hierarchy in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks that the Postman collection folder hierarchy is correctly structured. It verifies that the main folder contains the expected subfolders and requests.

Test Code - unittest
Postman
import unittest
from postman_collection import Collection

class TestFolderHierarchy(unittest.TestCase):
    def setUp(self):
        # Load the Postman collection JSON file
        with open('collection.json', 'r') as file:
            self.collection = Collection(file.read())

    def test_main_folder_contains_subfolders(self):
        main_folders = [item for item in self.collection.items if item.name == 'Main Folder']
        self.assertTrue(main_folders, 'Main Folder not found')
        main_folder = main_folders[0]
        subfolder_names = [item.name for item in main_folder.items]
        expected_subfolders = ['Subfolder A', 'Subfolder B']
        for folder in expected_subfolders:
            self.assertIn(folder, subfolder_names, f'{folder} not found in Main Folder')

    def test_subfolder_contains_requests(self):
        main_folder = next(item for item in self.collection.items if item.name == 'Main Folder')
        subfolder_a = next(item for item in main_folder.items if item.name == 'Subfolder A')
        request_names = [item.name for item in subfolder_a.items if hasattr(item, 'request')]
        expected_requests = ['Get User', 'Create User']
        for req in expected_requests:
            self.assertIn(req, request_names, f'Request {req} not found in Subfolder A')

if __name__ == '__main__':
    unittest.main()
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, collection.json file loaded-PASS
2Find 'Main Folder' in collection itemsCollection parsed, folders and requests loadedAssert 'Main Folder' existsPASS
3Check 'Main Folder' contains 'Subfolder A' and 'Subfolder B''Main Folder' items listedAssert 'Subfolder A' and 'Subfolder B' are presentPASS
4Find 'Subfolder A' inside 'Main Folder''Subfolder A' items loaded-PASS
5Check 'Subfolder A' contains requests 'Get User' and 'Create User'Requests inside 'Subfolder A' listedAssert 'Get User' and 'Create User' requests existPASS
6Test endsAll assertions passed-PASS
Failure Scenario
Failing Condition: Expected folder or request is missing in the collection hierarchy
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify first in the Postman collection?
AThat all requests have valid URLs
BThat the 'Main Folder' exists in the collection
CThat the collection has no duplicate requests
DThat the collection runs successfully
Key Result
Always verify the folder and request structure in your Postman collections to ensure tests target the correct elements and avoid false failures.