在while循环中未分配带整数的var值

时间:2018-06-12 07:45:52

标签: javascript protractor

我正在尝试从方法getPageNumber()获取页面编号值,其中页码在控制台中打印。但是在While循环中不使用该值。即使我尝试打印pageNum,它也会返回promise。 参考控制台输出。 enter image description here

it('TS-06, should able to navigate to Manage Users Screen',function(){
        clientAdminPortal.clickMenuInSideBar("User Management");

        manageUsers.at().then(function() {
            console.log("---> Navigated to Manage Users Screen");

        });

        expect(manageUsers.isVisible(manageUsers.searchTxtBox)).toBeTruthy();
    });

 it('TS-10, verify Activate Button is viewed for all users',function(){
        var i=1;
        var check=false;
        var pageNum=manageUsers.getPageNumber();
        while(i<pageNum){
        console.log("check");
        i++;
 }
});

this.getPageNumber=function(){
        return this.pgnumCount.then(function(number){
            console.log(number.length);
            return number.length;
        });
    };

1 个答案:

答案 0 :(得分:0)

由于this.getPageNumber()会返回承诺,您必须在then()内消费承诺,如下所示:

it('TS-10, verify Activate Button is viewed for all users', function () {
    var i = 1;
    var check = false;

    manageUsers.getPageNumber().then(function (pageNum) {
        while (i < pageNum) {
            console.log("check");
            i++;
        }
    });

});