How to Parameterize test cases in robot framework? - robotframework

I need to provide multiple inputs to a testcase using robot framework. I had done similarly in pytest with parameterization, is there any similar way to do in robot framework as well..

You can use variables for this.
for example
robot --variable HOST:10.0.0.2:1234 /testfolder/
variable ${HOST} will have value 10.0.0.2:1234 in this testrun

I think you can use Arguments using Robot framework. Keywords can accept zero or more arguments, and some arguments may have default values. It is best way to supply parameters to your testcase/keyword based on input required. More documentation can be found at - http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#using-arguments

Approach that i made:
As i'm calling my robot call only once for a suite and in test suite each indivdual test case may have different no and different variables.
I made a json file to have:
test suite name >
test case name >
test case params
max no of params in that test suite .
I'm adding a common tag as param1 param2 for test cases based on no of params for each tc and iterate the call for the robot test suite with above tags and variable as ${params} with tag name. So that only those test cases will be picked.
Param details i'm reading the json file in the test case based on the variable passed ${params}.
eg,.
robot --variable params:param1 -i param1
robot --variable params:param2 -i param2
TestCase[xxx]: Sample Test Case
[Documentation] Sample Test Case
[Tags] Sanity param1 param2 param3

Related

Is there a way to generate test report in robot framework which says total test case = 0, passed = 0 , failed = 0?

When we run test suites using a tag say "ABC" and if none of the tests are matching the given tag, there will be no report generated.
But is there a way to generate report that says zero test cases were executed in robot framework?
There is option to do exactly that, just add option --runemptysuite to your command.Here's a link
robot --runemptysuite --include ABC test.robot

Robotframework Change testcase name with variable

Is there any possible to change testcase name with variable like below?
(I don't want to change name from python side)
*** Variables ***
${country} US
*** Test Cases ***
test_${country}
As far as I know, it isn't possible to use a variable inside a test case name. It follows the same logic as normal Python functions, so normally, it isn't possible.
Instead, you can use the variable in the setup or in the test case directly to modify it's behaviour.
If you want to generate test cases based on a variable, you can write a (python) script that can generate the needed file/test cases with the corresponding values. Or, even better, use an Model-Based Testing tool to produce them.
Yes, you can. The way you have shown it should work. Are you facing any issue with that? If yes, pls provide the detailed error.
Yes this is supported.
example:-
*** Test Cases ***
Test title ${name}
[Tags] DEBUG
Log Welcome ${name}
output:-
robot --variable name:sample eg.robot

Defining setup, teardown and variable in argumentfile in robotframework

Basically 2 issues:
1. I plan to execute multiple test cases from argument file. The structure would look like that:
SOME_PATH/
-test_cases/
-some_keywords/
-argumentfile.txt
How should i define a suite setup and teardown for all those test cases executed from file (-A file)?
From what i know:
a) I could execute it in file with 1st and last test case, but the order of test cases may change so it is not desired.
b) provide it in init.robot and put it somewhere without test cases only to get the setup and teardown. This is because if I execute:
robot -i SOME_TAG -A argumentfile /path/to/init
and the init is in test_case folder it will execute the test_cases with a specific tag + those in a folder twice.
Is there any better way? Provide it, for example, in argumentfile?
2 How to provide PATH variable in argumentfiles in robotframework?
I know there is possibility to do:
--variable PATH:some/path/to/files
but is it not for test suite env?
How to get that variable to be visible in the file itself: ${PATH}/test_case_1.robot
For your 2nd question, you could create a temporary environment variable that you'd then use. Depending on the OS you're using, the way you'll do this will be different:
Windows:
set TESTS_PATH=some/path/here
robot -t %TESTS_PATH%/test_case_1.robot
Unix:
export TESTS_PATH="some/path/here"
robot -t $TESTS_PATH/test_case_1.robot
PS: you might want to avoid asking multiple, different questions in the same thread

Robot framework: Is there a way to write dynamic test cases?

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.
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

How to run tests in random order with robotframework maven plugin?

I am trying to run Robotframework testcases from eclipse with Robotframework-maven plugin. Can anyone tell me the configuration of POM.xml to run the testcases according to my given order instead of alphabetical order? For example, I have the following tags in the corresponding test suites:
TestSuit1--->
Testcase1.robot -- >MyTestcase1 [Tags] a
Testcase2.robot --- >MyTestcase2 [Tags] b
Testcase3.robot -- - > MyTestcase3 [Tags] c
I want to executes the above test cases random order. If I write in pom.xml
<includes_cli>b,a,c</includes_cli>
It executes the tests according to alphabetical order instead of my given order. Can anyone have a solution for that?
Br,
Dew
You can use --randomize option to execute the test cases in random order as below:
Case 1:
robot --randomize tests <Testcase1.robot>
tests: Test cases inside each test suite will be executed in random order
Case 2:
robot --randomize suites <path/to/Testsuite>
suites: All test suites will be executed in a random order, but test cases inside suites will run in the order they are defined
It looks like the latest version of the maven plugin has a randomize option:
http://robotframework.org/MavenPlugin/run-mojo.html#randomize
options are:
<randomize>all</randomize>
<randomize>suite</randomize>
<randomize>test</randomize>
with the default being no randomization.
Looks like the same options as for the --randomize command line argument for the robot command:
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#randomizing-execution-order

Resources