Reputation: 714
I have a bunch of testsuites which are executed using robot.api.
For Example,
from robot.api import TestSuite,ResultWriter
tc_dict = {
'test case #1' : 'Passed'
'test case #2' : 'Failed'
}
suite = TestSuite('tests_with_listener.robot')
for k,v in tc_dict.items():
test = suite.tests.create(k)
test.keywords.create('should be equal',args=(tc_dict[k],'Passed'))
result = suite.run(output=xml_fpath)
Is there any way in robot.api by which we can execute the following code?
robot -b debug.txt --listener <ListenerLibrary> tests_with_listener.robot
Upvotes: 1
Views: 759
Reputation: 714
Finally, after going through robot framework source code I was able to get an answer. The solution is simple but it's not well-documented in robot.api docs.
From RF source code's run(settings=None, **options)
method from TestSuite class
If
options
are used, their names are the same as long command line options except without hyphens, and they also have the same semantics. Options that can be given on the command line multiple times can be passed as lists likevariable=['VAR1:value1', 'VAR2:value2']
. If such an option is used only once, it can be given also as a single string likevariable='VAR:value'
.
from robot.api import TestSuite,ResultWriter
tc_dict = {
'test case #1' : 'Passed'
'test case #2' : 'Failed'
}
suite = TestSuite('tests_with_listener.robot')
for k,v in tc_dict.items():
test = suite.tests.create(k)
test.keywords.create('should be equal',args=(tc_dict[k],'Passed'))
result = suite.run(xunit=xunit_fpath,report=html_fpath,log=log_fpath,listener='AllureReportLibrary.AllureListener')
Upvotes: 2
Reputation: 6961
In the documentation for the robot.api the note following note can be found:
APIs related to the command line entry points are exposed directly via the robot root package.
The referred documentation is robot.run or robot.run_cli.
Upvotes: 2