How to split robot testcases using colon, so that each will be treated as separate testcase? - robotframework

I have 3 test cases which will test the same functionality. It will use same keywords as shown below.
Instead of writing three different test cases "test-1151,test-2125,test-2126", I want to write one test case separated with colons as shown below. But robot should treat this as three seperate test case and it should show pass/fail test case count accordingly.
test.robot:
*** Settings ***
Library lib.test
*** Variables ***
*** Keywords ***
*** Test Cases ***
test-1151:test-2125:test-2126
[Documentation] test_sample
[Tags] sanity
Install Adobe software
Launch the app
If I run the above robot file, robot is taking "test-1151:test-2125:test-2126" as one test case. How to tell robot to treat this as three different test cases (separated with colon)?

Why don't you turn the detail of the test case into a keyword? Then write three test cases that call the keyword?
This might be an alternative option for you:
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#data-driven-style
Basically have one test template which would be the same, maybe have some arguments for parameters that will change based on test cases. You can then have many test cases doing exactly the same or slightly different things in a short and concise notation.

It's unclear what your real goals are. It seems that you want to see three items in the report, "test-1151", "test-2125", and "test-2126", but that you actually only want to run that test once.
I'm guessing that those names correspond to either a test plan or an item in a ticketing system of some sort.
My recommendation is to use tags to tag your test. You can give the test any name you want, and then give it tags for the names you want to see in the report. Once the test runs, the report can give you statistics based on tag.
For example:
test-1151:test-2125:test-2126
[Documentation] test_sample
[Tags] sanity test-1151 test-2125 test-2126
Install Adobe software
Launch the app
To answer your specific question of whether you can have this one test reported three times, the answer is "no". It will show up in the logs and report as a single test. However, the report also includes test status by tag, so you will see one item in the report for each tag.

Related

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

Robot Framework Set test documentation multiline

I would like use KW "Set test documentation" with multiline with RobotFW
The return to the line (\n) does not work with this KW
Someone have solution?
Setting multiline documentation is tricky because robot has some odd rules about its documentation. From the user guide section titled Documentation Formatting:
Starting from Robot Framework 2.7.2, all regular text in the formatted HTML documentation is represented as paragraphs. In practice, lines separated by a single newline will be combined in a paragraph regardless whether the newline is added manually or automatically. Multiple paragraphs can be separated with an empty line (i.e. two newlines) and also tables, lists, and other specially formatted blocks discussed in subsequent sections end a paragraph.
In a nutshell, that means that each line needs to end with two newlines.
Example:
*** Variables ***
${var1} this is var1
${var2} this is var2
*** Test Cases ***
Example of setting multiline test documentation
set test documentation
... var1: ${var1}\n\nvar2: ${var2}
The above will appear in log.html like this:
If your goal is to document the values of variables, robot also supports a simple markup for creating tables. The following example shows how to create a table. In this example I use the ability to append to the documentation rather than replace it:
*** Variables ***
${var1} this is var1
${var2} this is var2
*** Test Cases ***
Example 2: documentation with embedded table
set test documentation
... | var1 | ${var1} | \n
set test documentation
... | var2 | ${var2} | \n append=True
The above will appear in log.html like this:
I am not sure if we can do that directly, i found a workaround after taking reference from Bryan's reply on this thread.
Testcase level variables in [Documentation] for robot framework
Here multi lines are first mentioned in [Documentation] section and then this section can be used by Set test documentation kw.
*** Variables***
${SystemUnderTest} Staging
*** Test cases***
Device Test
Set Test Variable ${device} iPhone
[Documentation] Device is:
... System is: ${SystemUnderTest}
Substitute vars in documentation
*** Keywords ***
Substitute vars in documentation
${doc}= replace variables ${test documentation} # This will substitute the variables in documentation with their values , ${test documentation} is an inbuilt keyword which actually parse the content of [Documentation]
set test documentation ${doc} append=True #now the set test docuemntation will take the multi line input from documentation section
refer below link for further details http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Test%20Documentation

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

Is it possible to write Robot Framework tests (not keywords) in Python?

