rawel
rawel

Reputation: 3033

set suite variable from listener for specific suite object

I'm creating dynamic test suites on the run as follows. It works fine. But I could not figure out how to set a suite variable for a dynamically created suite object. BuiltIn().set_suite_variable("${FOO}", "Bar") seems not working for current suite either. I don't need to set the variable for the current suite but for a specific child suite object. Please help.

from robot.libraries.BuiltIn import BuiltIn

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.children = list(suite.suites)

def add_test_cases(self, *versions):
    suitesAll = []
    for version in versions:
        for suite2 in self.children:
            suiteCopy = suite2.copy()
            print(version)
            print(suiteCopy.name)
            suiteCopy.name = suiteCopy.name + version
            BuiltIn().set_suite_variable("${FOO}", "Bar") #should be set for suiteCopy
            suitesAll.append(suiteCopy)
    self.top_suite.suites = suitesAll

 globals()[__name__] = DynamicTestLibrary

Upvotes: 1

Views: 379

Answers (1)

rawel
rawel

Reputation: 3033

I found the solution.

suiteCopy.keywords.create('Set Suite Variable', args=['${RAFOO}', 'activated','children=true'], type='setup')

for version > 4.0

suiteCopy.setup.config(name='Set Suite Variable', args=('${RAFOO}', 'activated','children=true'))

Upvotes: 1

Related Questions