Steppify
Generate Gherkin steps from Codeception modules.
Install this package using Composer:
composer require --dev lucatume/codeception-steppify
and then add the command to the custom commands used by your project following Codeception documentation on the subject:
extensions:
commands: [tad\Codeception\Command\Steppify]
The command will generate traits usable in Codeception tester classes from codeception modules.
As an example I might want to generate Gherkin steps to use Codeception own [PhpBrowser](!g codeception PhpBrowser module) module methods in Gherkin features:
codecept gherkin:steppify PhpBrowser
The command will generate PhpBrowserGherkinSteps.php
, a PHP trait
file, in the tests _support/_generated
folder.
To start using the new methods all that's required is to add a use
statement for the PhpBrowserSteps
trait in the suite Tester
class:
<?php
/**
* 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 \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;
use _generated\PhpBrowserGherkinSteps;
/**
* Define custom actions here
*/
}
You will now be able to write Gherkin features using steps generated from PhpBrowser
module provided methods like:
Scenario: methods provided by Codeception PhpBrowser module are available as Gherkin steps
Feature: I can go on the site homepage
When I am on page '/'
Then I can see element 'body.home'
The command is not limited to Codeception default modules only and will work with any custom module provided by other libraries or custom made for the project.
While the command will make an extra effort to support modules in the Codeception\Module\
name space modules defined outside of that namespace will require the specification of the fully qualified name to work:
codecept gherkin:steppify "Acme\Project\Tests\Modules\ModuleOne"
This means that gherkin:steppify ModuleName
is a shortcut for gherkin:steppify "Codeception\Module\ModuleName"
and you may provide any other compatible namespaced class.
While the command will try to be "smart" and helpful in generating the methods signatures it has, and will always have, limits. For this reason the method signature generation logic will take into account cascading definitions during the generation process:
- if available use the configuration file
- else available use the method documentation block
- else fallback on using the built-in logic
The command supports two docblock tags to control the generation:
@gherkin
- can beno
to avoid the method from generating any step, or a comma separated list of step types (given
,when
,then
).
Please note that if Gherkin step compatible step definitions are found in the method doc block than those will be used.
The command supports a --steps-config <file.yml>
option that allows specifying which methods and how steps should be generated.
The file has the following format:
modules:
PhpBrowser:
methods:
amOnPage:
generates: [given, when]
step: I visit page :page
Acme\Modules\SomeModule:
exclude:
- methodTwo
methods:
- haveAuthKeyInDatabase:
generates: [given]
step: I have authorization key :key in database
<module>:
exclude:
- <excluded method one>
- <excluded method two>
methods:
- <method name>:
generates: [given, when, then]
step: <step definition template>
The command supports options meant to make its output controllable to a comfortable degree:
--steps-config <file>
- see the configuration file section; allows specifying the path to a step definition generation configuration file.--prefix <prefix>
- allows specifying a string that should be appended to the generated step file name.