0

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.