5

I am pretty new to robot framework. I would like to create test cases dynamically without having a input key-value driven approach.

Found some material that suggested the following:

suite = TestSuite('Example suite', doc='...')
tc = TestCase('Example test')
tc.add_step(TestStep('Log', args=['Hello, world!'])
suite.add_test(tc)

I dont see add_step in test case class, Will continue to look around and see if there are any solutions.

1 Answer 1

4

The TestSuite object has a keywords attribute which itself has a create method which can be used to create new keywords.

The robot framework api documentation gives this example:

from robot.api import TestSuite

suite = TestSuite('Activate Skynet')
suite.resource.imports.library('OperatingSystem')
test = suite.tests.create('Should Activate Skynet', tags=['smoke'])
test.keywords.create('Set Environment Variable', args=['SKYNET', 'activated'], type='setup')
test.keywords.create('Environment Variable Should Be Set', args=['SKYNET'])

The above gives you the same test as if you had written it like this:

*** Settings ***
Library    OperatingSystem

*** Test Cases ***
Should Activate Skynet
    [Tags]    smoke
    [Setup]    Set Environment Variable    SKYNET    activated
    Environment Variable Should Be Set    SKYNET
Sign up to request clarification or add additional context in comments.

2 Comments

This is exactly what i was looking for, thanks for pointing me to the documentation.
How to get the log.html and report.html after executing this?

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.