Reputation: 197
I am using Robot Framework and I was wondering if it possible to run only particular steps within a test-case. For example, if I want to do a test in which, I just input the username and Submit, will I have to write a different test-case or can I conditionally run the test-case listed below ?
In other words, can Invalid Login(Testcase listed below) take parameters and execute only specific steps. For example, run Input Username and Submit or Run Input Password and Submit or Run both of these and then submit.
*** Test Cases ***
Invalid Login
Open Browser To Login Page
Input Username demo
Input Password check
Submit Credentials
Login Should Have Failed
[Teardown] Close Browser
Thanks!
Upvotes: 2
Views: 2290
Reputation: 95
What we did is to use the TAGS in the test name. And then when you run the command you can use the option -i or -e (include or exclude) the specific tags that you want to run or not run. So in your case:
*** Test Cases ***
Invalid Login
Open Browser To Login Page
[Tags] specific_tags
Input Username demo
[Tags] specific_tags
Input Password check
Submit Credentials
[Tags] specific_tags
Login Should Have Failed
[Teardown] Close Browser
And then you run with the command:
robot -i specific_tags your_robot_file.robot
Hope it can help someone even the question is quite old
Upvotes: 0
Reputation: 385830
In my opinion, the best approach is to have separate tests.
If you insist on having a test case with optional steps, the way I would do this is to put the optional parts in one or more keywords, and then use Run Keyword If
to conditionally exclude a step.
For example:
*** Keywords ***
| Do additional validation
| | log | doing additional validation...
*** Test Cases ***
| Invalid Login
| | Open Browser To Login Page
| | Input Username | demo
| | Input Password | check
| | Submit Credentials
| | Login Should Have Failed
| | # run the following only if "${DO_MORE}" is defined
| | Run keyword if | ${DO_MORE} == True
| | ... | Do additional validation
| | [Teardown] | Close Browser
Upvotes: 0
Reputation: 2270
You should look into how to write data driven tests for Robot Framework. A good example is provided with Robot Framework:
https://bitbucket.org/robotframework/webdemo/wiki/Home#rst-header-test-cases
Upvotes: 1