BentCoder
BentCoder

Reputation: 12740

Behat test fails with Modal dialog present

If you think the way I'm doing is wrong or there is another way then let me know so I can change whole code below.

Problem: I'm getting this error: (I think it is because alert box needs to be clicked)

[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();
}

Upvotes: 1

Views: 1862

Answers (1)

acfreitas
acfreitas

Reputation: 1397

In assertPopupMessage( ) you should compare the $message and 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");
        }   
    }

More testing with popup, look at https://gist.github.com/acfreitas/4d0778e8690e5d3a1de7

Upvotes: 2

Related Questions