Parallel execution of dynamic created test cases

We’re creating several test cases using the dynamic library from
variables - In Robot framework, how can I execute multiple of test cases in data driven meithod - Stack Overflow
That means, in robot I have only one test which is creating a test suite with different tests using the keyword “add test case”:

from robot.running.model import TestSuite

class DynamicTestLibrary(object):
    ROBOT_LISTENER_API_VERSION = 3
    ROBOT_LIBRARY_SCOPE = 'GLOBAL'
    ROBOT_LIBRARY_VERSION = 0.1

    def __init__(self):
        self.ROBOT_LIBRARY_LISTENER = self
        self.top_suite = None

    def _start_suite(self, suite, result):
        self.top_suite = suite
        self.top_suite.tests.clear() # remove placeholder test

    def add_test_case(self, name, keyword, *args):
        tc = self.top_suite.tests.create(name=name)
        tc.keywords.create(name=keyword, args=args)
        
    def add_test_matrix(self, data_set, test_scenarios):
        for data in data_set:
            for test_scenario in test_scenarios:
                self.add_test_case(f'{test_scenario} - {data}', test_scenario, data)

globals()[__name__] = DynamicTestLibrary

My robot file looks like:

*** Test Cases ***
Run All Testcases
   ${JiraIssues}    Find Relevant Issues In Jira
    FOR    ${JiraIssue}    IN    ${JiraIssues}
        Add Test Case    ${JiraIssue['key']}    Run Jira Test Case
    END

*** Keywords ***
Run Jira Test Case
    Log To Console    Running Test xyz ...

What I need is to parallelize the test cases. Pabot with his standard configuration sees only one test, so the are executed sequently and not in parallel. I’m open to rework the whole file.

Hallo Matthias,

This is easy and hard at the same time.
The easy thing is, there is already a solution.
The hard part is to explain it here.

In general i would definitely recommend not to run that for loop over jira issues.

But the solution you want to look for is using DataDriver and implement a DataReader that fetches the stuff from Jira.

DataDriver already works with Pabot.

The other option would be to search in the DataDriver code, how it works with Pabot. But it is really complicated and i would not recommend to solve this with it.

Great! Just got it running with DataDriver. I wrote a customized DataReader as you suggested, the tests are working correctly and using pabot in parallel! Very good documentation! Thanks a lot!

1 Like