Created
February 18, 2020 20:06
-
-
Save Tattoo/80a73e0af75efc07b6daac4828abdf64 to your computer and use it in GitHub Desktop.
Programmatically create a Robot Framework test suite, then programmatically create a version we can save on disk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example from https://robot-framework.readthedocs.io/en/latest/autodoc/robot.running.html#examples | |
from robot.api import TestSuite | |
suite = TestSuite('Activate Skynet') | |
suite.resource.imports.library('OperatingSystem') | |
test = suite.tests.create('Should Activate Skynet') | |
test.keywords.create('Set Environment Variable', args=['SKYNET', 'activated']) | |
test.keywords.create('Environment Variable Should Be Set', args=['SKYNET']) | |
result = suite.run(output='skynet.xml') | |
# This is how you turn the suite created above to something we can write on disk | |
from robot.api import TestCaseFile | |
tc = TestCaseFile(source='foobar.robot') | |
settings_table = tc.start_table(['Settings']) | |
[settings_table.add_library(i.name) for i in suite.resource.imports] | |
testcases = tc.start_table(['Test Cases']) | |
for t in suite.tests: | |
parsing_tc = testcases.add(t.name) | |
[parsing_tc.add_step([k.name] + k.args) for k in test.keywords] | |
tc.save() | |
# $ cat foobar.robot | |
# *** Settings *** | |
# Library OperatingSystem | |
# *** Test Cases *** | |
# Should Activate Skynet | |
# Set Environment Variable SKYNET activated | |
# Environment Variable Should Be Set SKYNET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment