量角器无法定位元素/值

时间:2015-03-11 15:48:07

标签: javascript angularjs testing protractor end-to-end

以下是html代码:

<tab id="briefcase" ng-controller="BriefcaseController as vm" active="main.uiState.briefcaseOpen">
        <tab-heading>
           <i class="glyphicon glyphicon-briefcase"></i><br>
            My Court Cases <span id="briefcaseCount" ng-show="main.briefcase.contents.length" class="badge">{{main.briefcase.contents.length}}</span>
        </tab-heading>
        <ng-include src="'app/components/briefcase/briefcase.html'"></ng-include>
    </tab>

我按照量角器API中给出的示例: 视图:

<span id="foo">{{variableInScope}}</span>

代码:

var value = element(by.id('foo')).evaluate('variableInScope');

在我的情况下,因为我有2个具有相同表达式的实例,所以我做了以下内容:

var value = element.all(by.id('briefcaseCount')).get(0).evaluate('main.briefcase.contents.length');

当我致电console.log(value)时...我正在[对象,对象] 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

您需要解析承诺才能在控制台上看到真正的价值:

element.all(by.id('briefcaseCount')).first().evaluate('main.briefcase.contents.length').then(function (value) {
    console.log(value);
});

如果您只需要断言值,请将其传递给expect() - 它会隐式解决承诺

var value = element.all(by.id('briefcaseCount')).first().evaluate('main.briefcase.contents.length');
expect(value).toEqual("somevalue");