I was hoping we could take a look at http://docs.behat.org/cookbook/using_spin_functions.html and determine if it's valuable for the slow and flaky tests.

Comments

pradeeprkara’s picture

Issue tags: +sprint 19

The spin method will make more sense in cases where Goutte is running. Here we can pass a callback function OR check the status code by default, every second or 2 second until an already specified timeout value is reached and throw a time out exception at the end. As selenium doesn't support the status check method, we still will need to depend on the wait() method which expects a javascript callback or statement to become true. In this case, we cannot write a javascript callback that effectively returns a true status after waiting/holding the execution. The first argument of wait() is a fixed timeout value but I am not sure this is working as expected.

Below is the modified step definition for I wait until the page is loaded with the spin method changes for Goutte with readyStatus check for selenium.

  public function iWaitUntilThePageLoads($callback = null) {
    // Manual timeout in seconds
    $timeout = 60;
    // Default callback
    if (empty($callback)) {
      if ($this->getSession()->getDriver() instanceof Behat\Mink\Driver\GoutteDriver) {
        $callback = function($context) {
          // If the page is completely loaded and the footer text is found
          if(200 == $context->getSession()->getDriver()->getStatusCode()) {
            return true;
          }
          return false;
        };
      }
      else {
        // Convert $timeout value to milliseconds
        // document.readyState becomes 'complete' when the page is fully loaded
        $this->getSession()->wait($timeout*1000, "document.readyState == 'complete'");
        return;
      }
    }
    if (!is_callable($callback)) {
      throw new Exception('The given callback is invalid/doesn\'t exist');
    }
    // Try out the callback until $timeout is reached
    for ($i = 0; $i < $timeout/2; $i++) {
      if ($callback($this)) {
        return true;
      }
      // Try every 2 seconds
      sleep(2);
    }
    throw new Exception('The request is timed out');
  }
  

I have committed the above changes to 7.x : http://drupalcode.org/project/doobie.git/commit/ec0e95e
So we cannot fully depend on the spin method from the lower level but making use of it in the core level would solve the timeout issues, I believe.

I am going to create an issue in Behat/Mink community, specifying the requirement and will update here once done.

pradeeprkara’s picture

Status: Active » Needs review
eliza411’s picture

Status: Needs review » Postponed

Thank you!

I'm setting this to postponed pending the Behat/Mink issue outcome. Would appreciate a link to the issue here once it's been opened.

pradeeprkara’s picture

Posted an issue at github.com

https://github.com/Behat/Mink/issues/302

eliza411’s picture

Assigned: pradeeprkara » Unassigned
Status: Postponed » Postponed (maintainer needs more info)

This issue is confirmed but no fix appears to be available yet. Unassigning and setting to need more info until the issue on GitHub is resolved.