在不同的单页面应用程序之间进行切换时,将[ng:test]没有找到元素参数的注入器发送到getTestability错误

时间:2015-06-17 03:42:14

标签: javascript angularjs protractor

我正在对量角器进行测试。我正在手动测试bootstrapping 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的rootelement通常是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之间使用spec文件之间的导航

browser.rootElement

任何人都可以帮我解决这个问题。如果我让开发人员在加载SPA的div顶部放置一个ID就可以解决?

2 个答案:

答案 0 :(得分:0)

我现在遇到了同样的问题。之前我正在测试一个应用程序,其body / div类在这样的conf.js中

rootElement:'。classOfDivUnderBodyOfAnSPA',

现在我正在测试另一个应用程序,我对此进行了评论,并对此进行了评论并添加了

rootElement:'。classOfDivUnderBodyOfNewSPA',

这解决了这个问题。

注意:我不是说要看哪个元素(比如你的身体)。我有正文下div的类值。希望这有帮助!

修订:我将div加在一起,逗号分隔,这也有帮助。所以不需要和其他人一起生活。 rootElement:'。class1,.class2',

答案 1 :(得分:0)

我刚刚通过更改

修复了此错误
`framework: jasmine` 
我的protractor.conf.js中的

属性为

`framework: jasmine2`