简体   繁体   English

量角器3.1.1 + Angular2:无法找到元素的可测试性

[英]Protractor 3.1.1 + Angular2: Could not find testability for element

I am running a simple HelloWorld sample with Protractor 3.1.1 and Angular2, but this thing keeps telling me Could not find testability for element . 我正在使用Protractor 3.1.1和Angular2运行一个简单的HelloWorld示例,但这件事一直告诉我无法找到元素的可测试性 I googled the Internet for some information about the error, but no luck, it seems to be a new sort of exception that not so many have faced. 我在网上搜索了有关错误的一些信息,但没有运气,这似乎是一个新的例外,没有那么多人面临过。

This is the component I'm using: 这是我正在使用的组件:

import {Component} from 'angular2/core';

@Component({
    selector: 'my-app',
    template: '<h1>My First Angular 2 App</h1>' +
    '<h2>{{myName}}</h2>' +
    '<input id="someId" [(ngModel)]="myName"/>'
})
export class AppComponent {
    myName = 'Joe';
}

This is the Protractor config file: 这是Protractor配置文件:

exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: [
    'e2e/*.js'
  ],
  baseUrl: 'http://localhost:3000'
};

And this is the Protractor scenario I am running: 这是我正在运行的量角器场景:

describe('angularjs homepage', function() {
    it('should say my name', function() {
        browser.get('/index.html');
        var greeting = element(by.id('someId'));
        expect(greeting.getAttribute('value')).toEqual('Joe');
    });
});

The webpage loads normally with the template HTML rendered, but Protractor thinks the resulting webpage is not an Angular webpage, now, why is that? 网页正常加载模板HTML,但是Protractor认为生成的网页不是Angular网页,现在,为什么呢? And obviously, if I inspect the resulting webpage, it is only the resulting HTML of the processed Angular code, am I doing something wrong? 显然,如果我检查生成的网页,它只是处理过的Angular代码的结果HTML,我做错了吗?

This is the complete error: 这是完整的错误:

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

If I run a simple test as the Protractor Tutorial says, using this demo page: http://juliemr.github.io/protractor-demo/ , it works as expected, so something has my Angular2 code that the Protractor is not working with it, but I already ran out of ideas, any one knows what is happening? 如果我像Protractor Tutorial所说的那样运行一个简单的测试,使用这个演示页面: http ://juliemr.github.io/protractor-demo/,它按预期工作,所以有一些东西我的Angular2代码,Protractor没有使用它,但我已经没有想法,任何人都知道发生了什么?

UPDATE 23-02-2016 更新2016年2月23日

After some research I found that to use Protractor with Angular2, there must be an additional configuration line in the config file: 经过一些研究,我发现要使用带有Angular2的Protractor,配置文件中必须有一个额外的配置行:

useAllAngular2AppRoots: true

such that conf.js now looks like: 这样conf.js现在看起来像:

exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: [
    'e2e/*.js'
  ],
  baseUrl: 'http://localhost:3000',
  useAllAngular2AppRoots: true
};

or include the app root explicitly with: 或明确包含应用程序根目录:

rootElement: 'my-app'

After this update all calls to find an element by.id() work OK, but if you pretend to use any of the locators by.model() or by.binding() , it will simply fail with the message UnknownError: unknown error: angular is not defined . 在此更新之后,所有调用以查找元素by.id()可以正常工作,但是如果您假装使用任何定位器by.model()by.binding() ,它将会失败并显示消息UnknownError: unknown error: angular is not defined No idea why. 不知道为什么。

Apparently there is a bug in that commit. 显然,该提交中存在一个错误。 Check this! 检查一下! .

But for now you can run your tests using browser.executeScript('window.name = "NG_ENABLE_DEBUG_INFO!"'); 但是现在你可以使用browser.executeScript('window.name = "NG_ENABLE_DEBUG_INFO!"');运行你的测试browser.executeScript('window.name = "NG_ENABLE_DEBUG_INFO!"');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM