Introducing SilverStripeExtension for Behat

During the second phase of GSoC an idea came into my mind. Why not allow other developers test their SilverStripe modules behaviourally?

There was already an extension created for basic interactions with the temporary database, but it was not in the state where you would be able to use it outside of the Sapphire framework.

But that’s the thing of the past. Now, let me introduce you to the new, shiny SilverStripeExtension.

Continue reading

AJAX callback support for Behat with Mink (and jQuery)

SilverStripe relies heavily on AJAX interactions with feedback times varying from 200ms to multiple seconds. In order to make testing both stable and fast we needed a more sophisticated system than fixed timeouts.

This has already been implemented for the old spec-by-example module.

As you can see in Developing Web Applications with Behat and Mink cookbook there is a separate step added that tells the scenario to wait for the specific event to occur:

And I wait for the suggestion box to appear

Then the following step is defined:

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

Good thing about the wait() function is that it continues after the condition provided as a second argument is true, so it doesn’t have to wait the entire time it has. But the problem with this solution is that this separate step is not really an active step that a non-technical user would spell out, and more importantly, it doesn’t add any value to the test descriptiveness as such.

Next you can find the complete code implemented by me that suppress the need of an additional step. It assumes that you use jQuery, but this can be changed easily. The code is then followed by a short explanation.

Continue reading

Conditional intercepting of redirections with Behat and Mink

In behat documentation, the topic of intercepting redirections is discussed in the context of using the profiler to test some of the features that hit specific browsers.

The solution proposed there has a specific drawback: it only works when you are trying to test using either goutte or symfony driver.

However, if some of the features you want to test using different driver too – like selenium2, that supports redirections, but does not allow to intercept them – you have to try different approach.

Continue reading