In the gherkin:
section of the suite configuration, you need to list your steps classes organised under default:
, role:
and/or tag:
sections. There are example configurations in the official documentation: Gherkin options.
Below is an example from a recent project (using Codeception 2.5.6):
file structure
/app/common
├── codeception.yml
├── tests
│ ├── acceptance.suite.yml
│ ├── _bootstrap.php
│ ├── _data
│ │ └── user.php
│ ├── _support
│ │ ├── AcceptanceTester.php
│ │ ├── Step
│ │ │ └── Acceptance
│ │ │ └── CuratorSteps.php
The layout above for the step class is the default one when generating step object using codecept generate:stepobject
command like so:
$ /app/vendor/bin/codecept -c /app/common generate:stepobject acceptance CuratorSteps
acceptance.suite.yml:
# acceptance.suite.yml
namespace: common\tests
suite_namespace: common\tests\acceptance
bootstrap: false
actor: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://example.com/
gherkin:
contexts:
default:
- common\tests\AcceptanceTester
role:
curator:
- common\tests\Step\Acceptance\CuratorSteps
The documentation doesn't mention it, but I notice I have to list the full namespace of the step classes, otherwise I'll get "Step definition for ... not found in contexts" errors when running the tests and the gherkin:steps
codecept command won't return the step definitions.
output
$ /app/vendor/bin/codecept -vvv -c /app/common gherkin:steps acceptance
Steps from role:curator context:
+--------------------------------------------------------------------+------------------------------------------------------------------------------------------+
| Step | Implementation |
+--------------------------------------------------------------------+------------------------------------------------------------------------------------------+
| I sign in as an admin | common\tests\Step\Acceptance\CuratorSteps::iSignInAsAnAdmin |
| I should see a :arg1 button | common\tests\Step\Acceptance\CuratorSteps::iShouldSeeAButton |
+--------------------------------------------------------------------+------------------------------------------------------------------------------------------+
Steps from default context:
+-------------------------------------+---------------------------------------------------------+
| Step | Implementation |
+-------------------------------------+---------------------------------------------------------+
| I take a screenshot with name :arg1 | common\tests\AcceptanceTester::itakeAScreenshotWithName |
+-------------------------------------+---------------------------------------------------------+