Creat Button for TestExecution in TestPlan

Vera_wyss
Contributor
January 30, 2025

Hi, i want to create a button with scriptrunner that runs in a Jira and Xray plugin environment. It aims to create new Test Execution Issues for all tests in a test plan, based on a current test plan and certain custom fields. The custom fields are Sprint TestAudience and TestPlan, these fields are also required on the TestExecution. Here is my script, but it is not correct and therefore does not work, can someone help me?

 

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.xpandit.xray.api.services.TestExecutionService

def issueManager = ComponentAccessor.getIssueManager()

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def testExecutionService = ComponentAccessor.getOSGiComponentInstanceOfType(TestExecutionService)

def testPlanKey = issue.key // Aktueller TestPlan-Key

def testPlanIssue = issueManager.getIssueObject(testPlanKey)

// Sprint-Feld abrufen

def sprintField = customFieldManager.getCustomFieldObjectByName("Sprint")

def sprintValue = testPlanIssue.getCustomFieldValue(sprintField)

// TestAudience-Feld abrufen

def testAudienceField = customFieldManager.getCustomFieldObjectByName("TestAudience")

def testAudienceValue = testPlanIssue.getCustomFieldValue(testAudienceField)

// Tests aus dem TestPlan abrufen

def tests = testExecutionService.getTestsAssociatedWithTestPlan(testPlanIssue.id)

def testExecutionIssues = []tests.each { test ->

    // TestExecution erstellen

    def testExecution = testExecutionService.createTestExecution(test)

    testExecution.setSummary("Planned execution for ${test.summary}")

    // Sprint-Feld setzen, falls vorhanden

    if (sprintField && sprintValue) {

        testExecution.setCustomFieldValue(sprintField, sprintValue)

    }    

    if (testAudienceField && testAudienceValue) {

         testExecution.setCustomFieldValue(testAudienceField, testAudienceValue)

     }

    // Assignee entfernen (Unassigned setzen)

    testExecution.setAssigneeId(null)

    // TestExecution speichern

    testExecution.save()

    testExecutionIssues.add(testExecution.key)

}

def resultMessage = "${testExecutionIssues.size()} Test Executions wurden erstellt: ${testExecutionIssues}"

return "<script>alert('${resultMessage.replace("'", "\\'")}');</script>"

 

 

 

Screenshot 2025-01-30 143849.png

 

 

I created the button in the Ui Fragments and it is displayed

0 answers

Suggest an answer

Log in or Sign up to answer