Is it possible to write Robot Framework tests in Python instead of the .txt format?
Behind the scenes it looks like the .txt test get converted into Python by pybot so I'm hoping that this is simply a matter of importing the right library and inheriting from the right class but I haven't been able to figure out how to do that.
(We already have a bunch of suites and have keywords written in both formats but sometimes the RF syntax makes it very difficult to do things that are simple in Python. I understand it would be possible to just write a Python keyword for each test plus 'wrap' setup and teardown functions the same way, but that seems cumbersome.)
Robot does not convert your test cases to python behind the scenes before running them. Instead, it parses the test cases, then iterates over each keyword, calling the code that implements the keyword. There isn't ever a stage where there's a completely pure python representation of a test case.
It is not possible to write tests in python, and have those tests run alongside traditional robot tests by the provided test runner. Like you said in your question, your only option is to put all of your logic for a single test case in a single keyword, and call that keyword from a test case.
It is possible to create and execute tests in python solely via the published API. This might not be what you're really asking for, because ultimately you're still creating keywords, you're just creating them via python.
from robot.api import TestSuite
suite = TestSuite('Activate Skynet')
suite.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 example was taken from here:
http://robot-framework.readthedocs.org/en/2.8.1/autodoc/robot.running.html
Well, you should not care if your python code represents tests or keywords as long as you code the logic of the tests in python.
The best you can do is to keep some html tables in robot format. Each line would be a call for a keyword. The keyword could be implemented in python, and, logically, represents a whole test (although in robot terminology it is still a "keyword").
This post shows how you can have access to the robot context from your python code.
robot variables
BuiltIn().get_variable_value("${USERNAME}")
java keywords
from com.mycompany.myproject.testtools import LoginRobotKeyword
LoginRobotKeywords().login(user, pwd)
robot keywords
BuiltIn().run_keyword("check user connected", user)
Robotframework does not support writting test cases in python directly. I've submitted an enhancement PR, check it here
https://github.com/robotframework/robotframework/issues/3128
But I've tried to do that by moving all the test cases logic to python code, and make RF test cases just a entry point to them.
Here is an example.
We could create a python file to include all testing logic and setup/teardown logic, like this
# *** case0001.py *****
from SchoolClass import SchoolClass
schCla = SchoolClass()
class case0001:
def steps(self):
print('''\n\n***** step 1 **** add school class \n''')
self.ret1 = schCla.add_school_class('grade#1', 'class#1', 60)
assert self.ret1['retcode'] == 0
print('''\n\n***** step 2 **** list school class to check\n''')
ret = schCla.list_school_class(1)
schCla.classlist_should_contain(ret['retlist'],
'grade#1',
'class#1',
60,
self.ret1['id'])
def setup(self):
pass
def teardown(self):
schCla.delete_school_class(self.ret1['id'])
And then we creat a Robot file. In which all RF test cases are in the same form and just work as entry points to python test cases above.
like this
*** Settings ***
Library cases/case0001.py WITH NAME C000001
Library cases/case0002.py WITH NAME C000002
*** Test Cases ***
add class - tc000001
[Setup] C000001.setup
C000001.steps
[Teardown] C000001.teardown
add class - tc000002
[Setup] C000002.setup
C000002.steps
[Teardown] C000002.teardown
You could see, in this way, the RF testcases are similar. We could even create a tool to auto generate them by scanning Python testcases.

What do the numbers before test testcase in Test lab indicate?

What do the numbers before test testcase in Test lab indicate? For example:
[1]Login with ur……
What does the [1] mean?
the [1] before the test case in the test lab indicates the number of occurrences of that test case. If you add the same test case twice it will look something like this.
[1] Test Case Name
[2] Test Case Name
it's the number of instances of that test case in the Execution Grid.
each time you add this test case to the grid you get a new instance added with a new number beside it.
It took me a while to understand instances of test 'cases'. I was thinking of it all wrong (because the test lab is where you run the tests, right?).
When you want a specific set of parameters for a test, use test configurations in the Test Plan.
Once the values are set, you create your instance in the Test Lab from the configuration so that you can execute it.
If, on the other hand, you have an instance in Test Lab with some specific values that you like, you can use right-click -> generate configuration.
This creates a configuration for you and you can give it a name of your choosing (something that I really wanted to do in the test lab, until I discovered how Configurations work).
There is also a button in the test plan configurations tab to 'push' updated values to the Test Lab. So while there is a disconnect between configurations and test lab (by design), but it is not such a disconnect that you can't connect them when you want.

Resources