javascript - 现在 ng-app 指令在 html 标签上, Protractor 抛出错误

标签 javascript html angularjs protractor

最近,在我们正在开发的应用程序中,与我合作的开发人员将 ng-app 指令从 body 标记移到了 html 标记。我正在使用 Protractor 构建端到端测试套件,因为我们目前使用的是 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">

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

最佳答案

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

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

关于javascript - 现在 ng-app 指令在 html 标签上, Protractor 抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34600052/

相关文章:

javascript - 当表单输入的值无效时,如何防止 AngularJS 解除表单输入值与其模型的绑定(bind)?

javascript - 通过选择两个相应的选择字段未生成动态链接

javascript - HTML 中消失的按钮

javascript - 从第一个斜杠拆分 javascript 中的图像路径

html - HTML 中的图像和文本标记,其中图像调整大小以适合容器

javascript - 如何在提交表单时在控制台上打印选择选项?

javascript - 在 Javascript 中判断视频是否加载

javascript - 使用带有动态字段的 HTML 在 Express Node JS 框架中呈现响应

javascript - AngularJS 编码德语变音符号

javascript - 为什么不添加 ng-leave/ng-enter 类