Changes between Initial Version and Version 1 of DeveloperGuidelines/Testing/Selenium


Ignore:
Timestamp:
03/27/12 09:30:43 (10 years ago)
Author:
Fran Boon
Comment:

Initial version for new test framework

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/Testing/Selenium

    v1 v1  
     1= Testing =
     2[[TOC]]
     3"A bug is a test case you haven't written yet" [[BR]]
     4"Unit Tests allow merciless [http://diveintopython.org/refactoring/refactoring.html refactoring]"
     5
     6Test-Driven Development is a programming styles which says that you 1st write your test cases (from the [BluePrints specs]) & then proceed to make them pass.
     7
     8Selenium provides the ability to test Sahana Eden as users see it - namely through a web browser. This therefore does end-to-end Functional Testing, however it can also be sued as Unit Testing
     9
     10We are building our framework around the new WebDriver, despite having some legacy code in the older format:
     11* http://seleniumhq.org/docs/appendix_migrating_from_rc_to_webdriver.html#why-migrate-to-webdriver
     12
     13These tests are stored in {{{eden/modules/tests}}}
     14
     15== Installation ==
     16Install Selenium Python Client Driver into your running Python:
     17* http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html
     18{{{
     19pip install -U selenium
     20}}}
     21or
     22{{{
     23wget http://pypi.python.org/packages/source/s/selenium/selenium-2.20.tar.gz
     24tar zxvf selenium-2.20.tar.gz
     25cd selenium-2.20
     26python setup.py install
     27}}}
     28
     29== Running Tests ==
     30Before running the Selenium scripts, you should put your database into a known state:
     31{{{
     32clean
     33}}}
     34
     35For the whole test suite, it is assumed that you are using:
     36{{{
     37deployment_settings.base.prepopulate = 2
     38}}}
     39
     40Run the whole test suite for the 'eden' application:
     41{{{
     42python web2py.py -S eden -M -R applications/eden/modules/tests/suite.py
     43}}}
     44Run a single test for the 'eden' application:
     45{{{
     46python web2py.py -S eden -M -R applications/eden/modules/tests/suite.py -A mytestfunction
     47}}}
     48
     49== Writing Tests ==
     50We aim to make it as easy as possible to write additional tests, which can easily be plugged into the suite.
     51
     52An example has been created: {{{eden/modules/tests/hrm/staff.py}}}
     53
     54New 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.
     55
     56The key is to make tests which are as least fragile as possible through:
     57* State (we should eb able to run individual tests easilty, which check their current state as-required)
     58* Deployment_Settings
     59* Localisation
     60* Theme
     61
     62This suggests refactoring tests to centralise common elements into a library to mean fixes should only happen in 1 place.
     63
     64There are a number of possible selectors to use to find your elements...the 'ID' may be the most stable, so don't be afraid of patching the code to add IDs where you'd like to be able to reach them reliably:
     65* http://selenium.googlecode.com/svn/trunk/docs/api/py/selenium/selenium.selenium.html
     66
     67== !ToDo ==
     68* Store results in a format suitable for use by CI
     69* Namespacing of tests
     70* Include timings
     71* Run from Nose?
     72 * http://blog.shiningpanda.com/2011/12/introducing-selenose.html
     73
     74== See Also ==
     75 * TestCases - User Testing - List of things to test
     76 * http://code.google.com/p/selenium/wiki/PageObjects - Style suggestion