Forum Discussion

AbdelrahmanFahd's avatar
AbdelrahmanFahd
New Member
22 days ago

How to filter test cases by multiple labels using AND logic?

When searching with two labels in Zephyr, the results include all test cases that have either label.
Is there a way to filter and retrieve only the test cases that contain both labels simultaneously?

1 Reply

  • MisterB's avatar
    MisterB
    Icon for Champion Level 3 rankChampion Level 3

    With some creativity this is possible.  You will need to:

    1. Run a report with both labels in the criteria (to get the source TQL code).
    2. Copy the report URL, which contains the TQL code for the report.
    3. Paste and amend the TQL section.
    4. Optionally, wrap this process into a bookmarklet that can be clicked and prompts and accepts label input and produces the report.

    In step 3 I recommend pasting the URL twice so you have an original for reference, and the amended version you need to produce.  Here is an example of an original and amended URL with the relevant IN statements in bold:

    Extract of original URL that uses the IN statement and functions as an OR operator:
    ...tql=testResult.projectId%20IN%20([PROJECT ID])%20AND%20testCase.labelName%20IN%20(%22One%22%2C%20%22Two%22)%20AND%20testCase.onlyLastTestResult%20IS%20true&epicJQL=&title=Test%20execution%20results%20(list)&projectId...

    Extract of amended URL that now has two IN statements (one for each label) and effectively functions as an AND operator:
    ...tql=testResult.projectId%20IN%20(10165)%20AND%20testCase.labelName%20IN%20(%22One%22)%20%20AND%20testCase.labelName%20IN%20(%22Two%22)%20AND%20testCase.onlyLastTestResult%20IS%20true&epicJQL=&title=Test%20execution%20results%20(list)&projectId