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



我一直在做试验和错误选择并单击以下代码不成功,因为我是全新的Protractor我可能错过了一些东西。

<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>

我想点击上面任何可点击的东西。测试

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中设置调试器,但是我不能检查变量,那里有很多不必要的数据。

对于第一个测试它('should rate feedback services', 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);
                    });                 
                });
            });
        });
    });
});

最新更新