【问题标题】:Protractor throwing error now that ng-app directive is on html tag现在 ng-app 指令在 html 标签上,量角器抛出错误
【发布时间】:2016-03-28 21:24:23
【问题描述】:

所以最近与我合作的开发人员将 ng-app 指令从 body 标记移至 html 标记,在我们正在开发的应用程序中。我正在使用量角器构建端到端测试套件,因为我们目前使用的是 Angular 1.4.8

今天早上之前,我所有测试中的所有内容都成功运行,但是现在 ng-app 指令位于 html 标记上,我收到以下错误。

 /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/async/nexttick.js:41
goog.global.setTimeout(function() { throw exception; }, 0);
                                  ^
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"

我知道我需要在 conf.js 文件中定义 rootElement: 'html',这是我的 conf.js 文件中的以下代码

exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['helpers.e2e.js', 'specs/leases.spec.js', ],
baseUrl: 'http://test.manage.ourApp.com/',
rootElement: 'html',
capabilities: {
  'browserName': 'chrome'
},
//This can be changed via the command line as:
//--params.login.user 'ourApp'
  params: {
  login: {
    email: 'ourApp.test@gmail.com',
    password: 'test'
  }
}, 

jasmineNodeOpts: {
  showColors: true,
  defaultTimeoutInterval: 300000,
  isVerbose: true,
  includeStackTrace: true
},

HTML 代码如下所示

 <html ng-app="ourApp" class="ng-scope">

我已经尝试了很多来自网络的建议,但仍然无法弄清楚我做错了什么。任何帮助将不胜感激。

【问题讨论】:

  • ng-app 属性后面的问号是错字吗?
  • 是的,很抱歉我在编辑中修复了它

标签: javascript html angularjs protractor


【解决方案1】:

在您的 protractor.conf.js 文件中,您应该将 rootElement 指定为一个选择器,它将查找包含您的 ng-app 属性的元素:

rootElement: '[ng-app="ourApp"]'

【讨论】:

  • 虽然此代码可能会回答问题,但提供有关此代码为何和/或如何回答问题的额外上下文可提高其长期价值。
  • 这并没有解决我的问题。我从 3.1.1 升级到 3.2.1,我开始收到错误。我的 ng-app 指令在 html 标签上,而控制器在 body 标签上。此修复针对哪个版本进行了测试?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-03
  • 2016-06-18
  • 1970-01-01
  • 2021-06-18
  • 1970-01-01
相关资源
最近更新 更多