diff --git a/integration/stick/README.md b/integration/stick/README.md index f222723..0e1fa72 100644 --- a/integration/stick/README.md +++ b/integration/stick/README.md @@ -1,113 +1,144 @@ Kolab Integration Test Suite ============================ This suite provides a collection of utility functions and classes to perform integration tests on Kolab Groupware components. It assumes a vanilla single-host installation of Kolab for the domain `example.org` running at localhost. The `KolabIntegrationTest` class from this package provides methods to reset the LDAP and IMAP stores of the Kolab server and create users, resources or shared folders: - `require_user()` - `require_resource()` - `require_shared_folder()` Call these functions once in the `setUpClass()` method of your test class before calling the parent method. For web client testing, test cases can be written using [[ http://docs.seleniumhq.org/ | Selenium]] by using the `KolabSeleniumTest` base class which itself requires [[http://selenium-python.readthedocs.org/ | selenium-python]]. Installation ------------ Install Selenium: ``` sudo yum install python-setuptools sudo easy_install selenium ``` Selenium tests use PhantomJS to run in a headless browser. It is based on Webkit and availbale as binary package for [[http://phantomjs.org/download.html | download]]: ``` wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2 tar xjf phantomjs-1.9.7-linux-x86_64.tar.bz2 cp phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/local/bin ``` For PHPUnit-based Selenium tests, the standalone server is required. Therefore install Java and get the server as Jar file: ``` yum -y install java-1.7.0-openjdk wget http://selenium-release.storage.googleapis.com/2.45/selenium-server-standalone-2.45.0.jar mv selenium-server-standalone-2.45.0.jar /usr/local/lib/ ``` Configuration ------------- The test environment uses configuration options from `/etc/kolab/kolab.conf` and expects an additonal section `[testing]` to provide values relevant for test execution. Namely the following: ``` [testing] roundcube_url = /roundcubemail/ roundcube_dir = /usr/share/roundcubemail develmode = false verbose = true phpunit_bin = vendor/bin/phpunit selenium_server_jar = /usr/local/lib/selenium-server-standalone-2.45.0.jar ``` - roundcube_url: The relative or absolute URL of the web client - roundcube_dir: Local filesystem path to Roundcube installation/checkout - develmode: Set to `true` to skip user account deletion and creation on every test run - verbose: Set to `true` to display log messages. Trigger them with `self.log()` from your tests - phpunit_bin: path to the `phpunit` binary used to execute PHPUnit tests, absolute or realtive to roundcube_dir - selenium_server_jar: Absolute path to the Selenium standalone server jar file +Writing Tests +------------- + +Create test classes extending one of the utility classes from the stick module `KolabIntegrationTest`, +`KolabSeleniumTest` or `KolabPhpunitTest`. + +**KolabIntegrationTest** + +Base class for integration tests written in Pyhthon. Supports all the assertials from the standard +`unittest` module as well as a `log()` method for printing messages in verbose mode. + +**KolabSeleniumTest** + +Extend this class for Selenium tests executing commands in a headless browser (PhandomJS). +The `self.driver` property holds an instance of [[http://selenium-python.readthedocs.org/en/latest/api.html | selenium.webdriver]] +which can be used to find UI elements and execute actions on them. + +**KolabPhpunitTest** + +This is a wrapper class for running existing PHPUnit tests from the Roundcube root directory. +Use the `execute()` method to run phpunit test files or entire suites, the return status of those +tests will be translated into an assertion. With `selenium=True`, a standalone Selenium server will +be started to run PHPUnit Selenium tests. + +**Decorators** + +The Stick module provides two decorators to flag tests as TODO `@stick.todo("TODO: why?")` +or as a Selenium test `@stick.selenium()`. With the according command line options, these +tests can be included or excluded from test runs. + + Examples -------- Basic Selenium test to check successful login to the web client: ``` import unittest from stick import KolabSeleniumTest class TestLogin(KolabSeleniumTest): @classmethod def setUpClass(self, *args, **kw): # define user account required for this test self.john = self.require_user("John", "Doe") super(TestLogin, self).setUpClass(*args, **kw) def test_login(self): # log-in with John Doe self.roundcube_login(self.john['mail'], self.john['userpassword']) # Check for username displayed in the main sceen elem = self.driver.find_element_by_css_selector('#header .username') self.assertEqual(self.john['mail'], str(elem.text), "Username in page header") ``` Credits ------- Many thanks to [[https://github.com/TBits/KolabScripts/tree/master/pySeleniumTests | TBits]] for the inspiration!