Changes between Version 60 and Version 61 of DeveloperGuidelines/Testing/Selenium


Ignore:
Timestamp:
07/02/13 19:01:02 (8 years ago)
Author:
somayjain
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/Testing/Selenium

    v60 v61  
    112112
    113113== Writing / Creating your own test scripts: ==
    114 We aim to make it as easy as possible to write additional tests, which can easily be plugged into the Sahana Eden Testing System Framework.
    115 
    116 The canonical example is: {{{eden/modules/tests/org/create_organisation.py}}}
     114We aim to make it as easy as possible to write additional tests, which can easily be plugged into the Sahana Eden Testing System Framework.
    117115
    118116New tests should be stored in a subfolder per module, adding the foldername to {{{eden/modules/tests/__init__.py}}} & creating an {{{__init__.py}}} in the subfolder.
    119117
    120 '''A walk-through example:'''[[BR]]
    121 We want to make an automated test script to test the Create Organization module.
    122 Create Organization falls under Human Resources Management (HRM) feature, therefore we must add this test script module file in the subfolder /hrm (eden/modules/tests/hrm/)
    123 
    124 Steps of automated the test for Create Organization:[[BR]][[BR]]
     118'''A walk-through example: Creating a Record'''[[BR]]
     119
     120The canonical example is: {{{eden/modules/tests/staff/create_staff.py}}}
     121
     122We want to make an automated test script to test the Create Staff module.
     123Create Staff falls under Staff feature, therefore we must add this test script module file in the subfolder /staff (eden/modules/tests/staff/)
     124
     125Steps of automated the test for Create Staff:[[BR]][[BR]]
    125126 
    126 1) Let's call this test file: create_organization.py and save it in the subfolder /hrm. [[BR]][[BR]]
     1271) Let's call this test file: create_staff.py and save it in the subfolder /staff. [[BR]][[BR]]
    127128
    1281292) We must now make sure we add the file name in the __init__.py
    129 Open file __init__.py in the subfolder /hrm and add:
    130 {{{
    131 from create_organisation import *
    132 }}}
    133 3) create_organisation.py
    134 {{{
    135 import os
    136 import time
    137 from selenium.common.exceptions import NoSuchElementException
    138 from gluon import current
    139 from s3 import s3_debug
     130Open file __init__.py in the subfolder /staff and add:
     131{{{
     132from create_staff import *
     133}}}
     1343) create_staff.py
     135{{{
     136
    140137from tests.web2unittest import SeleniumUnitTest
    141138
    142 class CreateOrganization(SeleniumUnitTest):
    143 
    144     # -------------------------------------------------------------------------
    145     def test_org001_create_organisation(self, items=[0]):
     139class CreateStaff(SeleniumUnitTest):
     140    def test_hrm001_create_staff(self):
    146141        """
    147             Create an Organisation
     142            @case: HRM001
     143            @description: Create a Staff
    148144           
    149             @param items: Organisation(s) to create from the data
    150 
    151             @ToDo: currently optimised for a single record
     145            @TestDoc: https://docs.google.com/spreadsheet/ccc?key=0AmB3hMcgB-3idG1XNGhhRG9QWF81dUlKLXpJaFlCMFE
     146            @Test Wiki: http://eden.sahanafoundation.org/wiki/DeveloperGuidelines/Testing
    152147        """
    153148        print "\n"
    154         # Configuration
    155         self.login(account="normal", nexturl="org/organisation/create")
    156         tablename = "org_organisation"
    157         #data = current.data["organisation"]
    158         # Data for the Organisation resource
    159         self.create("org_organisation",
    160                     [( "name", "Romanian Food Assistance Association (Test)"), ( "acronym", "RFAAT"), ("website", "http://www.rfaat.com"), ("comments", "This is a Test Organization")]
     149
     150        self.login(account="admin", nexturl="hrm/staff/create")
     151
     152        self.create("hrm_human_resource",
     153                    [( "organisation_id",
     154                       "International Federation of Red Cross and Red Crescent Societies"),
     155                     ( "site_id",
     156                       "AP Zone (Office)"),
     157                     ( "first_name",
     158                       "Robert",
     159                       "pr_person"),
     160                     ( "middle_name",
     161                       "James",
     162                       "pr_person"),
     163                     ( "last_name",
     164                       "Lemon",
     165                       "pr_person"),
     166                     ( "email",
     167                       "rjltestdonotusetest99@romanian.com",
     168                       "pr_person"),
     169                     ( "job_title_id",
     170                       "Warehouse Manager"),
     171                     ]
    161172                     )
    162         for item in items:
    163             _data = data[item]
    164             # Check whether the data already exists
    165             s3db = current.s3db
    166             db = current.db
    167             table = s3db[tablename]
    168             fieldname = _data[0][0]
    169             value = _data[0][1]
    170             query = (table[fieldname] == value) & (table.deleted == "F")
    171             record = db(query).select(table.id,
    172                                       limitby=(0, 1)).first()
    173             if record:
    174                 print "org_create_organisation skipped as %s already exists in the db\n" % value
    175                 return False
    176 
    177             # Login, if not-already done so
    178             self.login(account=account, nexturl=url)
    179 }}}
     173}}}
     174
     175* The create function takes 2 arguments - {{{create(table_name, data)}}}
     176* {{{table_name}}} - The name of the database table in which we want to insert the record.
     177* {{{data}}} - The list which contains the record to be inserted.
     178* Each tuple in the above list contains information about each individual field.
     179 * Eg - {{{( "organisation_id","International Federation of Red Cross and Red Crescent Societies")}}}. Here, {{{organisation_id}}} is the label of the field in which we want to insert data {{{International Federation of Red Cross and Red Crescent Societies}}}
    180180
    1811814) To run this automated test script.
    182 Open suite.py (modules/tests/suite.py) and add at the bottom of suite.py script so it can be executed. (NOTE: We add the class name, not the function name).
    183 {{{
    184 addTests(loadTests(CreateOrganization))
     182Determine the template(s) on which you wish to run this test on. The tests for each template are defined in {{{private/templates/<template_name>/tests.py}}}.
     183Open tests.py for these templates and append the class name of the test to the list so it can be executed. (NOTE: We add the class name, not the function name).
     184{{{
     185current.selenium_tests.append("CreateStaff")
    185186}}}
    186187