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

Posted

技术标签:

【中文标题】找不到元素的可测试性 - 量角器【英文标题】:Could not find testability for element - Protractor 【发布时间】:2016-11-24 08:23:54 【问题描述】:

config.js:

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

登陆页面.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,它在其中加载我的网络应用程序,然后失败并出现以下错误:

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

错误的原因是什么?

【问题讨论】:

【参考方案1】:

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

useAllAngular2AppRoots: true

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

【讨论】:

【参考方案2】:

添加了useAllAngular2AppRoots: true, 在量角器.conf.js 它对我有用

【讨论】:

以上是关于找不到元素的可测试性 - 量角器的主要内容,如果未能解决你的问题,请参考以下文章

使用量角器切换到 iframe 后找不到使用定位器错误的元素

量角器:by.model 在自定义指令中找不到元素

量角器+故事书:失败:使用定位器找不到元素:By(css选择器)

找不到元素的元素

错误:找不到模块 'jasmine-expect' [量角器]

成功解决后,带有打字稿的量角器找不到模块“量角器”