Commit 73a1ddbe authored by Christian Keuerleber's avatar Christian Keuerleber Committed by Thomas Löffler
Browse files

Implement codeception

parent bbcf8231
version: '3.6'
container_name: ddev-${DDEV_SITENAME}-chromedriver
image: robcherry/docker-chromedriver
restart: "no"
- "4444"
- "ddev-router:${DDEV_SITENAME}"
......@@ -13,3 +13,5 @@ sequelpro.spf
# documentation
## Acceptance Tests
### Concepts
The acceptance tests run in their own environment. In this environment we import a basic database via codeception
to have a working site and add new data per test via yaml files and steps provided by the
`punktde/codeception-database` package. When a yaml file is imported via the gherkin step, every database table
found in the yaml file is truncated before the new data is imported.
In `Tests/acceptance.suite.yml` the config for the database module can be found. We have set
`populate` and `reset` to true, so before running any test and between every test the command given as the config
option `populator` is run. If no `populator` is given, the `dumpFile` is imported.
At the moment (Nov 4th 2019) GeckoDriver and FireFox testing is only possible by using the detour via selenium,
and even then it's not really reliable.
We are running chromedriver within ddev, so if you use ddev everything just works ;)
### Run codeception tests
#### Run the tests
ddev run --service web vendor/bin/codecept --steps run acceptance
With `--steps`, all run steps are outputted to the command line. All errors are reported even if you don't use the
flag. You can also add `--xml` as a flag to get JUnit compatible output.
If you get errors, you can find the output in the directory `Tests/_output`. In there is a list of failed tests and
a screenshot and the html output of the page the moment a test failed.
##### Single feature
To run a single feature just add the path to the feature file to your command, e.g.
ddev run --service web vendor/bin/codecept --steps run acceptance Tests/acceptance/Features/Login.feature
You can also run single scenarios by providing step names, e.g.
ddev run --service web vendor/bin/codecept --steps run acceptance Tests/acceptance/Features/Login.feature:Login\ and\ Logout
### Writing tests
The acceptance tests are put into the directory `Tests/acceptance/Feature`. You can use any folder structure to
group your tests.
To get all the available step definitions just run the command
ddev run --service web vendor/bin/codecept gherkin:steps acceptance
which outputs the steps added to the project.
To add new steps, just write the new step in your `.feature` file and run
ddev run --service web vendor/bin/codecept gherkin:snippets acceptance
This will output a function stub with the proper step definition phpdoc. Put this in a appropriate `ActorTrait`
and (if needed) add the `ActorTrait` to the `AcceptanceTester` (`Tests/_support/AcceptanceTester.php`). Example
traits can be found in the directory `Classes/ActorTraits/` of the `punktde/codeception-*` packages.
use PunktDe\Codeception\Database\ActorTraits\Database;
use PunktDe\Codeception\Webdriver\ActorTraits\Webdriver;
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
* @SuppressWarnings(PHPMD)
class AcceptanceTester extends \Codeception\Actor
use _generated\AcceptanceTesterActions;
use Webdriver;
use Database;
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
use Codeception\Configuration;
use Codeception\Exception\ConfigurationException;
use Codeception\Exception\ModuleException;
use Codeception\Module\Cli;
use Codeception\Module\Filesystem;
use Neos\Utility\Files;
use PunktDe\Codeception\Database\Module\Database;
class Acceptance extends \Codeception\Module
* @param string[] $settings
* @throws ConfigurationException
* @throws ModuleException
public function _beforeSuite($settings = []): void
$filesystem = $this->getModule('Filesystem');
/** @var Filesystem $filesystem */
$cli = $this->getModule('Cli');
/** @var Cli $cli */
$db = $this->getModule(Database::class);
/** @var Database $db */
$this->debug('dumping development database');
$dumpCommand = sprintf(
'mysqldump --host=%s --user=%s --password=%s %s > %s',
Files::concatenatePaths([Configuration::dataDir(), 'localDatabase.sql'])
public function _afterSuite()
$cli = $this->getModule('Cli');
/** @var Cli $cli */
$db = $this->getModule(Database::class);
/** @var Database $db */
$dumpfilePath = Files::concatenatePaths([Configuration::dataDir(), 'localDatabase.sql']);
$this->debug('restoring development database');
$restoreCommand = sprintf(
'mysql --host=%s --user=%s --password=%s %s < %s',
$filesystem = $this->getModule('Filesystem');
/** @var Filesystem $filesystem */
# Codeception Test Suite Configuration
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
actor: AcceptanceTester
# order matters - \Helper\Acceptance has to be first!
- \Helper\Acceptance
- Filesystem
- Cli
- WebDriver:
browser: chrome
restart: true
window_size: 1920x2080
host: chromedriver
path: /
- '--headless'
- '--disable-gpu'
- '--disable-dev-shm-usage'
- '--no-sandbox'
- PunktDe\Codeception\Database\Module\Database:
dsn: 'mysql:host=db;dbname=db;charset=UTF8'
user: 'db'
password: 'db'
host: 'db'
dump: 'Tests/_data/Dumps/Fixture.sql'
populate: true
cleanup: true
populator: 'mysql --host=$host --user=$user --password=$password $dbName < $dump'
step_decorators: ~
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment