コード例 #1
0
ファイル: AbstractPage.php プロジェクト: kstupak/platform
    /**
     * Wait PAGE load
     */
    public function waitPageToLoad()
    {
        // writes javascript errors to screenshots
        $jsCode = <<<JS
            if (!window.onerror) {
                window.onerror = function (errorMsg, url, lineNumber, column, errorObj) {
                    \$('body').append(
                        '<div style="background: rgba(255,255,200,0.7); color: rgb(0,0,255); ' +
                            'position: absolute; top: 15px; left: 15px; right: 15px; ' +
                            'z-index: 999999; padding: 10px; border: 1px solid red;  border-radius: 5px;' +
                            'box-shadow: 0 0 40px rgba(0,0,0,0.5); white-space: pre">' +
                            '<h5>Js error occured</h5>' +
                            errorMsg + '\\n' +
                            'at ' + url + ':' + lineNumber + ':' + column +
                            '<h5>Stack trace:</h5>' +
                            errorObj.stack +
                        '</div>'
                    );

                    // Tell browser to run its own error handler as well
                    return false;
                }
            }
JS;
        $this->test->execute(array('script' => $jsCode, 'args' => array()));
        $this->test->waitUntil(function (\PHPUnit_Extensions_Selenium2TestCase $testCase) {
            $status = $testCase->execute(array('script' => "return 'complete' == document['readyState']", 'args' => array()));
            if ($status) {
                return true;
            } else {
                return null;
            }
        }, intval(MAX_EXECUTION_TIME));
        $this->test->waitUntil(function (\PHPUnit_Extensions_Selenium2TestCase $testCase) {
            $status = $testCase->execute(array('script' => "return typeof(document['page-rendered'])=='undefined' || !!document['page-rendered']", 'args' => array()));
            if ($status) {
                return true;
            } else {
                return null;
            }
        }, intval(MAX_EXECUTION_TIME));
        $this->test->timeouts()->implicitWait(intval(TIME_OUT));
    }