Reputation: 33
I've been able to create a test suite with multiple test cases programmatically via robot.api.TestSuite class. I've been able to successfully execute it and generate a report as well. What I'm missing is the option to generate the actual test cases file in .robot extension rather than "losing it" whenever my program stops. Is there some option to achieve this?
I've looked at the official (https://robot-framework.readthedocs.io/en/v3.1.1/index.html) but I didn't find a solution to my problem. Is there something I'm missing?
Upvotes: 0
Views: 526
Reputation: 1132
Robot Framework 4 has an API that allows creating the model, that is obtained when parsing a .robot file:
from robot.parsing.lexer.tokens import Token
from robot.parsing.model.blocks import File, TestCase, TestCaseSection
from robot.parsing.model.statements import SectionHeader, TestCaseName, KeywordCall
test_cases = TestCaseSection(
header=SectionHeader.from_params(Token.TESTCASE_HEADER),
body=[
TestCase(
header=TestCaseName.from_params("Testing 1,2,3"),
body=[
KeywordCall.from_params('Log To Console', args=('Dynamically generated test',)),
]
)
]
)
sections = [test_cases]
model = File(sections, 'testsuite.robot')
It is easy to generate a test suite from the model and execute it:
from robot.api import TestSuite
suite = TestSuite.from_model(model)
suite.run()
Of course the model can also be written to a .robot file:
model.save()
Upvotes: 0
Reputation: 386342
I don't think any such thing is supported by the robot API. You'll have to create your own function to convert an in-memory test suite to a file.
Upvotes: 3