I have a question on how to avoid hard-coding test data into Robot framework test cases when using test templates.
I have test cases such as:
Test template Invalid Login
*** Test Cases *** LOGIN PASSWORD
Login admin admin ${INVALID_PWD}
Login student student ${INVALID_PWD}
Login learner learner ${INVALID_PWD}
Login staff staff ${INVALID_PWD}
and so on...
I like this approach as long as I don't have 100 or so logins and passwords. Then I'd need to hard-code it here, which seems like a bit too much work to me.
Another what I've tried is:
*** Test Cases ***
Mahara Invalid Login
[Template] Invalid ${login} with ${password}
admin aa
student aa
which makes it a bit simpler, but I don't like it either because it's just one test case with several different steps, each one using a different test data.
What I'd like to have is, say, a list of logins and passwords, or a dict in Python and make Robot framework use these to generate such test cases. However, I have no idea if it's possible.
I've searched a bit and, among other things, found this post: https://stackoverflow.com/a/25206407/10401931 that doesn't look promising.
Then, I've found several ways how to read .csv. I can achieve that in Python, but it doesn't answer my question, how to load what I read in .csv, into this data-driven approach in Python. Basically, what I think it comes down to is how to force test template to loop over a given list/dict given to it. Since Test template is basically a for loop, there might be a way to change this loop a bit. Or isn't there?
Another approach could be to generate the whole .robot test suite as a file in Python. Again, I know how to make this, but it seems like overengineering it a lot, I'd like to find an easier way to do so.
I'd appreciate a little nudge in the right direction.
Thank you
Just to make this complete here, I'll answer my question.
The following test case does the job I wanted:
*** Test Cases ***
Mahara Invalid Login
[Template] Invalid ${login} with ${password}
:FOR ${login} IN @{invalid_logins.keys()}
\ ${login} ${invalid_logins['${login}']}
In this case, I'm loading test data from a Python dictionary where the key is a login and a value a password.
Or I can use a .csv file and do something like:
Mahara Invalid Login
${all_rows}= Get All Rows ${invalid_login_file} ${DELIMITER} ${HEADER}
:FOR ${row} IN @{all_rows}
\ ${login}= Set Variable ${row[0]}
\ ${password}= Set Variable ${row[1]}
\ Invalid ${login} with ${password}
Get All Rows would be a custom keyword that I use to load data from a .csv file.
In both examples, I don't need to write much, just prepare test data and write one for loop in Python.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.