解决方法
您需要做的是覆盖默认的帧加载行为,并在应用程序准备就绪时发出新事件.
第一件事是在angular应用程序中添加以下行以及angular.bootstrap调用.角度场景需要此数据.
angular.bootstrap(document,['app']); var html = document.getElementsByTagName('html')[0]; html.setAttribute('ng-app','app'); html.dataset.ngApp = 'app'; if (top !== window) { top.postMessage({ type: 'loadamd' },'*'); }
接下来,在您的e2e跑步者中,您必须包含这些线.如果它是外部脚本,则必须在angular-scenario之后加载它,并且必须在DOM准备好之前解析它:
/** * Hack to support amd with angular-scenario */ (function() { var setUpAndRun = angular.scenario.setUpAndRun; angular.scenario.setUpAndRun = function(config) { if (config.useamd) { amdSupport(); } return setUpAndRun.apply(this,arguments); }; function amdSupport() { var getFrame_ = angular.scenario.Application.prototype.getFrame_; /** * This function should be added to angular-scenario to support amd. It overrides the load behavior to wait from * the inner amd frame to be ready. */ angular.scenario.Application.prototype.getFrame_ = function() { var frame = getFrame_.apply(this,arguments); var load = frame.load; frame.load = function(fn) { if (typeof fn === 'function') { angular.element(window).bind('message',function(e) { if (e.data && e.source === frame.prop('contentWindow') && e.data.type === 'loadamd') { fn.call(frame,e); } }); return this; } return load.apply(this,arguments); } return frame; }; } })();
最后,要启用amd配置,必须将属性ng-useamd添加到angular-scenario的脚本标记中.
<script type="text/javascript" src="lib/angular-1.0.3/angular-scenario.js" ng-autotest ng-useamd></script>
你现在准备好了
使用角度场景v1.0.3进行测试