![](/img/trans.png)
[英]Undefined step reference in PhpStorm when using Codeception and Gherkin
[英]Codeception Gherkin, defining the step implementation path
我是 php 和 codeception 的新手,我想將 Gherkin 與 Codeception 一起使用,並且我已經設置了最低限度,以使功能文件在 Codeception 中運行。 我現在發現自己正在嘗試制作一個可擴展的結構並利用 PageObject 框架。 我創建了一個Steps文件夾,我希望我的步驟實現保存在該文件夾中。 默認情況下,運行codecept run some.feature
負載在定義的類acceptance.suite.yml
文件。
動機:我希望能夠將我的步驟實現保存在它自己的單獨文件夾中
鑒於我有一個acceptance.suite.yml 文件配置:
gherkin:
contexts:
default:
- AcceptanceTester
modules:
enabled:
- WebDriver:
url: https://www.google.com/
browser: chrome
- \Helper\Acceptance
我有一個codeception.yml
的配置文件:
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
我有我的下步夾_support
:
如何更改配置以允許從 Steps 文件夾調用我的步驟實現?
在套件配置的gherkin:
部分,您需要列出在default:
、 role:
和/或tag:
部分下組織的步驟類。 官方文檔中有示例配置: Gherkin options 。
下面是最近一個項目的示例(使用 Codeception 2.5.6):
文件結構
/app/common
├── codeception.yml
├── tests
│ ├── acceptance.suite.yml
│ ├── _bootstrap.php
│ ├── _data
│ │ └── user.php
│ ├── _support
│ │ ├── AcceptanceTester.php
│ │ ├── Step
│ │ │ └── Acceptance
│ │ │ └── CuratorSteps.php
當使用 codecept
generate:stepobject
命令生成步驟對象時,步驟類的上述布局是默認的,如下所示:$ /app/vendor/bin/codecept -c /app/common generate:stepobject acceptance CuratorSteps
accept.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
文檔沒有提到它,但我注意到我必須列出步驟類的完整命名空間,否則在運行測試和
gherkin:steps
時我會得到“在上下文中找不到的步驟定義”錯誤gherkin:steps
codecept 命令不會返回步驟定義。
輸出
$ /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 |
+-------------------------------------+---------------------------------------------------------+
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.