[英]Undefined method AcceptanceTester::getModule
i have a Yii2 project and i'm running automated tests with Codeception. 我有一个Yii2项目,并且正在使用Codeception运行自动化测试。
I intend to get a reference to the Webdriver instance. 我打算参考Webdriver实例。 How to do that? 怎么做?
I am getting an undefined method exception when i call $this->getModule("WebDriver") from the Cest class or the Acceptancetester class. 当我从Cest类或Acceptancetester类调用$ this-> getModule(“ WebDriver”)时,出现了未定义的方法异常。
This is my acceptance.suite.yml file: 这是我的accept.suite.yml文件:
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
And this is my AcceptanceTester that is trying to reference the WebDriver: 这是我的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);
}
}
I am getting an exception saying " Call to undefined method AcceptanceTester::getModule" when calling the AcceptanceTester::sendEnterKey method 调用AcceptanceTester :: sendEnterKey方法时,出现异常提示“调用未定义的方法AcceptanceTester :: getModule”
ps There is another question with the same title: Call to undefined method AcceptanceTester::getModule , but this is not a duplicate. ps还有一个标题相同的问题: 调用未定义的方法AcceptanceTester :: getModule ,但这不是重复的。 The problem in that question was due to the getModule call being in the Cest class. 该问题中的问题是由于在Cest类中进行了getModule调用。 But i did not make the same mistake. 但是我没有犯同样的错误。 I put the call in the AcceptanceTester 我把电话放在了AcceptanceTester
I think you need to put the method inside the Acceptance helper class. 我认为您需要将方法放入Acceptance helper类中。
It should be located at /_support/Helper/Acceptance.php
它应该位于/_support/Helper/Acceptance.php
So try this: 所以试试这个:
<?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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.