Mink:等待页面加载@BeforeStep

Dzi*_*mid 5 selenium behat mink selenium-webdriver

我想在依赖于jQuery的@BeforeStep钩子上执行页面上的一些javascript.但是当时没有定义jQuery,实际上页面是空白的.

这是我想要实现的目标:

/**
 * @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);
    }
Run Code Online (Sandbox Code Playgroud)

我想也许我可以等待页面首先加载jQuery(注释行),但事实并非如此.似乎执行被暂停,直到处理该钩子为止.

behat/mink生态系统在页面上执行javascript的正确位置是什么?

Jak*_*las 5

这个怎么样?

$this->getSession()->wait(5000, 'typeof window.jQuery == "function"');
Run Code Online (Sandbox Code Playgroud)