如何在转发器下获得转发器的所有元件

时间:2016-07-27 15:39:53

标签: testing automation protractor

<item id="item-1" class="item ng-scope" ng-repeat="incident in $ctrl.allIncidents track by incident.dg_guid"><div role="tablist" class="panel-group" ng-transclude="">
    <div class="panel ng-scope ng-isolate-scope panel-default panel-open" ng-class="panelClass || 'panel-default'" is-open="$ctrl.isExpanded" style="">

  <div id="accordiongroup-1970-6335-panel" aria-labelledby="accordiongroup-1970-6335-tab" aria-hidden="false" role="tabpanel" class="panel-collapse in collapse" uib-collapse="
    <!-- ngIf: $ctrl.showTextArea -->
    <div>

            <!-- ngRepeat: event in $ctrl.timeline.filterBy track by $index --><div class="incident-details__description-text flex-space-between ng-scope" ng-repeat="event in $ctrl.timeline.filterBy track by $index">
                <div>
                    <!-- ngRepeat: time in event.date track by $index --><div class="timeline__time__container ng-scope timeline__container-first" ng-repeat="time in event.date track by $index" ng-class="{'timeline__container-first': $first}">
                        <span class="timeline__time ng-binding">8:39 PM</span><br>
                    </div><!-- end ngRepeat: time in event.date track by $index --><div class="timeline__time__container ng-scope" ng-repeat="time in event.date track by $index" ng-class="{'timeline__container-first': $first}">
                        <span class="timeline__time ng-binding">07/26/16</span><br>
                    </div><!-- end ngRepeat: time in event.date track by $index -->
                </div>                
                </div>
            </div><!-- end ngRepeat: event in $ctrl.timeline.filterBy track by $index --><div class="incident-details__description-text flex-space-between ng-scope" ng-repeat="event in $ctrl.timeline.filterBy track by $index">
                <div>
                    <!-- ngRepeat: time in event.date track by $index --><div class="timeline__time__container ng-scope timeline__container-first" ng-repeat="time in event.date track by $index" ng-class="{'timeline__container-first': $first}">
                        <span class="timeline__time ng-binding">7:08 PM</span><br>
                    </div><!-- end ngRepeat: time in event.date track by $index --><div class="timeline__time__container ng-scope" ng-repeat="time in event.date track by $index" ng-class="{'timeline__container-first': $first}">
                        <span class="timeline__time ng-binding">07/25/16</span><br>
                    </div><!-- end ngRepeat: time in event.date track by $index -->
                </div>

我正在尝试获取timeline__time的时间

this.IncList = element.all(by.repeater('incident in $ctrl.allIncidents track by incident.dg_guid'));
this.FirtstIncTimeLine = this.IncList.get(0).element.all(by.repeater('event in $ctrl.timeline.filterBy track by $index'));
this.FirtstIncTopTimeLine = this.FirtstIncTimeLine.first();
this.FirtstIncTopTimeLineTime = this.FirtstIncTopTimeLine.element.all(by.css('span.timeline__time'));

我收到以下错误:

  

错误:TypeError:this.IncList.get(...)。element.all不是函数

如何在Repeater下获取转发器的所有元素?

1 个答案:

答案 0 :(得分:3)

这是Protractor中的一个常见问题,你正在进行链接错误,替换:

this.IncList.get(0).element.all(by.repeater('event in $ctrl.timeline.filterBy track by $index'));

使用:

this.IncList.get(0).all(by.repeater('event in $ctrl.timeline.filterBy track by $index'));

仅供参考,如果有兴趣,我currently working on making these kind of problems caught by static code analysis and ESLint

作为旁注,请勿在转发器定位器内使用“track by”:

this.IncList.get(0).all(by.repeater('event in $ctrl.timeline.filterBy'));

我已经实施the ESLint rule来警告这一点。