简体   繁体   中英

Protractor and ng-repeat inside AngularJS application

Running protractor tests that had previously worked now seem to be failing! The following code snippet is an ng-repeat with a sort applied to it. When this is displayed, the user will see four columns. I would like to select the first item in first row, inside this row are the study details. I need to select the third column ie study.TASK_ITEM_CNT from the chosen element.

Code Snippet:

<div class="row">
<div ng-repeat="study in studyItems.drafts | orderBy:sort.value" class="col-md-3 study-col"
  ng-click="editStudy(study)">
  <div class="individual-study draft">
     <div class="study-date">{{ study.DATEVIEW_JS | formatdate:"DD MMMM YYYY"}}</div>
     <div class="review-study-date review-study-status study-paused-label" ng-if="study.STUDY_TYPE == 'MODERATED' || study.STATUSID == 'STOPPED'">
        <a  ng-show="study.STUDY_TYPE == 'MODERATED'" class='study-setGreenPill' id="study-hoveroff-greenPill" title="Moderated Study">Mod.</a>
     </div>
     <div class="study-name" study_id="{{study.ID}}" ng-bind-html="study.NAME | to_trusted"></div>
     <div class="study-task-details">{{study.TASK_ITEM_CNT || 0}} screen{{ study.TASK_ITEM_CNT == 1 ? '' : 's' }}
     </div>
     <div class="study-actions" study_id="{{study.ID}}" ng-click="confirmDelete($event, study, $index)" title = "Delete Study"></div>
   </div>
 </div>
</div>

The old protractor test looked like the following;

var firstElement = element(by.repeater('study in studyItems.drafts').row(0).column('{{study.TASK_ITEM_CNT || 0}}'))
expect(firstElement.getText()).toBe('TEST);

There are no error messages except to say that the test failed.

This had worked previously, I got it working with the following as shown;

element.all(by.repeater('study in studyItems.drafts')).get(0).then(function(args){
  expect(args.getText()).toContain('TEST');
});

This is not as elegant as I would like! Any suggestions are welcome.

Thanks.

J

use

element.all(by.repeater('study in studyItems.drafts | orderBy:sort.value')).get(0).then(function(args){

expect(args.getText()).toContain('TEST'); });

您的期望声明将为您解决承诺,您无需在该声明周围再包装另一个声明:// $$('')是element.all(by.css(...))的缩写。

expect($$('[ng-repeat="study in studyItems.drafts | orderBy:sort.value"]').get(0).getText()).toContain('TEST');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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