2017-07-21 36 views
0

我無法獲取下面提到的表格的單元的數量。我只希望在表中獲取計數body.Please幫助我實現這 - 即時通訊尋求獲得數OF-如何使用量角器獲取數據中單元的數量

<td class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0">$0.90</td>

請讓我知道如何做到這一點。謝謝!!

<div class="show-for-large-up"> 
 
    <table> 
 
    <thead> 
 
     <tr> 
 
     <!-- ngIf: paymentDetails.responseObject[0].fee_amount > 0 --> 
 
     <th class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0" ng-bind-html="receiptTemplate.paymentFee" width="300">Payment Fee</th> 
 
     <!-- end ngIf: paymentDetails.responseObject[0].fee_amount > 0 --> 
 
     </tr> 
 
    </thead> 
 
    <tbody> 
 
     <!-- ngRepeat: lineItem in paymentDetails.responseObject[0].schedules[0].schedule_line_items track by $index --> 
 
     <tr class="ng-scope" ng-repeat="lineItem in paymentDetails.responseObject[0].schedules[0].schedule_line_items track by $index"> 
 
     <td class="ng-binding">$45.00</td> 
 
     <!-- ngIf: paymentDetails.responseObject[0].fee_amount > 0 --> 
 
     <td class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0">$0.90</td> 
 
     <!-- end ngIf: paymentDetails.responseObject[0].fee_amount > 0 --> 
 
     </tr> 
 
     <!-- end ngRepeat: lineItem in paymentDetails.responseObject[0].schedules[0].schedule_line_items track by $index --> 
 
     <tr class="ng-scope" ng-repeat="lineItem in paymentDetails.responseObject[0].schedules[0].schedule_line_items track by $index"> 
 
     <td class="ng-binding">Jul 21, 2017</td> 
 
     <td class="ng-binding">$0.00</td> 
 
     <!-- ngIf: paymentDetails.responseObject[0].fee_amount > 0 --> 
 
     <td class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0">$1.68</td> 
 
     <!-- end ngIf: paymentDetails.responseObject[0].fee_amount > 0 --> 
 
     </tr> 
 
    </tbody> 
 
    </table> 
 
</div>

我tried-什麼,但IM得到計數爲3。其實數應在1

var paymentTable = $$('.show-for-large-up tr'); 
 
var row = paymentTable.$$('[ng-repeat="lineItem in paymentDetails.responseObject[0].schedules[0].schedule_line_items track by $index"]'); 
 
var cell = row.$$('[ng-if="paymentDetails.responseObject[0].fee_amount > 0"]'); 
 
var cellCount = cell.filter(function(elm) { 
 
    return elm.count(); 
 
expect(elm.count()).toBe(1); 
 
});

查看圖像下方 Looking to fetch the count of rows for the column Payment fee

+0

你是如何訪問'elm.count()'過濾器外側?你沒有得到錯誤? –

+0

抱歉,複製代碼時出現錯字,現在編輯。 – Smitha

回答

1

的過濾器將無法工作,因爲一個過濾器將獲得第一個匹配的元素,不計,也見docs

你可以用each實現這一目標。你迭代每個匹配的元素,然後做你需要的事情。你的代碼會是這個樣子

var count = 0; 
 

 
// Get all the td's 
 
$$('[ng-if="paymentDetails.responseObject[0].fee_amount > 0"]') 
 
    // Walk through all the found td's 
 
    .each((element) => { 
 
    // Get the text of the td 
 
    return element.getText() 
 
     .then((text) => { 
 
     // Add a + 1 if the text matches 
 
     if (text === '$0.90') { 
 
      count + 1; 
 
     } 
 
     }); 
 
    }); 
 

 
// Do the assertion 
 
expect(count).toBe(1);

+0

感謝您的回答wswebcreation,但金額總是不會是0.90。每筆付款金額都會變化。請讓我知道是否有其他方法可以解決此問題。 – Smitha

+0

只是使數量變量 – wswebcreation

+0

仍然無法實現測試用例的意圖,您可以請求幫助獲得多行單元格的計數? – Smitha

相關問題