I want to execute some javascript on page in @BeforeStep hook that depends on jQuery. However jQuery is not defined at that time, in fact page is blank.
Here's what I am trying to achive:
/**
* @BeforeStep @javascript
*/
public function registerAjaxEventHandlers()
{
$javascript = <<<JS
window.jQuery(document).ready(function () {
if (window.__ajaxStatus !== undefined) {
return;
}
window.__ajaxStatus = 'none';
$('body').ajaxStop(function() {
window.__ajaxStatus = 'idle';
});
$('body').ajaxStart(function() {
window.__ajaxStatus = 'in-flight';
});
});
JS;
//$this->getSession()->wait(5000, 'window.jQuery !== undefined');
$this->getSession()->executeScript($javascript);
}
I figured maybe I could wait for the page to load jQuery first (commented line), but it is not true. Seems like execution is halted until that hook is processed.
What is the right place in behat/mink ecosystem to execute javascript on page?
How about this?
$this->getSession()->wait(5000, 'typeof window.jQuery == "function"');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With