Creating custom variables in Capture for JIRA

How to automatically enrich your JIRA issues with useful metadata while testing web applications.


What is Capture for JIRA?

Capture for JIRA is a Chrome extension that helps create JIRA issues. While using a web application, a tester can rapidly log a JIRA issue including a screenshot of the current page and other metadata about the error. The Chrome extension does not stand alone, it requires an, “active JIRA instance with Capture for JIRA enabled.”


How can additional data be captured?

One feature of Capture for JIRA is the ability to capture custom variables from the current page to enhance the quality of the issue being logged. These variables are defined using a javascript snippet in the “Templates” -> “Variables” tab of the Capture extension. The documentation gives some basic examples.

There is a catch. The custom variables’ javascript cannot reference any scripts loaded by the page being tested. This is because when the “capture” is initiated, the document alone is copied into a new browser tab, and presented as an image. Any properties that may have existed in the document’s model are not copied. Therefore, any custom data for capture variables must exist in the document, e.g. as a <meta> tag. For example, consider this simple html page:

<meta name=“build_id” content=“application-1.3.595”>

The data within the <meta> can be exposed to Capture for JIRA with the following capture variable expression:



What data is worth capturing?

The capture extension includes javascript expressions for these variables by default

  • document.URL
  • navigator.cookieEnabled
  • navigator.userAgent
  • document.title

Here are some ideas for other useful values to include in a bug report.

  • Application version
  • Last HTTP API response code
  • Most recent window.onerror message
  • Current AngularJS router state

One would have to set these values based on various javascript events that occur on the page. I created a library to aid in adding the values to the document’s <meta> tags, which is provided below.

JavaScript library

(function (window, document, jiraCapture, undefined) {

    jiraCapture.capture = function (attribute, value) {
        window.dispatchEvent(new CustomEvent('captureForJira', 
                     {'detail': {name: attribute, value: value}}

    window.addEventListener('captureForJira', function (e) {
        var meta = document.getElementsByTagName('meta')[];
        if (!meta) {
            meta = document.createElement('meta');
        meta.content = e.detail.value;
    }, false);

}(window, window.document, (window.jiraCapture = window.jiraCapture || {})));


Categories: Blog

Rusty Eller
05 Jan, 2017