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

06/06/14 10:08:53 (10 years ago)
Arnav Sharma



  • 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 [ EdenTest].
    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'''.
    2121=== What we have to do? ===
    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.
    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
    32 === Adding variables ===
     32*** Settings ***
     33Library    Selenium2Library
     34Variables    ../../execution/ #contains the local settings
     35Test Teardown    Close Browser #close the browser after running the test
    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
     41    Input Text      auth_user_password      testing
     42    Click Button        xpath=//input[@class='btn' and @value='Login']
     43    Page Should Contain     Logged in
    36 Inside the variables section of the testsuite file, indicated by `*** Variables ***` add the variables as
     47Note: Please make sure that the various arguments are separated by two spaces at least.
    39 ''' variable name [delimited by two tabs/8 spaces] id/url/etc '''.
    40 [[BR]]
    41 For ex:
     50Now run the testsuite login_functionality.txt. ([ Using EdenTest])
    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 }}}
    49 === Writing the test case ===
    51 Add this to the `*** Test Cases ***` section of the testsuite file.
    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}
    59     Submit CRUD Form
    60     Should Show Confirmation
    61 }}}
    63 Note: Please make sure that the various arguments are separated by two spaces.
    64 [[BR]]
    65 [[BR]]
    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
    69 {{{
    70 pybot tests/implementation/testsuites
     52pybot tests/implementation/testsuites/login_functionality.txt.
    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 ===
     60[Ignore the `*** Settings ***` section for the time being.]
     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. 
     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.
    7966To understand the selenium keywords visit [ Selenium2Library Keyword Documentation] and the documentation of keywords implemented under !EdenTest in '''tests/docs'''