【问题标题】:Undefined method AcceptanceTester::getModule未定义的方法 AcceptanceTester::getModule
【发布时间】:2019-11-23 12:02:13
【问题描述】:

我有一个 Yii2 项目,我正在使用 Codeception 运行自动化测试。

我打算获取对 Webdriver 实例的引用。 该怎么做?

当我从 Cest 类或 Acceptancetester 类调用 $this->getModule("WebDriver") 时,我得到一个未定义的方法异常。

这是我的acceptance.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

这是我的 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”

附言 还有一个同名问题:Call to undefined method AcceptanceTester::getModule,但这不是重复的。 该问题中的问题是由于 getModule 调用在 Cest 类中。但我没有犯同样的错误。我把电话放在 AcceptanceTester 中

【问题讨论】:

标签: php yii2 webdriver phpunit codeception


【解决方案1】:

我认为您需要将该方法放在 Acceptance 助手类中。

它应该位于/_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);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    • 2013-06-11
    • 2010-12-30
    • 2019-12-25
    相关资源
    最近更新 更多