如何使用量角器获取数据中单元格的计数
How to get the count of a cell in a data using Protractor
我无法获取下面提到的 table 单元格的计数。我只想在 table body.Please 中获取计数帮助我实现这一点-我希望获得-
的计数
<td class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0">[=10=].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">.00</td>
<!-- ngIf: paymentDetails.responseObject[0].fee_amount > 0 -->
<td class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0">[=11=].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">[=11=].00</td>
<!-- ngIf: paymentDetails.responseObject[0].fee_amount > 0 -->
<td class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0">.68</td>
<!-- end ngIf: paymentDetails.responseObject[0].fee_amount > 0 -->
</tr>
</tbody>
</table>
</div>
我试过的-但我得到的计数是 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);
});
见下图
过滤器将不起作用,因为过滤器将获取第一个匹配元素并且不计算在内,另请参阅 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 === '[=10=].90') {
count + 1;
}
});
});
// Do the assertion
expect(count).toBe(1);
我无法获取下面提到的 table 单元格的计数。我只想在 table body.Please 中获取计数帮助我实现这一点-我希望获得-
的计数<td class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0">[=10=].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">.00</td>
<!-- ngIf: paymentDetails.responseObject[0].fee_amount > 0 -->
<td class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0">[=11=].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">[=11=].00</td>
<!-- ngIf: paymentDetails.responseObject[0].fee_amount > 0 -->
<td class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0">.68</td>
<!-- end ngIf: paymentDetails.responseObject[0].fee_amount > 0 -->
</tr>
</tbody>
</table>
</div>
我试过的-但我得到的计数是 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);
});
见下图
过滤器将不起作用,因为过滤器将获取第一个匹配元素并且不计算在内,另请参阅 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 === '[=10=].90') {
count + 1;
}
});
});
// Do the assertion
expect(count).toBe(1);