1

以下代码的执行:

<?php

class InheritedFeatureContext extends Behat\MinkExtension\Context\MinkContext
{
    /**
     *Simulates hovering over a link
     *
     * @When /^I mouse over "([^"]*)"$/
     */
        public function iMouseOver($link)
        {
        $this->getSession()->getPage()->findLink($link)->mouseOver();
        }

    /**
     *Waits for the appearence of a drop down
     *
     * @Then /^I wait for the suggestion box to appear$/
     */
    public function iWaitForTheSuggestionBoxToAppear()
    {
        $this->getSession()->wait(5000, "$('.suggestions-results').children().length > 0");
    }
}

产生错误消息:

  TypeError: $ is not a function

在参照:

$this->getSession()->wait(5000, "$('.suggestions-results').children().length > 0");

这段代码以前工作得很好。有任何想法吗

上下文:这是 Behat/Mink 功能的一部分

4

4 回答 4

2

您可能没有包含 jQuery,但您尝试在这里使用它:

$this->getSession()->wait(5000, "$('.suggestions-results').children().length > 0");

wait() 方法接受 javascript 作为它的第二个参数。它等待脚本评估为真(作为第一个参数传递的最大毫秒数)。

于 2012-08-16T08:20:13.373 回答
1

If i am not wrong this code is from behat mink example at site.

That example was using http://en.wikipedia.org/wiki as base url and wikipedia does have jquery script attached with it. In your case have you checked your url location if it contains jquery or not

于 2012-10-01T11:27:11.423 回答
0

很可能您没有包含 jQuery。

如果您不想为了支持这个 Mink 测试而将 jQuery 添加到您的项目中,请尝试将您的行更改为以下内容,这将完成同样的事情,但不使用 jQuery:

$this->getSession()->wait(5000, "document.querySelector('.suggestions-results').children.length > 0");

于 2014-02-24T04:33:52.890 回答
-1

这适用于我使用 jQuery 而不是$快捷方式:

$this->getSession()->wait(5000, "jQuery('.suggestions-results').children().length > 0");
于 2016-12-19T13:24:49.140 回答