How to make Robot Framework Data Driven? - robotframework

In a test case I am able to read a csv file by following code
${value} = read_csv_file TestData.csv
Set Test Variable ${value}
log ${value}
But now the question comes why my test case will repeat for different data. Although if I want to repeat any step I can use for loop but I want to repeat this for entire test suite.
:FOR ${newvalue} in #{value}
\ Select Product #{newvalue}[0]
Templates are not preferred because they make the framework totally data-driven and also they have certain limitation.

As you don't want to use templates, you can also use keyword-driven approach of robot framework.
You need to create a robot resource file, define your keyword and call it where you want this particular code in your robot test suite.
***keywords***
Read and display
[Argument] ${filename}
${value} = read_csv_file ${filename}
Set Test Variable ${value}
log ${value}

Related

How to add Info to custom keyword Log

In Robot Framework, when you create a custom keyword using the *** Keyword *** section of .robot file, is there a way to print an INFO message in the log file? I've tried using BuiltIn.Log keyword, but it creates a new keyword section where the INFO is written.
I want to get INFO in custom keyword this way:
Info in Keyword execution
But currently, my only option is: Info inside BuiltIn.Log definition
Is there a way to add INFO directly to my custom keyword without using Python API?
Did you try Log to console Typing text ${User} into text field 'username' like this?
To my knowledge what you are attempting, is unfortunately not doable. This way of embedding messages can be done by the robot.logger or Python's logging api - More info in the Robot Framework User Guide
However in addition to using the Log keyword, you may alleviate the need by first adding a documentation string on your keywords - the first line is always shown in the Documentation section of the keyword. Additionally by enabling Trace on the log file you'll get at least the Arguments and Return values shown on each keyword.
The Documentation is added with the [Documentation] tag similar to
Custom Keyword
[Documentation] This string is shown completely until I leave at least
... One empty row.
...
... This is shown only in the library documentation file.
And logging modes are changed with a launch option -L or --loglevel, to enable Trace mode, simply add the option when launching your robot.
robot -t TestName -s SuiteName -L TRACE .\Path\to\Tests

How can we define, not one but a set of instructions for an if loop in robotframework?

I am trying to give more than one instruction after a "Run Keyword If" method, but the syntax allows me to give just one? How i can give multiple instructions after condition executed as true?
If you want an easy to read solution you could create another keyword with all your other actions inside of it. For example.
run keyword if '${a}'=='${a}' my keyword
my keyword
[Documentation] This is documentation
Action A
Action B
You can use the keyword Run Keywords with AND connector. Example given below:
Run Keyword If '${TEST1}'=='${TEST2}' Run Keywords Keyword1 AND Keyword2

Robot Frame Work:: Gherkin execution error

I wrote my First Gherkin Script (first.robot) when running same i am getting "No keyword with name 'Given' found." Error. Is there any Library i have to include or should i do any pip install something??
***
Gherkin Style TC
[Documentation] Let me try this time
Given Environement Setup Ready
When Required URL Get Loaded
Then Wait For Meters List to Appear
And Capture the list of Meters
Then CloseBrowser
***
You have two spaces after Given (and the others) but robot uses two spaces to separate keywords from arguments. You must have only one space after Given, When, etc. otherwise robot will think that Given is a keyword.
Gherkin Style TC
[Documentation] Let me try this time
Given Environement Setup Ready
When Required URL Get Loaded
Then Wait For Meters List to Appear
And Capture the list of Meters
Then CloseBrowser
Some people add extra space before the given/when/then to make things line up nicely:
Gherkin Style TC
[Documentation] Let me try this time
Given Environement Setup Ready
When Required URL Get Loaded
Then Wait For Meters List to Appear
And Capture the list of Meters
Then CloseBrowser

How to write a custom report name in Robotframework

I am trying to change the default report name (report.html) inside my test suite but can't find a way.
What are the different way to specify the report name ?
You should use the --report command line option (see User Guide.)
For example:
pybot --report myoutput.html mysuite.robot
will name your report myoutput.html instead of the default output.html

How to define a keyword as a new test case

I'm currently developing a couple of test cases with robotframework to compare some excel value with value inside our database.
I have to do it inside a specific test case as it is deploy on zephyr.
I am checking each value inside this test case by calling a homemade Keyword that does :
Run Keyword Should Contain ${valeurExcel1} ${valeurBDD1}
Run Keyword Should Contain ${valeurExcel2} ${valeurBDD2}
etc...
I need every single one of those "Should Contain" to be display in a separated row in the report.html
It currently only appear as one row as it is one test case.
Is there anyway to specify to robot framework that i want him to consider every "Should Contain" as a unique test case and to display it in a row on the report.html ?
(Maybe by tagging ?)
No you can't. If you want a row for each "should contain" then each of those call should be made in its own test case.
But I think the problem lies in your "I have to do it inside a specific test case as it is deploy on zephyr". Whatever you need to do before/after a test case, can be done in a "suite setup" (and "suite teardown"). So you could have this kind of architecture:
*** Settings ***
Suite Setup deploy SUT / Zephyr
Suite Teardown shutdown SUT / Zephyr
*** Test Cases ***
tc1
Run Keyword Should Contain ${valeurExcel1} ${valeurBDD1}
tc2
Run Keyword Should Contain ${valeurExcel2} ${valeurBDD2}

Resources