| | 109 | == Data driven testing == |
| | 110 | |
| | 111 | === What is Data-Driven testing? === |
| | 112 | Data-driven approach to testing is where test cases use only one higher-level keyword, normally created as a user keyword (as shown above), that hides the actual test workflow. These tests are very useful when there is a need to test the same scenario with different input and/or output data. It would be possible to repeat the same keyword with every test, but the test template functionality allows specifying the keyword to use only once. Thus, a testsuite file will run the same Test template with a lot of test data, each of which will be a testcase. Example follows. |
| | 113 | |
| | 114 | |
| | 115 | === Using Data-Driven Testing === |
| | 116 | Now, testing the login functionality with various permutations of email and password can be done using the Data-driven approach. Here is how: |
| | 117 | |
| | 118 | {{{ |
| | 119 | *** Settings *** |
| | 120 | Documentation Test case to check the login functionality of Eden |
| | 121 | Library Selenium2Library |
| | 122 | Variables ../../execution/config.py |
| | 123 | Test Teardown Close Browser |
| | 124 | Test Template Login should fail |
| | 125 | |
| | 126 | |
| | 127 | *** Variables *** |
| | 128 | ${LOGIN URL} http://${SERVER}/eden/default/user/login |
| | 129 | ${SUBMIT} xpath=//input[@class='btn' and @value='Login'] |
| | 130 | ${EMAIL ID} auth_user_email |
| | 131 | ${PASSWORD ID} auth_user_password |
| | 132 | |
| | 133 | |
| | 134 | *** Keywords *** |
| | 135 | Login with email and passwd |
| | 136 | [Documentation] Opens a browser to login url, inputs username and password |
| | 137 | [Arguments] ${email} ${passwd} |
| | 138 | Open Browser ${LOGIN URL} |
| | 139 | Input Text ${EMAIL ID} ${email} |
| | 140 | Input Text ${PASSWORD ID} ${passwd} |
| | 141 | Click Button ${SUBMIT} |
| | 142 | |
| | 143 | Login should fail |
| | 144 | [Documentation] Opens a browser to login url, inputs invalid username or password and checks for failure |
| | 145 | [Arguments] ${email} ${passwd} |
| | 146 | Login with email and passwd ${email} ${passwd} |
| | 147 | Page Should Contain Invalid login |
| | 148 | |
| | 149 | |
| | 150 | *** Test Cases *** email password |
| | 151 | The email is invalid nottheadmin@example.com testing |
| | 152 | The password is Invalid admin@example.com incorrect |
| | 153 | Both are Invalid nottheadmin@example.com incorrect |
| | 154 | }}} |
| | 155 | |
| | 156 | There are three test cases above, all of which implement the keyword `Login should fail` given against the setting `Test Template`. All the testcases implement the keyword with the arguments given against it. The keyword `Login should fail` takes two arguments and asserts that the login should fail for that case. Run the tests and |
| | 157 | |
| | 158 | === Further exercise === |
| | 159 | As an exercise, implement these two tests in a separate file |
| | 160 | * Login form validation |
| | 161 | * Login should pass [email] [password] |