Behat/Mink — Issue #142: $readyState just after click in SeleniumDriver is erroneously 'complete'
Author: markanobii
Created: 2011-12-09 17:21:04+00:00
State: open

At around line 425 in src/Behat/Mink/Driver/SeleniumDriver.php:

public function click($xpath)
{
$this->browser->click(SeleniumLocator::xpath($xpath));
$readyState = $this->browser->getEval('window.document.readyState');

if ($readyState == 'loading' || $readyState == 'interactive') {
$this->browser->waitForPageToLoad($this->timeout);
}
}

$readyState is 'complete', when it should be one of 'loading' or 'interactive'. It appears the click event hasn't been caused the browser to react at this stage. If I add sleep(1) after the click, $readyState is correct.

On the Selenium side I get:

17:12:01.286 INFO - Command request: click[xpath=(//html/.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][((./@id = 'searchButton' or contains(./@value, 'searchButton')) or contains(./@title, 'searchButton'))] | .//input[./@type = 'image'][contains(./@alt, 'searchButton')] | .//button[(((./@id = 'searchButton' or contains(./@value, 'searchButton')) or contains(normalize-space(string(.)), 'searchButton')) or contains(./@title, 'searchButton'))] | .//input[./@type = 'image'][contains(./@alt, 'searchButton')] | .//*[./@role = 'button'][((./@id = 'searchButton' or contains(./@value, 'searchButton')) or contains(./@title, 'searchButton') or contains(normalize-space(string(.)), 'searchButton'))])[1], ] on session 852361f332c343ce9f4356b81bd0c218
17:12:01.294 INFO - Got result: OK on session 852361f332c343ce9f4356b81bd0c218
17:12:01.296 INFO - Command request: getEval[window.document.readyState, ] on session 852361f332c343ce9f4356b81bd0c218
17:12:01.320 INFO - Got result: OK,complete on session 852361f332c343ce9f4356b81bd0c218

The page hasn't started reloading, so the readyState seems to stay at 'complete'. By the time the next test runs, the browser state is indeterminate - it might still be loading, therefore causing tests to fail.

I've worked around this by creating a waitForPageToLoad() definition in my own FeatureContext class, but it's a little hacky :P

Versiony stuff:
Behat: 2.1.3
Selenium: 2.14

Thanks,
Mark