如何使用量角器测试分页功能 [英] How to test Pagination feature using Protractor

查看:61
本文介绍了如何使用量角器测试分页功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请指导我如何使用量角器浏览不同的分页页面,我关注了这个博客:http://seleniumhome.blogspot.com/2013/07/how-can-we-automate-pagination-using.html,不幸的是代码不起作用.这是我的应用程序中的代码:

<ul class="分页无边距"><li class="箭头不可用" ng-class="{unavailable: currentPage === 0 || pagedRowsTotal.length == 0}"><a class="ng-binding" ng-click="loadPage(0)" ng-bind-html="rsPaginatorText.first">第一</a><li class="箭头不可用" ng-class="{unavailable: currentGroup === 1 || pagedRowsTotal.length == 0}"><li class="箭头不可用" ng-class="{unavailable: currentPage === 0 || pagedRowsTotal.length == 0}"><a class="ng-binding" ng-click="loadPage(currentPage - 1)" ng-bind-html="rsPaginatorText.previous">Previous</a><!-- ngRepeat: groupArray track by $index 中的页面--><li class="ng-scope current" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index"><a class="ng-binding" ng-click="loadPage(page-1)">1</a><!-- end ngRepeat: page in groupArray track by $index --><li class="ng-scope" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index"><a class="ng-binding" ng-click="loadPage(page-1)">2</a><!-- end ngRepeat: page in groupArray track by $index --><li class="ng-scope" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index"><a class="ng-binding" ng-click="loadPage(page-1)">3</a><!-- end ngRepeat: page in groupArray track by $index --><li class="ng-scope" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index"><a class="ng-binding" ng-click="loadPage(page-1)">4</a><!-- end ngRepeat: page in groupArray track by $index --><li class="ng-scope" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index"><a class="ng-binding" ng-click="loadPage(page-1)">5</a><!-- end ngRepeat: page in groupArray track by $index --><li class="arrow" ng-class="{unavailable: currentPage === pagedRowsTotal.length -1}"><a class="ng-binding" ng-click="loadPage(currentPage + 1)" ng-bind-html="rsPaginatorText.next">下一步</a><li class="arrow" ng-class="{unavailable: currentGroup === groupsTotal}"><li class="arrow" ng-class="{unavailable: currentPage === pagedRowsTotal.length -1}"><a class="ng-binding" ng-click="loadPage(pagedRowsTotal.length - 1)" ng-bind-html="rsPaginatorText.last">Last</a>

这是我尝试过的,但收到错误:

this.getPaginationsize = element.all(by.repeater('page in groupArray track by $index'));summaryPage.getPaginationsize.getSize().then(function (pagination) {如果(分页> 0){for (var i = 0; i < 分页; i++) {summaryPage.getPaginationsize.get(i).click();}} 别的 {console.log('分页不存在');}});失败:无法将对象转换为原始值

解决方案

summaryPage.getPaginationsize.getSize() 方法将返回一个具有 webelement 高度和宽度的对象.相反,您需要使用 summaryPage.getPaginationsize.count() 来获取 pageSize 的总数.

参考:

getSize() : http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.getSizecount() : http://www.protractortest.org/#/api?view=ElementArrayFinder.prototype.count

Please guide me how to navigate through different pages of pagination using Protractor , i followed this blog: http://seleniumhome.blogspot.com/2013/07/how-can-we-automate-pagination-using.html, unfortunately the code is not working. Here is the code from my application:

<div class="vertical-align">
<ul class="pagination no-margins">
<li class="arrow unavailable" ng-class="{unavailable: currentPage === 0 || pagedRowsTotal.length == 0}">
<a class="ng-binding" ng-click="loadPage(0)" ng-bind-html="rsPaginatorText.first">First</a>
</li>
<li class="arrow unavailable" ng-class="{unavailable: currentGroup === 1 || pagedRowsTotal.length == 0}">
<li class="arrow unavailable" ng-class="{unavailable: currentPage === 0 || pagedRowsTotal.length == 0}">
<a class="ng-binding" ng-click="loadPage(currentPage - 1)" ng-bind-html="rsPaginatorText.previous">Previous</a>
</li>
<!-- ngRepeat: page in groupArray track by $index -->
<li class="ng-scope current" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index">
<a class="ng-binding" ng-click="loadPage(page-1)">1</a>
</li>
<!-- end ngRepeat: page in groupArray track by $index -->
<li class="ng-scope" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index">
<a class="ng-binding" ng-click="loadPage(page-1)">2</a>
</li>
<!-- end ngRepeat: page in groupArray track by $index -->
<li class="ng-scope" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index">
<a class="ng-binding" ng-click="loadPage(page-1)">3</a>
</li>
<!-- end ngRepeat: page in groupArray track by $index -->
<li class="ng-scope" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index">
<a class="ng-binding" ng-click="loadPage(page-1)">4</a>
</li>
<!-- end ngRepeat: page in groupArray track by $index -->
<li class="ng-scope" ng-class="{current: page === (currentPage + 1)}" ng-repeat="page in groupArray track by $index">
<a class="ng-binding" ng-click="loadPage(page-1)">5</a>
</li>
<!-- end ngRepeat: page in groupArray track by $index -->
<li class="arrow" ng-class="{unavailable: currentPage === pagedRowsTotal.length -1}">
<a class="ng-binding" ng-click="loadPage(currentPage + 1)" ng-bind-html="rsPaginatorText.next">Next</a>
</li>
<li class="arrow" ng-class="{unavailable: currentGroup === groupsTotal}">
<li class="arrow" ng-class="{unavailable: currentPage === pagedRowsTotal.length -1}">
<a class="ng-binding" ng-click="loadPage(pagedRowsTotal.length - 1)" ng-bind-html="rsPaginatorText.last">Last</a>
</li>
</ul>

This is what i tried, but receiving an error:

this.getPaginationsize = element.all(by.repeater('page in groupArray track by $index'));

summaryPage.getPaginationsize.getSize().then(function (pagination) {
            if (pagination > 0) {

                for (var i = 0; i < pagination; i++) {
                    summaryPage.getPaginationsize.get(i).click();
                }
            } else {
                console.log('Pagination not exists');
            }
        });

Failed: Cannot convert object to primitive value

解决方案

summaryPage.getPaginationsize.getSize() method will return an Object with height and width of a webelement. Instead you need to use summaryPage.getPaginationsize.count() to get the total number of pageSize.

Reference:

getSize() : http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.getSize count() : http://www.protractortest.org/#/api?view=ElementArrayFinder.prototype.count

这篇关于如何使用量角器测试分页功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