Behat测试失败,出现Modal对话框

时间:2014-05-12 17:12:07

标签: selenium behat gherkin

如果您认为我正在做的方式是错误的或有另一种方式,请告诉我,以便我可以更改下面的整个代码。

问题:我收到此错误:(我认为这是因为需要点击警告框)

[WebDriver\Exception\UnexpectedAlertOpen]                                                                                                                                                                                                                                                                                                                       
  Modal dialog present: profile data saved 

TEST_1

When I fill in "firstname" with "a"
    And I fill in "lastname" with "b"
    And I follow "Save"
    Then I should see "profile data saved" in popup

test_2

This is second test which comes after test_1 and this is fine.

FeatureContext

/**
 * @When /^(?:|I )should see "([^"]*)" in popup$/
 *
 * @param string $message The message.
 *
 * @return bool
 */
public function assertPopupMessage($message)
{
    return $message == $this->getSession()->getDriver()->getWebDriverSession()->getAlert_text();
}

1 个答案:

答案 0 :(得分:2)

在assertPopupMessage()中,你应该比较$ message和getAlert_text()。

e.g

/**
     * @When /^(?:|I )should see "([^"]*)" in popup$/
     *
     * @param string $message The message.
     */
    public function assertPopupMessage($message)
    {
        $alertText = $this->getMainContext()->getSession()->getDriver()->getWebDriverSession()->getAlert_text();
        if ($alertText !== $message){
            throw new Exception("Modal dialog present: $alertText, when expected was $message");
        }   
    }

使用弹出窗口进行更多测试,请查看https://gist.github.com/acfreitas/4d0778e8690e5d3a1de7