Codeception 项目找不到 AcceptanceTester

Codeception project can't find AcceptanceTester

我正在使用 php v7.3.27 和 composer v2.0.12 在 Mac Catalina 10.15 上从头开始创建一个新项目。我之前创建了一个 Codeception 项目,但在另一台计算机上。我遵循了使用验收测试的快速入门指南。

我使用“php vendor/bin/codecept generate:pageobject 接受”生成了页面对象,并使用“php vendor/bin/codecept generate:cest 生成了 Cests接受“

当我尝试 运行 任何测试时,它说找不到 class。如果我将鼠标悬停在我的页面上或 AcceptanceTester 这个词上,它不会 link 我做任何事情。我的项目如下所示:

tests
   > data
   > output
   v support
     v _generated
       AcceptanceTesterActions.php
       FunctionalTesterActions.php
       UnitTesterActions.php
   > Helper
   > Page/Acceptance
      CustomerSignupHomePage.php
    AcceptanceTester.php
    FunctionalTester.php
    UnitTester.php
   v acceptance
      CustomerSignupCest.php

我意识到我的主目录中没有 .bashrc,所以我创建了一个并更新了 bash_profile,类似于我在工作计算机上的内容:

#Global composer bin

export $PATH=~/.composer/vendor/bin:$PATH
export $PATH="$HOME/.composer/vendor/bin:$PATH"

cat .bash_profile
#alias composer="php /usr/local/bin/composer.phar"
  
export PATH="./composer/vendor/bin/:$PATH"

export PATH="/usr/local/opt/php@7.3/bin:$PATH"
export PATH="/usr/local/opt/php@7.3/sbin:$PATH"
~                                                  

我的 codeception.yml 看起来像这样:

    tests: tests
    output: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
actor_suffix: Tester
extensions:
    enabled:
        - Codeception\Extension\RunFailed

我的 composer.json 看起来像这样:

    "require-dev": {
        "codeception/codeception": "^4.1",
        "codeception/module-phpbrowser": "^1.0.0",
        "codeception/module-asserts": "^1.0.0"
    },
    "require":{
        "ext-zip": "*",
        "guzzlehttp/guzzle": "^7.2",
        "vlucas/phpdotenv": "^5.2"
    },
    "autoload": {
        "psr-4": {
            "Tests\Support\": "tests/_support/"
        }
    }
}

我的一个 Cest 文件如下所示:


use Tests\Support\Page\Acceptance\CustomerSignupHomePage;

class CustomerSignupCest
{

    const ADDRESS = "100 Silmarillion Trail, Austin TX 78739";
    const NAME = "POC Automation Tester";
    const PHONE = "512-203-5555";

    /**
     * signUp
     *
     * @param AcceptanceTester $I
     * @return void
     */
    public function signUp(AcceptanceTester $I)
    {
        $I->wantToTest("the signup flow");
        CustomerSignupHomePage::fillGetQuickAndEasyPrice($I, self::ADDRESS, self::NAME, self::PHONE);
    }
}

我的页面 class 看起来像这样:


namespace Tests\Support\Page\Acceptance;

class CustomerSignupHomePage
{
    // include url of current page
    public static $URL = 'https://dev-www.<mycompany>.com';

    /**
     * Declare UI map for this page here. CSS or XPath allowed.
     * public static $usernameField = '#username';
     * public static $formSubmitButton = "#mainForm input[type=submit]";
     */
    const ADDRESS_INPUT = "#streetAddress";
    const SEE_PRICE_BUTTON = ".js-submitButton";
    const NAME_INPUT = ".js-fullNameInput";
    const PHONE_INPUT = ".js-phoneInput";
    
    /**
     * fillGetQuickAndEasyPrice
     *
     * @param AcceptanceTester $I
     * @param mixed $address
     * @param mixed $name
     * @param mixed $phone
     * @return void
     */
    public static function fillGetQuickAndEasyPrice(AcceptanceTester $I, $address, $name, $phone)
    {
        $I->waitForElement(self::ADDRESS_INPUT);
        $I->fillField(self::ADDRESS_INPUT, $address);
        $I->click(self::SEE_PRICE_BUTTON);
        $I->fillField(self::NAME_INPUT, $name);
        $I->fillField(self::PHONE_INPUT, $phone);
        $I->click(self::SEE_PRICE_BUTTON);
    }

    /**
     * Basic route example for your current URL
     * You can append any additional parameter to URL
     * and use it in tests like: Page\Edit::route('/123-post');
     */
    public static function route($param)
    {
        return static::$URL.$param;
    }

    /**
     * @var \AcceptanceTester;
     */
    protected $acceptanceTester;

    public function __construct(\AcceptanceTester $I)
    {
        $this->acceptanceTester = $I;
    }

}

如果我尝试 运行 测试,我会收到此错误:

[TypeError] Argument 1 passed to Tests\Support\Page\Acceptance\CustomerSignupHomePage::fillGetQuickAndEasyPrice() must be an instance of Tests\Support\Page\Acceptance\AcceptanceTester, instance of AcceptanceTester given, called in /Users/julie/workspaces/Codeception-Demo/tests/acceptance/CustomerSignupCest.php on line 21
 

我的AcceptanceTester.php是codeception自动生成的:



/**
 * 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 void pause()
 *
 * @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
    use _generated\AcceptanceTesterActions;

    /**
     * Define custom actions here
     */
}

我的 Cest 文件和页面文件根本看不到 AutomationTester。如果我开始输入 $I-> 它看不到任何代码接收方法。我已将 Codeception 市场扩展添加到 Vscode。如果我将鼠标悬停在方法参数中的 AcceptanceTester 上,它不会将我带到 class 文件。如果我将鼠标悬停在页面上,它不会将我带到页面对象文件。这就像我在盲目飞行。错误发生在终端的 vscode 和 vscode 之外。

我试过:

您需要在方法签名中的 AcceptanceTester class 名称前指定反斜杠才能在根命名空间中找到 class:

public function signUp(\AcceptanceTester $I)

public static function fillGetQuickAndEasyPrice(\AcceptanceTester $I, $address, $name, $phone)