Skip to content

Latest commit

 

History

History
139 lines (88 loc) · 3.34 KB

File metadata and controls

139 lines (88 loc) · 3.34 KB
layout doc
title Sequence - Codeception - Documentation

Sequence

Installation

If you use Codeception installed using composer, install this module with the following command:

{% highlight yaml %} composer require --dev codeception/module-sequence

{% endhighlight %}

Alternatively, you can enable Sequence module in suite configuration file and run

{% highlight yaml %} codecept init upgrade4

{% endhighlight %}

This module was bundled with Codeception 2 and 3, but since version 4 it is necessary to install it separately.
Some modules are bundled with PHAR files.
Warning. Using PHAR file and composer in the same project can cause unexpected errors.

Description

Sequence solves data cleanup issue in alternative way. Instead cleaning up the database between tests, you can use generated unique names, that should not conflict. When you create article on a site, for instance, you can assign it a unique name and then check it.

This module has no actions, but introduces a function sq for generating unique sequences within test and sqs for generating unique sequences across suite.

Usage

Function sq generates sequence, the only parameter it takes, is id. You can get back to previously generated sequence using that id:

{% highlight php %}

wantTo('create article'); $I->click('New Article'); $I->fillField('Title', sq('Article')); $I->fillField('Body', 'Demo article with Lorem Ipsum'); $I->click('save'); $I->see(sq('Article') ,'#articles') {% endhighlight %} Populating Database: {% highlight php %} haveInDatabase('users', array('login' => sq("user$i"), 'email' => sq("user$i").'@email.com'); } {% endhighlight %} Cest Suite tests: {% highlight php %} createUser(sqs('user') . '@mailserver.com', sqs('login'), sqs('pwd')); } public function checkEmail(AcceptanceTester $I) { $I->seeInEmailTo(sqs('user') . '@mailserver.com', sqs('login')); } public function removeUser(AcceptanceTester $I) { $I->removeUser(sqs('user') . '@mailserver.com'); } } {% endhighlight %} #### Config By default produces unique string with param as a prefix: {% highlight yaml %} sq('user') => 'user_876asd8as87a' {% endhighlight %} This behavior can be configured using `prefix` config param. Old style sequences: {% highlight yaml %} Sequence: prefix: '_' {% endhighlight %} Using id param inside prefix: {% highlight yaml %} Sequence: prefix: '{id}.' {% endhighlight %} ### Actions

 

Module reference is taken from the source code. Help us to improve documentation. Edit module reference