UNPKG

node-red-contrib-testmonitor

Version:

A comprehensive Node-RED wrapper for TestMonitor API providing test case management, test runs, milestones, and test result operations for test automation workflows

274 lines (224 loc) 10.6 kB
<script type="text/javascript"> RED.nodes.registerType('testmonitor-testcase', { category: 'TestMonitor', color: '#4CAF50', defaults: { name: {value: ""}, operation: {value: "get", required: true}, testCaseId: {value: ""}, testCaseFolderId: {value: ""}, field: {value: "payload"}, fieldType: {value: "msg"}, enableCaching: {value: true}, cacheDuration: {value: 300}, timeout: {value: 30000}, credentials: {value: "", type: "testmonitor-credentials", required: true} }, inputs: 1, outputs: 1, icon: "font-awesome/fa-file-text-o", label: function() { return this.name || "testcase: " + this.operation; }, oneditprepare: function() { $("#node-input-field").typedInput({ default: 'msg', types: ['msg', 'flow', 'global'], typeField: "#node-input-fieldType" }); // Update field visibility based on operation function updateFieldVisibility() { const operation = $("#node-input-operation").val(); // Hide all optional fields first $(".optional-field").hide(); $(".create-update-field").hide(); // Show relevant fields based on operation switch(operation) { case "get": $("#testCaseId-row").show(); break; case "list": $("#testCaseFolderId-row").show(); break; case "create": $(".create-update-field").show(); $("#testCaseFolderId-row").show(); break; case "update": $("#testCaseId-row").show(); $(".create-update-field").show(); break; case "delete": $("#testCaseId-row").show(); break; } } // Initial visibility update updateFieldVisibility(); // Update visibility when operation changes $("#node-input-operation").change(updateFieldVisibility); } }); </script> <script type="text/html" data-template-name="testmonitor-testcase"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="TestCase Node"> </div> <div class="form-row"> <label for="node-input-credentials"><i class="fa fa-key"></i> Credentials</label> <input type="text" id="node-input-credentials"> </div> <div class="form-row"> <label for="node-input-operation"><i class="fa fa-cog"></i> Operation</label> <select id="node-input-operation"> <option value="get">Get Test Case</option> <option value="list">List Test Cases</option> <option value="create">Create Test Case</option> <option value="update">Update Test Case</option> <option value="delete">Delete Test Case</option> </select> </div> <div class="form-row" id="testCaseId-row" style="display:none;"> <label for="node-input-testCaseId"><i class="fa fa-file-text-o"></i> Test Case ID</label> <input type="text" id="node-input-testCaseId" placeholder="Test Case ID"> <div class="form-tips">Required for get, update, and delete operations</div> </div> <div class="form-row create-update-field" id="testCaseFolderId-row" style="display:none;"> <label for="node-input-testCaseFolderId"><i class="fa fa-folder"></i> Folder ID</label> <input type="text" id="node-input-testCaseFolderId" placeholder="Test Case Folder ID"> <div class="form-tips">Test case folder (suite) ID for organization</div> </div> <!-- Input Field Configuration --> <div class="form-row"> <label for="node-input-field"><i class="fa fa-edit"></i> Input Field</label> <input type="text" id="node-input-field" style="width: 70%"> <input type="hidden" id="node-input-fieldType"> <div class="form-tips">Message property containing test case data</div> </div> <!-- Caching Configuration --> <div class="form-row"> <label for="node-input-enableCaching"><i class="fa fa-database"></i> Enable Caching</label> <input type="checkbox" id="node-input-enableCaching" style="display: inline-block; width: auto; vertical-align: top;"> <span style="margin-left: 10px;">Cache results for faster retrieval</span> </div> <div class="form-row"> <label for="node-input-cacheDuration"><i class="fa fa-clock-o"></i> Cache Duration (s)</label> <input type="number" id="node-input-cacheDuration" placeholder="300"> <div class="form-tips">Cache duration in seconds (default: 300)</div> </div> <div class="form-row"> <label for="node-input-timeout"><i class="fa fa-hourglass"></i> Timeout (ms)</label> <input type="number" id="node-input-timeout" placeholder="30000"> <div class="form-tips">Request timeout in milliseconds (default: 30000)</div> </div> </script> <script type="text/html" data-help-name="testmonitor-testcase"> <p>Manage TestMonitor test cases with full CRUD operations.</p> <h3>Operations</h3> <dl class="message-properties"> <dt>Get Test Case</dt> <dd>Retrieve a specific test case by ID, including custom fields</dd> <dt>List Test Cases</dt> <dd>List all test cases, optionally filtered by folder</dd> <dt>Create Test Case</dt> <dd>Create a new test case with specified properties</dd> <dt>Update Test Case</dt> <dd>Update an existing test case</dd> <dt>Delete Test Case</dt> <dd>Delete a test case by ID</dd> </dl> <h3>Input</h3> <p>The node accepts input via the configured input field (default: <code>msg.payload</code>) or directly via message properties:</p> <dl class="message-properties"> <dt>testCaseId <span class="property-type">number</span></dt> <dd>ID of the test case (required for get, update, delete)</dd> <dt>operation <span class="property-type">string</span></dt> <dd>Override the configured operation</dd> <dt>name <span class="property-type">string</span></dt> <dd>Test case name (required for create)</dd> <dt>testCaseFolderId <span class="property-type">number</span></dt> <dd>Folder ID for organization</dd> <dt>duration <span class="property-type">number</span></dt> <dd>Expected duration in minutes</dd> <dt>expected_result <span class="property-type">string</span></dt> <dd>Expected test result description</dd> <dt>test_data <span class="property-type">string</span></dt> <dd>Test data or parameters</dd> <dt>preconditions <span class="property-type">string</span></dt> <dd>Prerequisites for the test</dd> <dt>instructions <span class="property-type">array</span></dt> <dd>Array of test step instructions</dd> <dt>tags <span class="property-type">array</span></dt> <dd>Array of tags for categorization</dd> <dt>description <span class="property-type">string</span></dt> <dd>Custom field: Test description</dd> <dt>expected_value <span class="property-type">string</span></dt> <dd>Custom field: Expected value</dd> <dt>skip_time <span class="property-type">number</span></dt> <dd>Custom field: Skip time in seconds</dd> </dl> <h3>Output</h3> <dl class="message-properties"> <dt>payload <span class="property-type">object | array</span></dt> <dd>Test case data or array of test cases</dd> <dt>testMonitor <span class="property-type">object</span></dt> <dd>Metadata about the operation including timestamp</dd> </dl> <h3>Configuration</h3> <dl class="message-properties"> <dt>Credentials</dt> <dd>TestMonitor credentials configuration node</dd> <dt>Operation</dt> <dd>Default operation to perform</dd> <dt>Input Field</dt> <dd>Message property to read input data from</dd> <dt>Caching</dt> <dd>Enable caching for read operations to improve performance</dd> <dt>Cache Duration</dt> <dd>How long to cache results (in seconds)</dd> <dt>Timeout</dt> <dd>Request timeout in milliseconds</dd> </dl> <h3>Examples</h3> <h4>Get Test Case</h4> <pre>msg.testCaseId = 123; // Outputs test case details in msg.payload</pre> <h4>Create Test Case</h4> <pre>msg.payload = { name: "Test Login Function", testCaseFolderId: 45, expected_result: "User successfully logged in", instructions: ["Open login page", "Enter credentials", "Click login"], tags: ["authentication", "smoke"] };</pre> <h4>List Test Cases in Folder</h4> <pre>msg.testCaseFolderId = 45; // Outputs array of test cases in msg.payload</pre> <h3>Custom Fields</h3> <p>The node supports TestMonitor custom fields:</p> <ul> <li><strong>description:</strong> Detailed test description</li> <li><strong>expected_value:</strong> Expected output value</li> <li><strong>skip_time:</strong> Time to skip test execution</li> </ul> <h3>Error Handling</h3> <p>Errors are reported via the node status and Node-RED's error handling mechanisms. Common errors include:</p> <ul> <li>Missing credentials configuration</li> <li>Invalid test case ID</li> <li>Missing required fields for operations</li> <li>API authentication failures</li> </ul> </script> <style> .form-tips { font-size: 0.9em; color: #666; margin-top: 5px; font-style: italic; } .optional-field, .create-update-field { display: none; } </style>