ProtractorJS:等待量角器与页面同步时出错:"无法找到元素的可测试性。"

时间:2016-08-10 21:04:00

标签: selenium angular jasmine protractor

我试图用ProtractorJS端到端地测试我的Angular 2项目。 当我在控制台中运行protractor conf.js时,我得到:

 Failed: Error while waiting for Protractor to sync with the page: "Could not
 find testability for element."

在配置文件中:

exports.config = {
    seleniumAddress: "http://localhost:4444/wd/hub",
    framework:"jasmine2",
    capabilities: {"browserName": "chrome"},
    specs: ["todo-spec.js"]
};

我的根组件:

<section>
    <h1>Employee Payroll Information Directory</h1>
    <employee-searchform></employee-searchform>
</section>

这是我试图运行的测试:

describe('modal component', function () {
    it('should output the employee and delete it from the array', function () {
        browser.get('http://localhost:80/Fourth/Fourth/');
        var searchField = element(by.className('.ng-valid'));
        searchField.click();
        searchField.sendKeys('Skye');
        searchField.getText().then(function (text) {
            console.log(text);
        });
        var employeeListItem = element(by.id('employee-list'));
    });
});

这是我在webDriver Selenium服务器上获得的:

23:57:25.816 INFO - Done: [execute async script: try { return (function (rootSel
ector, callback) {
  var el = document.querySelector(rootSelector);

  try {
    if (window.getAngularTestability) {
      window.getAngularTestability(el).whenStable(callback);
      return;
    }
    if (!window.angular) {
      throw new Error('angular could not be found on the window');
    }
    if (angular.getTestability) {
      angular.getTestability(el).whenStable(callback);
    } else {
      if (!angular.element(el).injector()) {
        throw new Error('root element (' + rootSelector + ') has no injector.' +

           ' this may mean it is not inside ng-app.');
      }
      angular.element(el).injector().get('$browser').
          notifyWhenNoOutstandingRequests(callback);
    }
  } catch (err) {
    callback(err.message);
  }
}).apply(this, arguments); }
catch(e) { throw (e instanceof Error) ? e : new Error(e); }, [body]]
23:57:25.899 INFO - Executing: [delete session: 35adb055-eee3-419e-b3c1-461b65b4
18aa])
23:57:29.157 INFO - Done: [delete session: 35adb055-eee3-419e-b3c1-461b65b418aa]

2 个答案:

答案 0 :(得分:3)

你应该将Protractor指向容纳Angular应用程序的元素。这可以通过在量角器配置中设置rootElement来完成:

rootElement: 'app',

答案 1 :(得分:-1)

如果您使用By.className(),则无需提及&#34;。&#34;在你的班级名字前面。您只需使用By.className("ng-valid")

即可