Php 未定义的方法AcceptanceTester::getModule
我有一个Yi2项目,我正在用Codeception运行自动化测试 我打算获取对Webdriver实例的引用。 怎么做 当我从Cest类或Acceptancetester类调用$this->getModuleWebDriver时,我得到一个未定义的方法异常 这是我的acceptance.suite.yml文件:Php 未定义的方法AcceptanceTester::getModule,php,yii2,webdriver,phpunit,codeception,Php,Yii2,Webdriver,Phpunit,Codeception,我有一个Yi2项目,我正在用Codeception运行自动化测试 我打算获取对Webdriver实例的引用。 怎么做 当我从Cest类或Acceptancetester类调用$this->getModuleWebDriver时,我得到一个未定义的方法异常 这是我的acceptance.suite.yml文件: class_name: AcceptanceTester modules: enabled: - Cli:
class_name: AcceptanceTester
modules:
enabled:
- Cli:
- WebDriver:
url: http://localhost:8081/
browser: firefox
port: 4455
- Yii2:
part: [orm,fixtures]
entryScript: index-test.php
cleanup: false
这是我的AcceptanceTester,它试图引用WebDriver:
/**
* 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 \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;
public function sendEnterKey(){
// the following line will raise an exception
$driver = $this->getModule("WebDriver");
$driver->getKeyboard()->sendKeys(\Facebook\WebDriver\WebDriverKeys::ENTER);
}
}
在调用AcceptanceTester::sendEnterKey方法时,我收到一个异常,称为调用未定义的方法AcceptanceTester::getModule
p、 美国。
还有一个问题的标题相同:,但这不是重复的问题。
该问题中的问题是由于getModule调用位于Cest类中。但我没有犯同样的错误。我将调用放在AcceptanceTester中我认为需要将该方法放在Acceptance helper类中 它应该位于/_support/Helper/Acceptance.php 所以试试这个:
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Acceptance extends \Codeception\Module
{
public function sendEnterKey()
{
$driver = $this->getModule("WebDriver");
$driver->getKeyboard()->sendKeys(\Facebook\WebDriver\WebDriverKeys::ENTER);
}
}
@Muhammad Omer Aslam的可能重复不是重复:该问题中的问题是由于getModule调用位于Cest类中。但我没有犯同样的错误。我把电话放进了验收测试仪。