Changes between Version 1 and Version 2 of DeveloperGuidelines/Testing/EdenTest/WriteTestcase


Ignore:
Timestamp:
06/06/14 10:08:53 (11 years ago)
Author:
Arnav Sharma
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/Testing/EdenTest/WriteTestcase

    v1 v2  
    1717Before 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].
    1818
    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'''
     19As !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'''.
    2020
    2121=== What we have to do? ===
    2222
    23 So, our testcase needs to do the following
     23Let 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 
    2425
    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 ===
     27Follow these steps:
     28* Create a file named login_functionality.txt inside the folder '''/tests/implementation/testsuites'''.
     29* Write the testcase below in it
    3130
    32 === Adding variables ===
     31{{{
     32*** Settings ***
     33Library    Selenium2Library
     34Variables    ../../execution/config.py #contains the local settings
     35Test Teardown    Close Browser #close the browser after running the test
    3336
    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 ***
     38Login 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
    3544
    36 Inside the variables section of the testsuite file, indicated by `*** Variables ***` add the variables as
     45}}}
     46
     47Note: Please make sure that the various arguments are separated by two spaces at least.
    3748[[BR]]
    3849
    39 ''' variable name [delimited by two tabs/8 spaces] id/url/etc '''.
    40 [[BR]]
    41 For ex:
     50Now run the testsuite login_functionality.txt. ([http://eden.sahanafoundation.org/wiki/DeveloperGuidelines/EdenTest#UsingEdenTest Using EdenTest])
    4251{{{
    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
     52pybot tests/implementation/testsuites/login_functionality.txt.
    7153}}}
    7254
     
    7456
    7557
    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 ===
    7759
     60[Ignore the `*** Settings ***` section for the time being.]
     61[[BR]]
     62As 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
     64If 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.
    7865
    7966To 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'''