2016-12-15 32 views
0
<table class="table table-bordered table-striped"> 

     <thead> 
     <tr> 
     <td> 
     <a href="#" ng-click="sortType = 'date'; sortReverse = !sortReverse"> 
     Date-Time 
     </a> 
     </td> 
     <td><a>Amount</a></td> 
     <td><a>Transaction Type</a></td> 
    </tr> 
    </thead> 

    <tbody> 


    <!-- ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end --><tr id="anchor0" ng-repeat="tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end" class="ng-scope"> 
     <td class="ng-binding">Dec 13, 2016 10:54:12 AM</td> 
    <td class="ng-binding">12</td> 
     <td class="ng-binding">Debit</td> 
     </tr><!-- end ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end --><tr id="anchor1" ng-repeat="tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end" class="ng-scope"> 
     <td class="ng-binding">Dec 13, 2016 10:54:10 AM</td> 
    <td class="ng-binding">155</td> 
     <td class="ng-binding">Debit</td> 
     </tr><!-- end ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end --><tr id="anchor2" ng-repeat="tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end" class="ng-scope"> 
     <td class="ng-binding">Dec 13, 2016 10:54:05 AM</td> 
    <td class="ng-binding">32</td> 
     <td class="ng-binding">Credit</td> 
     </tr><!-- end ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end --><tr id="anchor3" ng-repeat="tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end" class="ng-scope"> 
     <td class="ng-binding">Dec 13, 2016 10:54:03 AM</td> 
    <td class="ng-binding">1000</td> 
     <td class="ng-binding">Credit</td> 
     </tr><!-- end ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end --><tr id="anchor4" ng-repeat="tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end" class="ng-scope"> 
     <td class="ng-binding">Dec 8, 2016 4:45:08 PM</td> 
    <td class="ng-binding">100</td> 
     <td class="ng-binding">Debit</td> 
     </tr><!-- end ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end --><tr id="anchor5" ng-repeat="tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end" class="ng-scope"> 
     <td class="ng-binding">Dec 8, 2016 4:44:43 PM</td> 
    <td class="ng-binding">210</td> 
     <td class="ng-binding">Credit</td> 
     </tr><!-- end ngRepeat: tx in transactions | orderBy:sortType:sortReverse | sDate:startDate:end --> 
    </tbody> 

    </table> 

我正在添加示例代碼,我試圖測試這個網站。多種方式,我試圖解決我的問題,但未能解決。現在幫我你所有走出它 - 的如何測量量角器中的列值?

it("Column values",function() { 
browser.get('http://www.way2automation.com/angularjs-protractor/banking/#/listTx#anchor'); 
browser.sleep(1500); 
var rows = element.all(by.repeater("tx in transactions")); 

var data = rows.map(function (row) { 
    var cells = row.all("td"); 
    return { 
     value1: cells.first().getText(), 
     value2: cells.get(1).getText(), 
     value3: cells.get(2).getText() 
    } 
}); 

    expect(data).toEqual([ 
     {value1: "Dec 8, 2016 4:44:43 PM", value2: "210", value3: "Credit"}, 
     {value1: "Dec 8, 2016 4:45:08 PM", value2: "100", value3: "Debit"} 
    ]); 

我想這個值在HTML 2016年12月8日下午四點44分43秒信用

回答

1

您需要解決的getText()方法獲得單元格的值。如下所示,

var data = rows.map(function (row) { 
    return row.all("td").getText().then(function(cellTextArray){ 
    return { 
     value1: cellTextArray[0], 
     value2: cellTextArray[1], 
     value3: cellTextArray[2] 
    } 
    }) 

}); 
+0

謝謝..但它不起作用 –

+0

你得到什麼錯誤? –

+0

預期[]等於{value1:「2016年12月8日下午4點44分43秒」,value2:「210」,value3:「Credit」}, {value1:「2016年12月8日下午4:45:08 PM 「,value2:」100「,value3:」Debit「} ]); –