Testing Joomla Extensions with Codeception
From Joomla! Documentation
Note: this page is under construction
What is Codeception?
Codeception PHP Testing Framework is designed to work just out of the box. This means its installation requires minimal steps and no external dependencies preinstalled (except PHP, of course). Only one configuration step should be taken and you are ready to test your web application from an eye of actual user.
Structure of a test
The testing framework is built on the three layered testing architecture
1. Page Objects
Each page on your application has a class which we call page objects, each page class will have information about the URL, fields, Text present on the page. We use the best possible selector for any field on the page
2. Step Objects
Step Objects are classes which contains steps which are to be executed on the application to perform certain operations, step objects make use of page objects to perform thoose actions.
3. Cept Class
Cept or Test, it is the main class which contains steps of execution for the tests, Cept Class will call Step Class functions which will indirectly make use of page objects to perform operations
Setting Up Codeception
setting up the repository
clone the directory
1.fork com_localise
2.git clone git@github.com:*your-github-profile-name*/com_localise.git
Testing with Codeception
There are two ways to get and run codeception, via PHAR or via Composer.
Codeception.phar
Linux Machine : wget http://codeception.com/codecept.phar
Windows Machine: Download from codecept.phar
Step1 : php ./codecept.phar build
Using Composer
You need to have Composer in your system, if not download it from here: https://getcomposer.org/
Step 1: composer update
Step 2: run Codeception by doing: php vendor/codeception/codeception/codecept build
Update Repository
Step 1: git submodule init
step 2: git submodule update
Running the Test
Rename tests/acceptance.suite.dist.yml to tests/acceptance.suite.yml
Step 1: Modify the configuration at tests/acceptance.suite.yml to fit your server details.
Find the instructions in this file : Instructions
Step 2: php codecept.phar run
with --steps to see a step-by-step report on the performed actions.
php codecept.phar run --steps
with --html. This command will run all tests for all suites, displaying the steps, and building HTML and XML reports. Reports will be store in tests/_output/ directory.
php codecept.phar run --html
To activate the debug mode in Codeception just add the parameter --debug when you run the tests:
php codecept.phar run acceptance --debug 1stInstallTestCept.php
Best Practices at Testing
When do not use contains
We do not recommend to use the function contains on XPath because is not specific and can create false positives at tests. See: https://github.com/joomla-projects/GSOC-Webdriver_system_tests_for_CMS/pull/99#issuecomment-69004191