In an attempt to fully optimize the requests Iām running I looked into ways to copy certain response values into the clipboard for easier access (no need to manually select and ctrl+V on the console logs).
At first it seemed like it was not possible but then I found a topic with a workaround. (testing - How do you copy response values to the clipboard in Postman javascript tests? - Stack Overflow)
let template = `<html><body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.11/clipboard.min.js"></script>
<code style="width:max-content!important;padding:10px;display:block;" id="copyText">${jsonData.backgroundProcessId}</code>
<button id="copyButton" type="button" data-clipboard-action="copy" data-clipboard-target="#copyText" style="background:green;color:white;">Copy to Clipboard</button>
<script>
new ClipboardJS('#copyButton')
.on('success', function(e) {
e.clearSelection();
})
.on('error', function(e) {
e.clearSelection();
copyText.style.borderColor = 'red';
});
copyButton.click();
</script>
</body></html>`;
pm.visualizer.set(template);
The above block of code does indeed allow automatic copying to clipboard but it requires me to access the visualize tab. Problem is, Iām running various requests in a collection which (to my knowledge) does not open the visualize tab at any point.
Is there anyway to make the collection runner open the visualize tab of a specific request? Or a different way to copy response values to the clipboard automatically?
Thank you for any help!