Changes between Version 1 and Version 2 of DeveloperGuidelines/Testing/EdenTest/WriteTestcase
- Timestamp:
- 06/06/14 10:08:53 (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DeveloperGuidelines/Testing/EdenTest/WriteTestcase
v1 v2 17 17 Before writing your first testcase, please make sure that you have !EdenTest set up, you understand the directory structure and the know-how of how to run !EdenTest and see its results. If not, go through [http://eden.sahanafoundation.org/wiki/DeveloperGuidelines/EdenTest EdenTest]. 18 18 19 Here is a description of how to write a testcase in !EdenTest. Say for example, we want to test if a new staff member can be added or not. As the functionality is under hrm, open the testsuite file ''/tests/implementation/testsuites/hrm/human_resource.txt''. If the functionality to be tested does not fall under any of the existing testsuites (eg hrm, projects etc), create a new folder/file under '''/tests/implementation/testsuites''' 19 As !EdenTest is built on the principle of '''ATDD''' which is a practice in which the acceptance criteria is decided, with examples, and then distilled into a set of concrete acceptance tests before development begins. To say it simply, write the tests which covers your functionality before writing the code for the functionality. Then, write the code for that functionality so that it passes the tests. The '''T''' aspect of '''F.I.R.S.T'''. 20 20 21 21 === What we have to do? === 22 22 23 So, our testcase needs to do the following 23 Let us assume you have to implement a simple login form. The user story is as follows: It asks for the email and password. If the login is successful, it redirects to the homepage of Eden, if unsuccessful it shows an error. We will write the testcase to check if successful login works. 24 24 25 25 1. Go to ''eden/hrm/staff/create'' 26 2. Select an organisation from dropdown list National Society / Branch. 27 3. Input text into the person name field 28 4. Input text into the person email field 29 5. Submit the CRUD form 30 6. Check for confirmation message 26 === Writing the testcase === 27 Follow these steps: 28 * Create a file named login_functionality.txt inside the folder '''/tests/implementation/testsuites'''. 29 * Write the testcase below in it 31 30 32 === Adding variables === 31 {{{ 32 *** Settings *** 33 Library Selenium2Library 34 Variables ../../execution/config.py #contains the local settings 35 Test Teardown Close Browser #close the browser after running the test 33 36 34 Before we write the testcase, we should assign variables to the link we are going to visit, ids we are going to use etc. 37 *** Test Cases *** 38 Login with valid email and passwd should be successful #name of the testcase. 39 Open Browser http://${SERVER}/eden/default/user/login 40 Input Text auth_user_email admin@example.com 41 Input Text auth_user_password testing 42 Click Button xpath=//input[@class='btn' and @value='Login'] 43 Page Should Contain Logged in 35 44 36 Inside the variables section of the testsuite file, indicated by `*** Variables ***` add the variables as 45 }}} 46 47 Note: Please make sure that the various arguments are separated by two spaces at least. 37 48 [[BR]] 38 49 39 ''' variable name [delimited by two tabs/8 spaces] id/url/etc '''. 40 [[BR]] 41 For ex: 50 Now run the testsuite login_functionality.txt. ([http://eden.sahanafoundation.org/wiki/DeveloperGuidelines/EdenTest#UsingEdenTest Using EdenTest]) 42 51 {{{ 43 ${StaffCreateUrl} ${STAFF URL}/create #${STAFF URL} already exists 44 ${HrmOrgSelector} hrm_human_resource_organisation_id #Selector for the dropdown list National Society / Branch. 45 ${PersonNameField} hrm_human_resource_person_id_full_name #ID of Name field 46 ${PersonEmailField} hrm_human_resource_person_id_email #ID of email field 47 }}} 48 49 === Writing the test case === 50 51 Add this to the `*** Test Cases ***` section of the testsuite file. 52 53 {{{ 54 Create Staff 55 Go To ${StaffCreateUrl} 56 Select From List By Label ${HrmOrgSelector} Indian Red Cross Society 57 Input Text ${PersonNameField} Fname Lname 58 Input Text ${PersonEmailField} flname@email.com 59 Submit CRUD Form 60 Should Show Confirmation 61 }}} 62 63 Note: Please make sure that the various arguments are separated by two spaces. 64 [[BR]] 65 [[BR]] 66 67 Compare the section '''What we have to do?''' and the testcase written above and marvel the beauty of Robot Framework. Run the testcase using the command 68 69 {{{ 70 pybot tests/implementation/testsuites 52 pybot tests/implementation/testsuites/login_functionality.txt. 71 53 }}} 72 54 … … 74 56 75 57 76 `Go To`, `Select From List By Label`, `Input Text`, `Submit CRUD Form` and `Should Show Confirmation` are all keywords imported using '''main.txt''' in the `*** Settings ***` section which in turn imports all the keyword files. If your use case requires a keyword that does not exist, create one under '''/tests/implementation/resources'' 58 === Understanding the testcase === 77 59 60 [Ignore the `*** Settings ***` section for the time being.] 61 [[BR]] 62 As you can see, the name of the testcase is very descriptive and describes the objective. '''Open Browser''', '''Input Text''', '''Click Button''' and '''Page Should Contain''' are all keywords (functions) implemented in Selenium2Library. The beauty of writing tests this way is that they are easy to read and understand, thus eliminating the need to explain them. 63 64 If you have understood how the above above testcase is written, try writing the testcase '''Login with invalid email and passwd should fail'''. It should be fairly simple. 78 65 79 66 To understand the selenium keywords visit [http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html Selenium2Library Keyword Documentation] and the documentation of keywords implemented under !EdenTest in '''tests/docs'''