Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
August 5, 2025

Hi @Vera_wyss

Could you please specify what is the exact error you are encountering?

Thank you and Kind regards,
Ram

Vera_wyss
Contributor
August 11, 2025

Hi @Ram Kumar Aravindakshan _Adaptavist_ 
Thanks for asking, the problem has been resolved; we found another solution.

Best regards, Vera

Suggest an answer

Log in or Sign up to answer