我正在10.15上用php v7.3.27和composer v2.0.12从头开始创建一个新项目。我以前在另一台计算机上创建了一个协同欺骗项目。我遵循了使用验收测试的快速启动指南。
我使用"php供应商/bin/codecept generate:pageobject acceptance“生成页面对象,并使用"php供应商/bin/codecept生成:cest验收”生成cest。
当我尝试运行任何测试时,它都说没有找到这个类。如果我悬停在我的页面或单词AcceptanceTester上,它不会将我链接到任何东西。我的项目如下:
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);
}
}我的页面类如下:
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是通过共同欺骗自动生成的:
/**
* 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->,它就不会看到任何欺骗方法。我已经在Vscode中添加了Codeception扩展。如果我在我的方法的param上悬停在AcceptanceTester上,它就不会带我到类文件。如果我悬停在页面上,它就不会带我到页面对象文件。就像我在瞎飞一样。错误发生在vscode和外部vscode在终端。
我试过:
work
目录。我设立这个项目不是为了实用,而是为了让人接受。
发布于 2021-04-22 18:40:55
您需要在方法签名中的AcceptanceTester类名之前指定反斜杠,以便在根命名空间中找到类:
public function signUp(\AcceptanceTester $I)
public static function fillGetQuickAndEasyPrice(\AcceptanceTester $I, $address, $name, $phone)
https://stackoverflow.com/questions/67204477
复制相似问题