简体   繁体   English

Codeception Gherkin,定义步骤实现路径

[英]Codeception Gherkin, defining the step implementation path

I'm new to php and codeception and I wanted to use Gherkin with Codeception, and I've already setup the bare minimum to make feature files run in Codeception.我是 php 和 codeception 的新手,我想将 Gherkin 与 Codeception 一起使用,并且我已经设置了最低限度,以使功能文件在 Codeception 中运行。 I now find myself trying to make a scalable structure and make use of the PageObject framework.我现在发现自己正在尝试制作一个可扩展的结构并利用 PageObject 框架。 I created a Steps Folder and I wanted my step implementations kept in that folder.我创建了一个Steps文件夹,我希望我的步骤实现保存在该文件夹中。 By default running codecept run some.feature loads the class defined in the acceptance.suite.yml file.默认情况下,运行codecept run some.feature负载在定义的类acceptance.suite.yml文件。

Motivation: I want to be able keep my step implementations into it's own separate folder动机:我希望能够将我的步骤实现保存在它自己的单独文件夹中

Given I have an acceptance.suite.yml file configuration of:鉴于我有一个acceptance.suite.yml 文件配置:

gherkin:
    contexts:
        default: 
            - AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: https://www.google.com/
            browser: chrome
        - \Helper\Acceptance

And I have a codeception.yml file configuration of:有一个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

And I have my Steps folder under _support :有我的下_support

在此处输入图片说明

How do I change the configuration to allow my step implementation to be called from the Steps folder?如何更改配置以允许从 Steps 文件夹调用我的步骤实现?

In the gherkin: section of the suite configuration, you need to list your steps classes organised under default: , role: and/or tag: sections.在套件配置的gherkin:部分,您需要列出在default:role:和/或tag:部分下组织的步骤类。 There are example configurations in the official documentation: Gherkin options .官方文档中有示例配置: Gherkin options

Below is an example from a recent project (using Codeception 2.5.6):下面是最近一个项目的示例(使用 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:当使用 codecept generate:stepobject命令生成步骤对象时,步骤类的上述布局是默认的,如下所示:

 $ /app/vendor/bin/codecept -c /app/common generate:stepobject acceptance CuratorSteps

acceptance.suite.yml: 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

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.文档没有提到它,但我注意到我必须列出步骤类的完整命名空间,否则在运行测试和gherkin:steps时我会得到“在上下文中找不到的步骤定义”错误gherkin:steps codecept 命令不会返回步骤定义。

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 |
+-------------------------------------+---------------------------------------------------------+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM