You can store your test user configuration/properties in a resource file (say test_properties.txt) as below:
=== test_properties.txt ===
| *** Variables *** |
| ${tp_app_url} | http://yourapp.com |
| ${tp_browser} | firefox |
| ###### user roles to test with - admin, non-admin, regular |
| ${tp_user_type} | admin |
| ###### test users |
| ${tp_admin_user} | admin@app.com |
| ${tp_admin_password} | admin@123 |
| ${tp_regular_user} | regular@app.com |
| ${tp_regular_password} | regular@123 |
Here, the user role/type with which you want to test your application is defined as:
| ###### user roles to test with - admin, regular |
| ${tp_user_type} | admin |
Your test suite file can then import above resource file as below:
=== testsuite.txt ===
| *** settings *** |
| Library | Selenium2Library |
| Resource | test_properties.txt |
| *** test cases *** |
| Validate Page Controls |
| | Open Browser To Login Page | ${tp_user_type} |
| | Page Controls Should be Visible | ${tp_user_type} |
| *** keywords *** |
| Open Browser To Login Page |
| | [Arguments] | ${user_type} |
| | Open Browser | ${tp_app_url} | ${tp_browser} |
| | Input Username | ${tp_${user_type}_user} |
| | Input Password | ${tp_${user_type}_password} |
| | Submit Credentials |
| | Title Should Be | Welcome Page |
| Input Username |
| | [Arguments] | ${username} |
| | Input Text | username_field | ${username} |
| Input Password |
| | [Arguments] | ${password} |
| | Input Text | password_field | ${password} |
| Submit Credentials |
| | Click Button | login_button |
| Page Controls Should be Visible |
| | [Arguments] | ${user_type} |
Your code related to validating the page controls could reside in the keyword Page Controls Should be Visible
which will perform the checks based on the user type argument.
Note: Test user's userId and password variables are formed here by embedding the user type variable as: ${tp_${user_type}_user}
which in turn gets evaluated as ${tp_admin_user}
in our case.
During execution, you can pass the value of ${tp_user_type} on command line, and it override the value set in the resource file.
pybot --variable tp_user_type:non-admin path/to/your/testfile
If you want to run the same tests with multiple user types, you can create a batch file like:
pybot --variable tp_user_type:non-admin path/to/your/testfile
pybot --variable tp_user_type:admin path/to/your/testfile
pybot --variable tp_user_type:regular path/to/your/testfile
I'm sure there will be a better solution than this for your problem. Ideally, the keywords defined above in the test suite file should reside in a resource file. You can also create a data-driven test to run your template keyword (which validates page controls) for each user type.