无法找到元素的可测试性 - 量角器

时间:2016-11-24 08:23:55

标签: angular protractor ui-testing e2e-testing

config.js:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js', 'landing-page-spec.js']
};

着陆page.spec.js:

describe('homepage', function() {
  it('navigates to the find page when clicking "try now"', function() {
    browser.get('http://localhost:3002');
    element(by.css('button.x-button')).click();
    var x = element(by.css('h2:first-of-type'));
    expect(x.getText()).toEqual("hello world");
  });
});

当我运行配置文件时,它会通过todo-spec.js完成,然后开始执行landing-page.spec.js,在其中加载我的Web应用程序,然后失败并出现此错误:

Failures: 1) VEPO homepage navigates to the find page when clicking "try now"   Message:
    Failed: Error while waiting for Protractor to sync with the page: "Could not find testability for element."   Stack:
    Error: Error while waiting for Protractor to sync with the page: "Could not find testability for element."
        at /usr/local/lib/node_modules/protractor/built/browser.js:269:23
        at ManagedPromise.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1379:14)
        at TaskQueue.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2913:14)
        at TaskQueue.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2896:21)
        at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2775:27
        at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
        at process._tickCallback (node.js:382:9)Error
        at ElementArrayFinder.applyAction_ (/usr/local/lib/node_modules/protractor/built/element.js:397:27)
        at ElementArrayFinder._this.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/built/element.js:100:30)
        at ElementFinder.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/built/element.js:728:22)
        at Object.<anonymous> (/Users/Ben/Development/vepo/app/test/landing-page-spec.js:4:43)
        at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:94:23
        at new ManagedPromise (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1082:7)
        at controlFlowExecute (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:80:18)
        at TaskQueue.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2913:14)
        at TaskQueue.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2896:21)
        at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2820:25
    From: Task: Run it("navigates to the find page when clicking "try now"") in control flow
        at Object.<anonymous> (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:79:14)
    From asynchronous test: 
    Error
        at Suite.<anonymous> (/Users/Ben/Development/vepo/app/test/landing-page-spec.js:2:3)
        at Object.<anonymous> (/Users/Ben/Development/vepo/app/test/landing-page-spec.js:1:1)
        at Module._compile (module.js:398:26)
        at Object.Module._extensions..js (module.js:405:10)
        at Module.load (module.js:344:32)
        at Function.Module._load (module.js:301:12)

2 specs, 1 failure Finished in 9.143 seconds [21:11:17] I/launcher - 0 instance(s) of WebDriver still running [21:11:17] I/launcher - chrome
#01 failed 1 test(s) [21:11:17] I/launcher - overall: 1 failed spec(s) [21:11:17] E/launcher - Process exited with error code 1

错误的原因是什么?

2 个答案:

答案 0 :(得分:3)

您的网页是否以Angular 2构建?在这种情况下,将以下内容添加到config.js:

useAllAngular2AppRoots: true

浏览器现在将等待加载所有angular2。

答案 1 :(得分:1)

添加 useAllAngular2AppRoots:true,
在protractor.conf.js中 它对我有用