Changes between Version 2 and Version 3 of DeveloperGuidelines/Testing/EdenTest/WriteTestcase/Advanced
- Timestamp:
- 06/08/14 06:52:58 (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DeveloperGuidelines/Testing/EdenTest/WriteTestcase/Advanced
v2 v3 6 6 {{{ 7 7 *** Settings *** 8 Documentation 9 Library 10 Variables 11 Test Teardown 8 Documentation Test case to check the login functionality of Eden 9 Library Selenium2Library 10 Variables ../../execution/config.py 11 Test Teardown Close Browser 12 12 13 13 *** Test Cases *** 14 14 Login with valid email and valid passwd should be successful 15 Open Browser 16 Input Text auth_user_emailadmin@example.com17 Input Text auth_user_passwordtesting18 Click Button 19 Page Should Contain 15 Open Browser http://${SERVER}/eden/default/user/login 16 Input Text auth_user_email admin@example.com 17 Input Text auth_user_password testing 18 Click Button xpath=//input[@class='btn' and @value='Login'] 19 Page Should Contain Logged in 20 20 21 21 Login with invalid email and valid passwd should fail 22 Open Browser 23 Input Text auth_user_emailnottheadmin@example.com24 Input Text auth_user_passwordtesting25 Click Button 26 Page Should Contain 22 Open Browser http://${SERVER}/eden/default/user/login 23 Input Text auth_user_email nottheadmin@example.com 24 Input Text auth_user_password testing 25 Click Button xpath=//input[@class='btn' and @value='Login'] 26 Page Should Contain Invalid login 27 27 }}} 28 28 … … 48 48 {{{ 49 49 *** Variables *** 50 ${LOGIN URL} 51 ${SUBMIT} 52 ${EMAIL ID} 53 ${PASSWORD ID} 50 ${LOGIN URL} http://${SERVER}/eden/default/user/login 51 ${SUBMIT} xpath=//input[@class='btn' and @value='Login'] 52 ${EMAIL ID} auth_user_email 53 ${PASSWORD ID} auth_user_password 54 54 55 55 56 56 *** Test Cases *** 57 57 Login with valid email and valid passwd should be successful 58 Open Browser 59 Input Text ${EMAIL}admin@example.com60 Input Text ${PASSWORD}testing61 Click Button 62 Page Should Contain 58 Open Browser ${LOGIN URL} 59 Input Text ${EMAIL} admin@example.com 60 Input Text ${PASSWORD} testing 61 Click Button ${SUBMIT} 62 Page Should Contain Logged in 63 63 64 64 Login with invalid email and valid passwd should be successful 65 Open Browser 66 Input Text ${EMAIL}nottheadmin@example.com67 Input Text ${PASSWORD}testing68 Click Button 69 Page Should Contain 65 Open Browser ${LOGIN URL} 66 Input Text ${EMAIL} nottheadmin@example.com 67 Input Text ${PASSWORD} testing 68 Click Button ${SUBMIT} 69 Page Should Contain Invalid login 70 70 }}} 71 71 … … 88 88 *** Keywords *** 89 89 Login with email and passwd 90 [Documentation] 91 [Arguments] ${email}${passwd}92 Open Browser 93 Input Text ${EMAIL ID}${email}94 Input Text ${PASSWORD ID}${passwd}95 Click Button 90 [Documentation] Opens a browser to login url, inputs username and password 91 [Arguments] ${email} ${passwd} 92 Open Browser ${LOGIN URL} 93 Input Text ${EMAIL ID} ${email} 94 Input Text ${PASSWORD ID} ${passwd} 95 Click Button ${SUBMIT} 96 96 97 97 *** Test Cases *** 98 98 Login with valid email and valid passwd should be successful 99 Login with email and passwd admin@example.comtesting100 Page Should Contain 99 Login with email and passwd admin@example.com testing 100 Page Should Contain Logged in 101 101 102 102 Login with invalid email and valid passwd should be successful 103 Login with email and passwd iamnottheadmin@example.comtesting104 Page Should Contain 103 Login with email and passwd nottheadmin@example.com testing 104 Page Should Contain Invalid login 105 105 }}} 106 106 … … 110 110 111 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.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. 113 113 114 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 separate testcase. Example follows. 114 115 115 116 === Using Data-Driven Testing === … … 118 119 {{{ 119 120 *** Settings *** 120 Documentation 121 Library 122 Variables 123 Test Teardown 124 Test Template 121 Documentation Test case to check the login functionality of Eden 122 Library Selenium2Library 123 Variables ../../execution/config.py 124 Test Teardown Close Browser 125 Test Template Login should fail 125 126 126 127 127 128 *** Variables *** 128 ${LOGIN URL} 129 ${SUBMIT} 130 ${EMAIL ID} 131 ${PASSWORD ID} 129 ${LOGIN URL} http://${SERVER}/eden/default/user/login 130 ${SUBMIT} xpath=//input[@class='btn' and @value='Login'] 131 ${EMAIL ID} auth_user_email 132 ${PASSWORD ID} auth_user_password 132 133 133 134 134 135 *** Keywords *** 135 136 Login with email and passwd 136 [Documentation] 137 [Arguments] ${email}${passwd}138 Open Browser 139 Input Text ${EMAIL ID}${email}140 Input Text ${PASSWORD ID}${passwd}141 Click Button 137 [Documentation] Opens a browser to login url, inputs username and password 138 [Arguments] ${email} ${passwd} 139 Open Browser ${LOGIN URL} 140 Input Text ${EMAIL ID} ${email} 141 Input Text ${PASSWORD ID} ${passwd} 142 Click Button ${SUBMIT} 142 143 143 144 Login should fail 144 [Documentation] 145 [Arguments] ${email}${passwd}146 Login with email and passwd ${email}${passwd}147 Page Should Contain 145 [Documentation] Opens a browser to login url, inputs invalid username or password and checks for failure 146 [Arguments] ${email} ${passwd} 147 Login with email and passwd ${email} ${passwd} 148 Page Should Contain Invalid login 148 149 149 150 150 *** Test Cases *** email password151 The email is invalid nottheadmin@example.comtesting152 The password is Invalid admin@example.comincorrect153 Both are Invalid nottheadmin@example.comincorrect151 *** Test Cases *** 152 The email is invalid nottheadmin@example.com testing 153 The password is Invalid admin@example.com incorrect 154 Both are Invalid nottheadmin@example.com incorrect 154 155 }}} 155 156 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 and157 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. 157 158 158 159 === Further exercise === … … 160 161 * Login form validation 161 162 * Login should pass [email] [password] 163 Also, try and improve the Teardown and Setup of the above tests. Refer to this [http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html#test-setup-and-teardown documentation] for help.