覆盖jasmin的函数,启动测试时出错

时间:2016-05-03 11:25:25

标签: angularjs jasmine protractor

美好的一天! 我在量角器it中覆盖了jasmin的onPrepare函数:

var originalIt = global.it;
        global.it = function () {


            function waitForSpinner() {

                element(by.css('.uil-element-loader-wrapper')).isPresent().then((el) => { //check if element on the page, if not don't wait at all

                    if(el) {
                        browser.wait(function () {
                            return element(by.css('.uil-element-loader-wrapper')).getAttribute('style').then((style) => {
                                if ((style.indexOf('block') > -1)) { //console.log('Spinner is here ' + (style.indexOf('block') > -1) + style);
                                    setTimeout(waitForSpinner, 100);
                                } else { //console.log('Spinner is gone');
                                    return true;
                                }
                            });
                        });
                    } else {
                        browser.wait(element(by.css('body')).isPresent());
                    }
                });

            }

            waitForSpinner();

            return originalIt.apply(this, arguments);
        };

但在开始测试时遇到一些问题:

[13:45:46] E/launcher - Process exited with error code 1

/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:654
    throw error;
    ^
Error while waiting for Protractor to sync with the page: "window.angular is undefined.  This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping.  See http://git.io/v4gXM for details"
Trace: { [Error: protractor exited with code 1]
  message: 'protractor exited with code 1',
  showStack: false,
  showProperties: true,
  plugin: 'gulp-protractor',
  __safety: { toString: [Function: bound ] } }
    at emitOne (events.js:82:20)
    at Stream.emit (events.js:169:7)
    at ChildProcess.<anonymous> (/node_modules/gulp-protractor/index.js:64:13)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)

虽然如果使用注释的waitForSpinner()运行测试;一切都好。

0 个答案:

没有答案