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
172 lines (148 loc) • 6.54 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('testmonitor-credentials', {
category: 'config',
defaults: {
name: { value: "" },
baseUrl: { value: "https://elemental-machines.testmonitor.com/api/v1", required: true },
projectId: { value: 2, required: true, validate: RED.validators.number() }
},
credentials: {
apiKey: { type: "password", required: true }
},
label: function() {
return this.name || "TestMonitor Credentials";
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
}
});
</script>
<script type="text/html" data-template-name="testmonitor-credentials">
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-config-input-name" placeholder="TestMonitor Credentials">
</div>
<div class="form-row">
<label for="node-config-input-baseUrl"><i class="fa fa-globe"></i> Base URL</label>
<input type="text" id="node-config-input-baseUrl" placeholder="https://your-instance.testmonitor.com/api/v1">
<div class="form-tips">
<strong>Tip:</strong> Use your TestMonitor instance URL (e.g., https://company.testmonitor.com/api/v1)
</div>
</div>
<div class="form-row">
<label for="node-config-input-projectId"><i class="fa fa-folder"></i> Project ID</label>
<input type="number" id="node-config-input-projectId" placeholder="2">
<div class="form-tips">
<strong>Tip:</strong> The numeric ID of your TestMonitor project
</div>
</div>
<div class="form-row">
<label for="node-config-input-apiKey"><i class="fa fa-key"></i> API Key</label>
<input type="password" id="node-config-input-apiKey" placeholder="Your TestMonitor API Key">
<div class="form-tips">
<strong>Tip:</strong> Generate an API key from your TestMonitor account settings
</div>
</div>
<div class="form-row">
<button id="node-config-test-connection" class="red-ui-button">
<i class="fa fa-plug"></i> Test Connection
</button>
<div id="node-config-test-result" style="margin-top: 10px;"></div>
</div>
</script>
<script type="text/html" data-help-name="testmonitor-credentials">
<p>Configuration node for TestMonitor API authentication.</p>
<h3>Configuration</h3>
<dl class="message-properties">
<dt>Name <span class="property-type">string</span></dt>
<dd>A friendly name for this configuration</dd>
<dt>Base URL <span class="property-type">string</span></dt>
<dd>The base URL of your TestMonitor instance API (e.g., https://company.testmonitor.com/api/v1)</dd>
<dt>Project ID <span class="property-type">number</span></dt>
<dd>The numeric ID of the TestMonitor project to work with</dd>
<dt>API Key <span class="property-type">string</span></dt>
<dd>Your TestMonitor API key for authentication</dd>
</dl>
<h3>Authentication</h3>
<p>This node uses Bearer token authentication with the TestMonitor API. You need to:</p>
<ol>
<li>Log into your TestMonitor account</li>
<li>Go to your account settings</li>
<li>Generate an API key</li>
<li>Copy the API key into the configuration above</li>
</ol>
<h3>Testing Connection</h3>
<p>Use the "Test Connection" button to verify your credentials and connection to TestMonitor.</p>
<h3>Security</h3>
<p>API keys are securely stored encrypted in Node-RED's credential system.</p>
</script>
<style>
.form-tips {
font-size: 0.9em;
color: #666;
margin-top: 5px;
font-style: italic;
}
#node-config-test-result {
padding: 8px;
border-radius: 3px;
font-weight: bold;
}
#node-config-test-result.success {
background-color: #dff0d8;
color: #3c763d;
border: 1px solid #d6e9c6;
}
#node-config-test-result.error {
background-color: #f2dede;
color: #a94442;
border: 1px solid #ebccd1;
}
</style>
<script type="text/javascript">
(function() {
$('#node-config-test-connection').click(function() {
const button = $(this);
const resultDiv = $('#node-config-test-result');
// Get form values
const baseUrl = $('#node-config-input-baseUrl').val();
const projectId = $('#node-config-input-projectId').val();
const apiKey = $('#node-config-input-apiKey').val();
if (!baseUrl || !projectId || !apiKey) {
resultDiv.removeClass('success').addClass('error')
.text('Please fill in all required fields');
return;
}
// Disable button and show loading
button.prop('disabled', true).html('<i class="fa fa-spinner fa-spin"></i> Testing...');
resultDiv.removeClass('success error').text('');
// Test the connection
$.ajax({
url: baseUrl + '/projects/' + projectId,
type: 'GET',
headers: {
'Authorization': 'Bearer ' + apiKey,
'Content-Type': 'application/json'
},
timeout: 10000,
success: function(data) {
resultDiv.removeClass('error').addClass('success')
.text('Connection successful! Project: ' + (data.name || 'Unknown'));
},
error: function(xhr, status, error) {
let errorMsg = 'Connection failed';
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMsg += ': ' + xhr.responseJSON.message;
} else if (error) {
errorMsg += ': ' + error;
}
resultDiv.removeClass('success').addClass('error').text(errorMsg);
},
complete: function() {
// Re-enable button
button.prop('disabled', false).html('<i class="fa fa-plug"></i> Test Connection');
}
});
});
})();
</script>