Changes between Version 25 and Version 26 of DeveloperGuidelines/Testing/Selenium


Ignore:
Timestamp:
06/19/12 23:41:13 (12 years ago)
Author:
coldblooded
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/Testing/Selenium

    v25 v26  
    7575
    7676== Writing / Creating your own test scripts: ==
    77 We aim to make it as easy as possible to write additional tests, which can easily be plugged into the testing suite or/and executed separately.
     77We aim to make it as easy as possible to write additional tests, which can easily be plugged into the Sahana Eden Testing System Framework.
    7878
    79 The canonical example is: {{{eden/modules/tests/org/org_create_organisation.py}}}
     79The canonical example is: {{{eden/modules/tests/org/create_organisation.py}}}
    8080
    8181New 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.
     82
     83'''A walk-through example:'''[[BR]]
     84We want to make an automated test script to test the Create Organization module.
     85Create 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/)
     86
     87Steps of automated the test for Create Organization:[[BR]][[BR]]
     88 
     891) Let's call this test file: create_organization.py and save it in the subfolder /hrm. [[BR]][[BR]]
     90
     912) We must now make sure we add the file name in the __init__.py
     92Open file __init__.py in the subfolder /hrm and add:
     93{{{
     94from create_organisation import *
     95}}}
     963) create_organisation.py
     97{{{
     98import os
     99import time
     100from selenium.common.exceptions import NoSuchElementException
     101from gluon import current
     102from s3 import s3_debug
     103from tests.web2unittest import SeleniumUnitTest
     104
     105class CreateOrganization(SeleniumUnitTest):
     106
     107    # -------------------------------------------------------------------------
     108    def test_org001_create_organisation(self, items=[0]):
     109        """
     110            Create an Organisation
     111           
     112            @param items: Organisation(s) to create from the data
     113
     114            @ToDo: currently optimised for a single record
     115        """
     116        print "\n"
     117        # Configuration
     118        self.login(account="normal", nexturl="org/organisation/create")
     119        tablename = "org_organisation"
     120        #data = current.data["organisation"]
     121        # Data for the Organisation resource
     122        self.create("org_organisation",
     123                    [( "name", "Romanian Food Assistance Association (Test)"), ( "acronym", "RFAAT"), ("website", "http://www.rfaat.com"), ("comments", "This is a Test Organization")]
     124                     )
     125        for item in items:
     126            _data = data[item]
     127            # Check whether the data already exists
     128            s3db = current.s3db
     129            db = current.db
     130            table = s3db[tablename]
     131            fieldname = _data[0][0]
     132            value = _data[0][1]
     133            query = (table[fieldname] == value) & (table.deleted == "F")
     134            record = db(query).select(table.id,
     135                                      limitby=(0, 1)).first()
     136            if record:
     137                print "org_create_organisation skipped as %s already exists in the db\n" % value
     138                return False
     139
     140            # Login, if not-already done so
     141            self.login(account=account, nexturl=url)
     142}}}
     143
     1444) To run this automated test script.
     145Open 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).
     146{{{
     147addTests(loadTests(CreateOrganization))
     148}}}
     149
     1505) Run your test script. (Refer above on how to run/execute test scripts from the Test Suite).
     151
     152'''Other information on the Test System framework:'''[[BR]]
    82153
    83154The key is to make tests which are as least fragile as possible through: