【问题标题】:Getting [ng:test] no injector found for element argument to getTestability error when swithching between different single page applications在不同的单页应用程序之间切换时,获取 [ng:test] 的元素参数没有找到 getTestability 错误的注入器
【发布时间】:2015-06-17 03:42:13
【问题描述】:

我正在量角器上运行测试。我正在测试手动引导 angularjs 的网站。在运行测试时,这是我得到的错误,即使步骤继续执行

Error while waiting for Protractor to sync with the page:
"[ng:test] no injector found for element argument to getTestability
\nhttp://errors.angularjs.org/1.3.15/ng/test"

转到链接 https://docs.angularjs.org/error/ng/test

我得到的解释是这样的

Angular's testability helper, getTestability, requires a root
element to be passed in. This helps differentiate between different
Angular apps on the same page. 
This error is thrown when no injector is found for root element.
It is often because the root element is outside of the ng-app.

当我从一个 SPA 切换到另一个 SPA 时出现此错误。我正在测试的网站在任何地方都没有使用 ng-app

据我了解,ng-app 的根元素通常是 html 或 body

如果我在我的 conf.js 中使用 body。我能够成功运行其他测试,但是当我从一个 SPA 导航到另一个 SPA 时,测试有时会出现上述错误

这是我的 conf.js 文件

var customReport  = require('./Utilities/HtmlWriter.js').htmlWriter;

//config dependencies - all the js files  in tests folder ending with -spec.js will be executed
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub', //Selenium webdriver instance needed to run the tsts
  specs: ['./tests/functional/EditAppInfo_spec.js'], // All tests need to be placed inside tests folder and should end with _spec.js

  baseUrl:'http://url.in.test.net',

      capabilities: {
        'browserName': 'firefox',
    },

    /*
     multiCapabilities:[
      {
            'browserName': 'chrome'
       },
        {
            'browserName': 'firefox'
        },       
        {
           'browserName': 'internet explorer',
        }
    ],
    */  

  getPageTimeout:30000,
  allScriptsTimeout:30000,
  rootElement: "body",

  jasmineNodeOpts: {
    onComplete: null,
    isVerbose: true,
    showColors: true,
    includeStackTrace: true,
    defaultTimeoutInterval: 10000000000000
 },

         onPrepare: function() {
    }
};

当我在不同的 SPA 之间导航时,是否需要更改根元素?

browser.rootElement

谁能帮我解决这个问题。如果我让开发人员在加载 SPA 的 div 顶部放置一个 ID,这会解决吗?

【问题讨论】:

    标签: javascript angularjs protractor


    【解决方案1】:

    我现在遇到了同样的问题。早些时候我正在测试一个应用程序,它的 body/div 类在 conf.js 中,就像这样

    rootElement: '.classOfDivUnderBodyOfAnSPA',

    现在我正在测试另一个应用程序,我很热,我评论了这个并添加了

    rootElement: '.classOfDivUnderBodyOfNewSPA',

    这解决了这个问题。

    注意:我并不是说要查看哪个元素(例如您拥有的 body)。我有主体下 div 的类值。希望这会有所帮助!

    修订:我将两个 div 加在一起,用逗号分隔,这也有帮助。所以没有必要和一个或另一个一起生活。 rootElement: '.class1, .class2',

    【讨论】:

    • 我厌倦了你告诉我的事情。其中许多错误已得到解决,但我在 firefox 上仍然遇到同样的错误几次
    【解决方案2】:

    我刚刚通过更改修复了这个错误

    `framework: jasmine` 
    

    我 protractor.conf.js 中的属性到

    `framework: jasmine2`
    

    【讨论】:

    • 反引号是有意的吗?
    • 不,我不这么认为
    猜你喜欢
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    • 2014-11-13
    • 1970-01-01
    • 2016-05-17
    • 2021-03-02
    • 2017-09-27
    • 1970-01-01
    相关资源
    最近更新 更多