mardi 30 octobre 2018

Generating test cases in Robot framework data-driven approach

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

Aucun commentaire:

Enregistrer un commentaire