在量角器中测试嵌套的ng-repeat

时间:2014-07-24 19:54:13

标签: angularjs protractor

我一直在做试验和错误选择并点击以下代码失败,因为我是Protractor的新手我可能遗漏了一些东西。

HTML

<table id="sample-table-1" class="table table-striped table-condensed table-hover no-bottom-margin feedback">
    <thead>
    <tr>
        <th>
            Service
        </th>
        <th class="text-center">
            Rating
        </th>
    </tr>
    </thead>
    <tbody>
        <tr ng-repeat="feedbackService in feedbackServices" class="ng-scope">
            <td class="ng-binding">Feedback Service One</td>
            <td>
                <div rating="" score="feedbackService.rating_id" max="5" id="34" updaterating="updateScore(ratingId, id)" class="text-center ng-isolate-scope">
                    <div class="rating">
                        <a ng-repeat="star in stars" ng-mouseover="hover($index)" ng-mouseleave="stopHover()" ng-class="starColor($index)" ng-click="setRating($index)" class="ng-scope rating-normal">
                            <i class="fa fa-star-o" ng-class="starClass(star, $index)"></i>
                        </a>
                        <a ng-repeat="star in stars" ng-mouseover="hover($index)" ng-mouseleave="stopHover()" ng-class="starColor($index)" ng-click="setRating($index)" class="ng-scope rating-normal">
                            <i class="fa fa-star-o" ng-class="starClass(star, $index)"></i>
                        </a>
                    </div>
                </div>
            </td>
        </tr>
        <tr ng-repeat="feedbackService in feedbackServices" class="ng-scope">
            <td class="ng-binding">Feedback Service Two</td>
            <td>
                <div rating="" score="feedbackService.rating_id" max="5" id="30" updaterating="updateScore(ratingId, id)" class="text-center ng-isolate-scope">
                    <div class="rating">
                        <a ng-repeat="star in stars" ng-mouseover="hover($index)" ng-mouseleave="stopHover()" ng-class="starColor($index)" ng-click="setRating($index)" class="ng-scope rating-normal">
                            <i class="fa fa-star-o" ng-class="starClass(star, $index)"></i>
                        </a>
                        <a ng-repeat="star in stars" ng-mouseover="hover($index)" ng-mouseleave="stopHover()" ng-class="starColor($index)" ng-click="setRating($index)" class="ng-scope rating-normal">
                            <i class="fa fa-star-o" ng-class="starClass(star, $index)"></i>
                        </a>
                    </div>
                </div>
            </td>
        </tr>
    </tbody>
</table>

我想点击上面可点击的任何内容。 的 TEST

it('should rate feedback services', function() {
    element.all(by.repeater('feedbackService in feedbackServices')).then(function(arr) {
       console.log(arr);
        var rowElems = arr.findElements(by.tagName('td'));
        rowElems.then(function(cols){
            var stars = element.all(by.repeater('star in stars')).then(function(starArr) {
                for (var i = 0; i < cols.length; ++i) {
                    starArr[0].click();
                }
            });
        });
    });
    browser.debugger();
});

xit('feedback services', function() {
    var rows = element.all(by.repeater('feedbackService in feedbackServices'));
    rows.last().then(function(row) {
        var rowElems = row.findElements(by.tagName('td'));
        rowElems.then(function(cols){
                // Not sure if this is the right approach either?

        });
    });
});

我也能在Webstorm中设置调试器,但是我无法检查变量,那里有很多不必要的数据。

1 个答案:

答案 0 :(得分:2)

对于第一次测试(&#39;应评价反馈服务&#39;,function(){,您的脚本在此行中有问题

var rowElems = arr.findElements(by.tagName('td'));
rowElems.then(function(cols){

你应该把它改成

arr.findElements(by.tagName('td')).then(function(rowElems) {
element.all(by.repeater('star in stars')).then(function(starArr)

第二次测试相同

element.all(by.repeater('feedbackService in feedbackServices')).then(function(rows) {

我重写你的测试如下,我没有测试它

it('should rate feedback services', function() {
    element.all(by.repeater('feedbackService in feedbackServices')).then(function(arrs) {           
        arrs.forEach(function(arr) {
            arr.findElements(by.tagName('td')).then(function(rowElems) {
                var cols = rowElems.length;
                element.all(by.repeater('star in stars')).then(function(starArr) {
                    for (var i = 0; i < cols; ++i) {
                        starArr[0].click();     
                    }
                });
            });
        });
    });
});

it('feedback services', function() {
    element.all(by.repeater('feedbackService in feedbackServices')).then(function(rows) {
        rows[rows.length-1].then(function(row) {
            row.findElements(by.tagName('td')).then(function(rowElems) {
                rowElems.forEach(function(rowElem) {
                    rowElem.getText().then(function(text){
                        console.log(text);
                    });                 
                });
            });
        });
    });
});