Behat: having method __toString() not implemented 错误

Behat: having method __toString() not implemented error

我有 php 5.6.14.

为 behat 测试编写上下文我看到一个错误:

/** @When /^I want to see JS alert$/ */
public function iExecuteJs() {
    $this->webDriver()->executeScript("jsAlert()");
        if ($this->webDriver()->switchTo()->alert()->getText().contains("js")){
            echo "test passed";
        };

}

我应该用它做什么?

谢谢

最后,我将代码更改为:

    $element = $this->webDriver()->switchTo()->alert()->getText();
        if ($element == "I am a JS Alert"){
           echo "correct js alert appeared";
        }