我怎样才能让量角器在桌子上向下滚动?我的表进行无限滚动-它加载20个记录,当显示第二行到最后一行时,它将获取接下来的20个记录。并不是view...some中的所有记录都在下面有待滚动,而当用户滚动过它时,有些记录就在上面。我在想考试是
it('should fetch next set of records on scroll') {
element.all(by.id('users')).map(function (elm) {
return elm;
}).then(function (users) {
expect(users.length).toBe(20);
});
// Scroll the table to the bottom to trigger fetching more records
element.all(by.id('users')).map(function (elm) {
return elm;
}).then(function (users) {
expect(users.length).toBe(40);
});
};
这样做对吗?
HTML表代码:
<div ng-if="users && users.length > 0" class="table-scroll" ng-infinite-scroll="loadMoreUsers()">
<table id="users-table" class="table table-hover text-overflow-ellipsis">
<thead>
<td class="col1"></td>
<td id="users-table-name-col" class="col2">User</td>
<td id="users-table-date-col" class="col3">Birthday</td>
</thead>
<tbody ng-repeat="group in users">
<tr ng-repeat="user in group.users" ng-click="userClicked(user);">
<td class="col1">
<img class="col-xs-1 profile-picture" style="padding:0" ng-src="{{user.profile_picture}}"></td>
<td class="col2">
<div id="user-name"> {{ user.last_name }}, {{ user.first_name }} </div>
</td>
<td class="col3">
<div id="user-date"> {{user.date}} </div>
</td>
</tr>
</tbody>
</table>
</div>
发布于 2015-01-06 15:00:04
这样做的目的是在表中找到最新的元素(tr
标记),并通过将父元素的scrollTop
设置为最后一个元素的offsetTop
来滚动到它。
Element.scrollTop
属性获取或设置元素内容向上滚动的像素数。元素的scrollTop是一个元素顶部到其最上面可见内容的距离的度量。HTMLElement.offsetTop
只读属性返回当前元素相对于offsetParent节点顶部的距离。
var div = element(by.css('div.table-scroll'));
var lastRow = element(by.css('table#myid tr:last-of-type'));
browser.executeScript("return arguments[0].offsetTop;", lastRow.getWebElement()).then(function (offset) {
browser.executeScript('arguments[0].scrollTop = arguments[1];', div.getWebElement(), offset).then(function() {
// assertions
});
});
另见(所用的类似解决方案):
https://stackoverflow.com/questions/27794316
复制相似问题